From patchwork Tue Apr 4 16:10:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 96753 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp266636qgd; Tue, 4 Apr 2017 09:10:24 -0700 (PDT) X-Received: by 10.99.146.7 with SMTP id o7mr24584070pgd.6.1491322224500; Tue, 04 Apr 2017 09:10:24 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 125si2081070pfe.397.2017.04.04.09.10.24; Tue, 04 Apr 2017 09:10:24 -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 S932227AbdDDQKP (ORCPT + 25 others); Tue, 4 Apr 2017 12:10:15 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:32787 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932184AbdDDQKM (ORCPT ); Tue, 4 Apr 2017 12:10:12 -0400 Received: by mail-wm0-f41.google.com with SMTP id x89so769059wma.0 for ; Tue, 04 Apr 2017 09:10:11 -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; bh=V11tzwUZnyF23Frqr30bLLVSCATmNHyWC9g2Wi+dGPM=; b=QAMEifmru45YvoPDJiKKTKYJXcASsEYpmGVHKVFOCkKm+LFf+hX4GDoraY+AKU1plO O1bI4NjaXRLbnEPzM0KbpiF4rlmRoUhosuOKeqrHPBtzcuG/sKcc/2Th24z+Tdc0ZjO1 II5g2LAJorwD2BwAEO6+k2QL3vnOD2+UzMzYM= 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; bh=V11tzwUZnyF23Frqr30bLLVSCATmNHyWC9g2Wi+dGPM=; b=BkJIn+LpHIvuldgrPGjjkjDrQoHXx8MHS48hYPeGkxNtNsWnUD70LGYqFg2MbgIVmv fuQW4/i20oJG8HNlRc3kFENVg9zP/kZTIh9cFR777BUjbSn/tHyUr4OAh+gbAhz+vGKq 1aFyHnpEy7DzLkXh9zHBbi5QGJ2UVknDlomheEgtCwGXdZTWWp7jk+An91+cmW/+sA/6 /MGXIeIpzHJDXwWfsyvZkWbqsqcjwz9seE7i4bU3jszNUbtaOHrOxCT9gHX9vmadQORm jEAkMvvWYjS1jJQbLcpkjrxpP4MBdR/RqjfH3sYcTVz1K4NfCagQI98OqAV7qBTW9Gj7 FF7w== X-Gm-Message-State: AFeK/H0spAHtwWq2vJ2OxwFJ+s8JjTHHkI2z9GYTjW9pdYoU+4dP980C7hpmgCQyFrMzaO8m X-Received: by 10.28.91.82 with SMTP id p79mr15179568wmb.130.1491322210909; Tue, 04 Apr 2017 09:10:10 -0700 (PDT) Received: from localhost.localdomain ([2.31.167.174]) by smtp.gmail.com with ESMTPSA id j77sm18971292wmj.3.2017.04.04.09.10.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 09:10:10 -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, kernel@stlinux.com, patrice.chotard@st.com, linux-media@vger.kernel.org, benjamin.gaignard@st.com, Lee Jones Subject: [PATCH 1/2] [media] rc-core: Add inlined stubs for core rc_* functions Date: Tue, 4 Apr 2017 17:10:04 +0100 Message-Id: <20170404161005.20884-1-lee.jones@linaro.org> X-Mailer: git-send-email 2.9.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently users have to use all sorts of ugly #ifery within their drivers in order to avoid linking issues at build time. This patch allows users to safely call these functions when !CONFIG_RC_CORE and make decisions based on the return value instead. This is a much more common and clean way of doing things within the Linux kernel. Signed-off-by: Lee Jones --- include/media/rc-core.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) -- 2.9.3 diff --git a/include/media/rc-core.h b/include/media/rc-core.h index 73ddd721..1f2043d 100644 --- a/include/media/rc-core.h +++ b/include/media/rc-core.h @@ -209,7 +209,14 @@ struct rc_dev { * @rc_driver_type: specifies the type of the RC output to be allocated * returns a pointer to struct rc_dev. */ +#ifdef CONFIG_RC_CORE struct rc_dev *rc_allocate_device(enum rc_driver_type); +#else +static inline struct rc_dev *rc_allocate_device(int unused) +{ + return ERR_PTR(-EOPNOTSUPP); +} +#endif /** * devm_rc_allocate_device - Managed RC device allocation @@ -218,21 +225,42 @@ struct rc_dev *rc_allocate_device(enum rc_driver_type); * @rc_driver_type: specifies the type of the RC output to be allocated * returns a pointer to struct rc_dev. */ +#ifdef CONFIG_RC_CORE struct rc_dev *devm_rc_allocate_device(struct device *dev, enum rc_driver_type); +#else +static inline struct rc_dev *devm_rc_allocate_device(struct device *dev, int unused) +{ + return ERR_PTR(-EOPNOTSUPP); +} +#endif /** * rc_free_device - Frees a RC device * * @dev: pointer to struct rc_dev. */ +#ifdef CONFIG_RC_CORE void rc_free_device(struct rc_dev *dev); +#else +static inline void rc_free_device(struct rc_dev *dev) +{ + return; +} +#endif /** * rc_register_device - Registers a RC device * * @dev: pointer to struct rc_dev. */ +#ifdef CONFIG_RC_CORE int rc_register_device(struct rc_dev *dev); +#else +static inline int rc_register_device(struct rc_dev *dev) +{ + return -EOPNOTSUPP; +} +#endif /** * devm_rc_register_device - Manageded registering of a RC device @@ -240,14 +268,28 @@ int rc_register_device(struct rc_dev *dev); * @parent: pointer to struct device. * @dev: pointer to struct rc_dev. */ +#ifdef CONFIG_RC_CORE int devm_rc_register_device(struct device *parent, struct rc_dev *dev); +#else +static inline int devm_rc_register_device(struct device *parent, struct rc_dev *dev) +{ + return -EOPNOTSUPP; +} +#endif /** * rc_unregister_device - Unregisters a RC device * * @dev: pointer to struct rc_dev. */ +#ifdef CONFIG_RC_CORE void rc_unregister_device(struct rc_dev *dev); +#else +static inline void rc_unregister_device(struct rc_dev *dev) +{ + return; +} +#endif /** * rc_open - Opens a RC device From patchwork Tue Apr 4 16:10:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 96754 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp266641qgd; Tue, 4 Apr 2017 09:10:25 -0700 (PDT) X-Received: by 10.84.197.3 with SMTP id m3mr29893491pld.89.1491322224920; Tue, 04 Apr 2017 09:10:24 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 125si2081070pfe.397.2017.04.04.09.10.24; Tue, 04 Apr 2017 09:10:24 -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 S932258AbdDDQKV (ORCPT + 25 others); Tue, 4 Apr 2017 12:10:21 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:32789 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932127AbdDDQKS (ORCPT ); Tue, 4 Apr 2017 12:10:18 -0400 Received: by mail-wm0-f47.google.com with SMTP id x89so769142wma.0 for ; Tue, 04 Apr 2017 09:10:17 -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=zKoKQs+CJdDJ56k6UiAV7sQ+Re4BpS9+cOFzhuD0TcM=; b=ALNUBJm9Z5Y+qK1lFRE7ObpANc8pzRNVdq+sYqHMc3y2a8UJG91YerFPTPctT1Poax 6vMfG0pIFLKHFa0pLJ6EDRpT+PTEfXre23x0s1vUqjnzcHWsyStcd1uYsWYIw6ppzmnT +LrV4pJVq3xMNK1iWrbEob2rUW+XVNCHetF9Y= 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=zKoKQs+CJdDJ56k6UiAV7sQ+Re4BpS9+cOFzhuD0TcM=; b=OXrir+RgQZDdIzSwcRYlQ4hinUU8M3UYzgscTTo3E7J6qsQOiaIArr6kFNfvJ06rEx MJqpiZMktnRc1mkUKoaBPOGVUqtzyG15PMZ+wFxkm9wMNrxjUd2hQQZrONML8Wi3YrHg k/Z8byNLKfTkMITKuJ979fFntRKAZRKzF+N0kf3YLV7KX7hcKAHW+Gvf38fDJHFnHQU5 NRagrXflaL6UcVJTbL20Lmzxl1Qkr91cZYkflkb5Z9gYkzeiBLQG739NrJTTwkmLYn1L OLHBYQOFzkzvDi8YxXSVCiCFE5rz8svRV/cn5PqvwSe5FNN0j73quI0PSgLAs80wz1qG VN4w== X-Gm-Message-State: AFeK/H3dHSzcisEB7xXhLHKHlgj/x3Dydvr61Keiz3rmffwTJmtslqFR c11bUVGvICDezLN1 X-Received: by 10.28.103.138 with SMTP id b132mr15146886wmc.79.1491322212046; Tue, 04 Apr 2017 09:10:12 -0700 (PDT) Received: from localhost.localdomain ([2.31.167.174]) by smtp.gmail.com with ESMTPSA id j77sm18971292wmj.3.2017.04.04.09.10.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Apr 2017 09:10:11 -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, kernel@stlinux.com, patrice.chotard@st.com, linux-media@vger.kernel.org, benjamin.gaignard@st.com, Lee Jones Subject: [PATCH 2/2] [media] cec: Handle RC capability more elegantly Date: Tue, 4 Apr 2017 17:10:05 +0100 Message-Id: <20170404161005.20884-2-lee.jones@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170404161005.20884-1-lee.jones@linaro.org> References: <20170404161005.20884-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 | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) -- 2.9.3 diff --git a/drivers/media/cec/cec-core.c b/drivers/media/cec/cec-core.c index cfe414a..51be8d6 100644 --- a/drivers/media/cec/cec-core.c +++ b/drivers/media/cec/cec-core.c @@ -208,9 +208,13 @@ 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 (WARN_ON(caps & CEC_CAP_RC && !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 +241,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 +267,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 +286,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 +298,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 +335,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 +354,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);