From patchwork Tue Apr 11 11:12:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 97240 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp1756354qgd; Tue, 11 Apr 2017 04:13:33 -0700 (PDT) X-Received: by 10.99.218.69 with SMTP id l5mr61677027pgj.219.1491909212995; Tue, 11 Apr 2017 04:13:32 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g5si16487301pgi.386.2017.04.11.04.13.32; Tue, 11 Apr 2017 04:13:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754653AbdDKLNV (ORCPT + 23 others); Tue, 11 Apr 2017 07:13:21 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:38036 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753319AbdDKLM6 (ORCPT ); Tue, 11 Apr 2017 07:12:58 -0400 Received: by mail-wm0-f41.google.com with SMTP id t189so58435929wmt.1 for ; Tue, 11 Apr 2017 04:12:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yaC6sQ5EYbO3sfwbY4X+L6MZIWITac7cJ6D1IC2NUVc=; b=HP5LqGwWKE3S81zD4KaS89W2wI3EmjDYLK7nAVyTNvq1Cr7i4QMhpQ/grfPukxpEyG 30RHy+sFcKSQ8HkC3XMJ8Pd+DL3lCLH8Uqd4sLw049F8s+t6d6VqV94CJT+pfHhOoijG YdCukdLzyvbRpjcTd+My0OHh9KNhARAFXjslY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yaC6sQ5EYbO3sfwbY4X+L6MZIWITac7cJ6D1IC2NUVc=; b=H8Kg2PYcsDo4gtBTQNppZRRNZxRVR0H8LW20Hlypfw7vPHcBN+R0aVc6YwiYoWkOWy joLAeL4XEZrEF7IzY3QWg6KzYfiLo1oqPJv7TRs+77E/2ikTQr5rfbOs6NN3VgzoF/hO 46bY7NLem5uo0NFjk1/RGmXXqUeFcKTvO/dBrSsxrM7N8ush3qR2s8GN+2g8OkVCc0co Elfd7JW2KqQpeAU8TSHONpimYAVOl5ZZWO7wZ0dNHh3PaMbhwSw7k7UarYwFTAxhFn56 V85On7vs+zWGf6pX41ikL6y4eynahJHE92uXjdopQ9ZZnSBRtR3C1SOuNjZ8TqWj3N/c Sl4Q== X-Gm-Message-State: AN3rC/4v0NepByhAweaJ0VCeaGUn7c1KwHc1sMmZhV0j6xCew9TUfurdKNgxMD4mregtUV0V X-Received: by 10.28.186.3 with SMTP id k3mr12613340wmf.74.1491909177311; Tue, 11 Apr 2017 04:12:57 -0700 (PDT) Received: from localhost.localdomain ([2.31.167.174]) by smtp.gmail.com with ESMTPSA id j138sm2069526wmg.10.2017.04.11.04.12.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Apr 2017 04:12:56 -0700 (PDT) From: Lee Jones To: hans.verkuil@cisco.com, mchehab@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, patrice.chotard@st.com, linux@armlinux.org.uk, Lee Jones Subject: [RESEND 2/2] [media] cec: Handle RC capability more elegantly Date: Tue, 11 Apr 2017 12:12:44 +0100 Message-Id: <20170411111244.29599-2-lee.jones@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170411111244.29599-1-lee.jones@linaro.org> References: <20170411111244.29599-1-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a user specifies the use of RC as a capability, they should really be enabling RC Core code. If they do not we WARN() them of this and disable the capability for them. Once we know RC Core code has not been enabled, we can update the user's capabilities and use them as a term of reference for other RC-only calls. This is preferable to having ugly #ifery scattered throughout C code. Most of the functions are actually safe to call, since they sensibly check for a NULL RC pointer before they attempt to deference it. Signed-off-by: Lee Jones --- drivers/media/cec/cec-core.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) -- 2.9.3 diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c index cfe414a..c859dcf 100644 --- a/drivers/media/cec/cec-core.c +++ b/drivers/media/cec/cec-core.c @@ -208,9 +208,15 @@ struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops, return ERR_PTR(-EINVAL); if (WARN_ON(!available_las || available_las > CEC_MAX_LOG_ADDRS)) return ERR_PTR(-EINVAL); + + /* If RC Core is not available, remove driver-level capability */ + if (!IS_REACHABLE(CONFIG_RC_CORE)) + caps &= ~CEC_CAP_RC; + adap = kzalloc(sizeof(*adap), GFP_KERNEL); if (!adap) return ERR_PTR(-ENOMEM); + strlcpy(adap->name, name, sizeof(adap->name)); adap->phys_addr = CEC_PHYS_ADDR_INVALID; adap->log_addrs.cec_version = CEC_OP_CEC_VERSION_2_0; @@ -237,7 +243,6 @@ struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops, if (!(caps & CEC_CAP_RC)) return adap; -#if IS_REACHABLE(CONFIG_RC_CORE) /* Prepare the RC input device */ adap->rc = rc_allocate_device(RC_DRIVER_SCANCODE); if (!adap->rc) { @@ -264,9 +269,7 @@ struct cec_adapter *cec_allocate_adapter(const struct cec_adap_ops *ops, adap->rc->priv = adap; adap->rc->map_name = RC_MAP_CEC; adap->rc->timeout = MS_TO_NS(100); -#else - adap->capabilities &= ~CEC_CAP_RC; -#endif + return adap; } EXPORT_SYMBOL_GPL(cec_allocate_adapter); @@ -285,7 +288,6 @@ int cec_register_adapter(struct cec_adapter *adap, adap->owner = parent->driver->owner; adap->devnode.dev.parent = parent; -#if IS_REACHABLE(CONFIG_RC_CORE) if (adap->capabilities & CEC_CAP_RC) { adap->rc->dev.parent = parent; res = rc_register_device(adap->rc); @@ -298,15 +300,13 @@ int cec_register_adapter(struct cec_adapter *adap, return res; } } -#endif res = cec_devnode_register(&adap->devnode, adap->owner); if (res) { -#if IS_REACHABLE(CONFIG_RC_CORE) /* Note: rc_unregister also calls rc_free */ rc_unregister_device(adap->rc); adap->rc = NULL; -#endif + return res; } @@ -337,11 +337,10 @@ void cec_unregister_adapter(struct cec_adapter *adap) if (IS_ERR_OR_NULL(adap)) return; -#if IS_REACHABLE(CONFIG_RC_CORE) /* Note: rc_unregister also calls rc_free */ rc_unregister_device(adap->rc); adap->rc = NULL; -#endif + debugfs_remove_recursive(adap->cec_dir); cec_devnode_unregister(&adap->devnode); } @@ -357,9 +356,7 @@ void cec_delete_adapter(struct cec_adapter *adap) kthread_stop(adap->kthread); if (adap->kthread_config) kthread_stop(adap->kthread_config); -#if IS_REACHABLE(CONFIG_RC_CORE) rc_free_device(adap->rc); -#endif kfree(adap); } EXPORT_SYMBOL_GPL(cec_delete_adapter);