From patchwork Wed Apr 12 15:39:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 97299 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp326224qgf; Wed, 12 Apr 2017 08:40:32 -0700 (PDT) X-Received: by 10.98.74.135 with SMTP id c7mr16923944pfj.140.1492011632857; Wed, 12 Apr 2017 08:40:32 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t5si20779560pgb.329.2017.04.12.08.40.32; Wed, 12 Apr 2017 08:40: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 S1754410AbdDLPkH (ORCPT + 17 others); Wed, 12 Apr 2017 11:40:07 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:35332 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752513AbdDLPkD (ORCPT ); Wed, 12 Apr 2017 11:40:03 -0400 Received: by mail-wm0-f41.google.com with SMTP id w64so91249839wma.0 for ; Wed, 12 Apr 2017 08:40:02 -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=zP/FCmfAPEjGvhxKfCM/diDVPdlmpLtz1x4mGXEdsTs=; b=ZiUdxMtmh/Vb7VgtoGOVTvhJPHtx/2lP29HXj+8NduOa9XX8LMwevBpoKFCqXK6foy 6MBQDX6LsuSquczLepIvptPWhXvJIB4Cxs+hoW02E4Zugkfr5eO+KmKjnu1tc2JjIQ0v dRPKiR+eZEbBcAbx2iW+iYM1kD7PmOlapQp/A= 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=zP/FCmfAPEjGvhxKfCM/diDVPdlmpLtz1x4mGXEdsTs=; b=FqLU1EnMnot7j5KOVHD/9LI35e9NvRcigsnKOzTGOsP1KRaLv9XeExjML4T3THyQEk /jzVAvgS3WmjHyt52PyuiRjIF0vKRoN5krjDVLU8JDMKVD4Q+b+uhVQ+bRVg4DHNgowu Z3a0d+WaRI+5z751D0F+Y0WXMebR/YajVR9TmbQw+8h/JQ2vnPZR0oXdwaHkUg3Gd2w9 CEduSRO2FF4LnWCowqyPR3h3+LRcUCAcK10ckjbsismPxKph1UHxoBJacGgUAyYAdiQU 7NUjapeSNxjQTZNopRb60BAYp1Y3JwX2NU4z3b8aXRVLqwG32gyQrX+7+V392iX+WCbZ EunQ== X-Gm-Message-State: AN3rC/4A80zlCcxYKfHfvTpp3b5PkMBRoGqF53eQ0yfs3OocTrdqWAno 11J0a3SWIL2IYKS5 X-Received: by 10.28.146.207 with SMTP id u198mr20143556wmd.103.1492011601615; Wed, 12 Apr 2017 08:40:01 -0700 (PDT) Received: from localhost.localdomain ([2.31.167.174]) by smtp.gmail.com with ESMTPSA id c8sm26055904wrd.57.2017.04.12.08.40.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Apr 2017 08:40:00 -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: [PATCH v2 1/2] [media] rc-core: Add inlined stubs for core rc_* functions Date: Wed, 12 Apr 2017 16:39:55 +0100 Message-Id: <20170412153956.13329-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 --- v1 => v2 - Use '#if IF_ENABLED()' instead of '#ifdef' in order to do the right thing, even when CONFIG_RC_CORE=m. 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..f176a9e 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. */ +#if IS_ENABLED(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 NULL; +} +#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. */ +#if IS_ENABLED(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 NULL; +} +#endif /** * rc_free_device - Frees a RC device * * @dev: pointer to struct rc_dev. */ +#if IS_ENABLED(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. */ +#if IS_ENABLED(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. */ +#if IS_ENABLED(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. */ +#if IS_ENABLED(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 Wed Apr 12 15:39:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 97298 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp326099qgf; Wed, 12 Apr 2017 08:40:14 -0700 (PDT) X-Received: by 10.99.225.5 with SMTP id z5mr68300693pgh.145.1492011614451; Wed, 12 Apr 2017 08:40:14 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 68si20816242pfo.80.2017.04.12.08.40.14; Wed, 12 Apr 2017 08:40:14 -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 S1754510AbdDLPkL (ORCPT + 17 others); Wed, 12 Apr 2017 11:40:11 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:35341 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754418AbdDLPkJ (ORCPT ); Wed, 12 Apr 2017 11:40:09 -0400 Received: by mail-wm0-f49.google.com with SMTP id w64so91250272wma.0 for ; Wed, 12 Apr 2017 08:40:08 -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=aKqHrYJcNrMco+FavAvw8ivM3dof1DNFfffw54XKouZ5cRsjfKMLXdacw9EgflPytK znHvGQsq7NM2I1s/dLSGy8YtYoorZ67M/lU1q/B6n+9hGspHw+Gg5+3dfSzatFq4ipLK 6KgGyGgCJFE1JAr+UAg6leu2LoCKZbtIuDa7o= 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=SHkosOvlMlQe5hP79xjW8lQz1ogtt4y/Asp7Qw9o2xe5Bq17lGbJpiYxRFkZEGoSfh 7y+UVDCbE7xIEqNU4fWdaKdcWyxU5SkgKYhmA5+0b87x2yKZEtMdztyVAOKXmXE/tf7d YDYYd7Y7Bo2tLYoEcRuvxUBxQiDtf/UG5oYIBmuFnZJQlRmoU5oYZbYbR/zmLT5BTHut p9oQ8Nnf5N2Kk5aWbDXZRzCyct5uM1r1bDoF0xP+9cns93EubsdnYgwDp9dSRmHHPeZ0 4dkACg110J0FtorZG3YqG48LLIWysQmxMoSfCFAtDhK/ZOuKl/SshXSwb77Np2ovLwUB 9cqg== X-Gm-Message-State: AN3rC/5isHjoM1MldnJhmvc8nOfpCr73f0UiO8RqJOx2n+A1J4i8yHbY kv7V4WeUDd99BjD1 X-Received: by 10.28.68.134 with SMTP id r128mr6013321wma.60.1492011602704; Wed, 12 Apr 2017 08:40:02 -0700 (PDT) Received: from localhost.localdomain ([2.31.167.174]) by smtp.gmail.com with ESMTPSA id c8sm26055904wrd.57.2017.04.12.08.40.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Apr 2017 08:40:02 -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: [PATCH v2 2/2] [media] cec: Handle RC capability more elegantly Date: Wed, 12 Apr 2017 16:39:56 +0100 Message-Id: <20170412153956.13329-2-lee.jones@linaro.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170412153956.13329-1-lee.jones@linaro.org> References: <20170412153956.13329-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);