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: 9662029 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7862A6032D for ; Tue, 4 Apr 2017 16:11:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68F392768C for ; Tue, 4 Apr 2017 16:11:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C12E2832D; Tue, 4 Apr 2017 16:11:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0ECF32768C for ; Tue, 4 Apr 2017 16:11:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=sSF2j6Ff6cQsV1H3QgtgreTby8Rt/yZEw+XNP+eZsoI=; b=nm77PtTotN3WXl3wj8GQfeAUbA 3xoZ3jXDrZFxZY2rAGekMkSShGjkJeVwSFDih6OAIR1nvEZCK3a8oKWAk/dpRsKGZfhYTpJwdd7sk RDhKOLCd2nvUtiL93AH3bBQm5gnpp/fmVfEq935Fv1w9yKGs8yYlXrqVLxn8DYIgZaDwGLGzoaUNF VUG3i3qceusC/3t7eREM+3XhMA0s9WO1NaQtT77jGry4ZU3K4XcmRrqTxny1m0kJFTVIryblHfGM/ 2czAKp7SDmGDlcuijQ6IjEvQuEE6bAqeLzmB0d0sm0XY6IzofVuBGwjGf6W3xwKEjVpBZT7PM0kOO tXUXkQUw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cvR2o-0005FV-IF; Tue, 04 Apr 2017 16:10:58 +0000 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cvR2R-0004hr-2D for linux-arm-kernel@lists.infradead.org; Tue, 04 Apr 2017 16:10:37 +0000 Received: by mail-wm0-x229.google.com with SMTP id x124so32533839wmf.0 for ; Tue, 04 Apr 2017 09:10:14 -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=f6OQvsCkBo6xK7iomKs2exI7St1HdV7asDk5vE1tlfqJNB7UcqduwXP1aPZr3C3Y2T 7jyvrTCpOkY5noS74RiryVKX4QkOTSF7x9gbgkRQIfoDQqmyV+ecT612Oj93LqeIHzHN DRzjr/Svzo2hGlkkV+uDG51EvJ7ZDHcHqQw//+RbR1fR11rbWGfAfSDwa/GxHlurHdw6 ihh9ZdQLYVgB4IOa5TU1ixGXdr5Wrc0FoZc24QpGMJlOyCZyf1jRfAtNXZsZ1v2kU8HM xuygjuMN04+x6CkDByIE4ba04A+a+5VcS6pmWzKcstmSyuZZq7lZuwrWnI4Cig2FlBoS ByaA== X-Gm-Message-State: AFeK/H2tGOUys3RlQNS0rX24u6zGueqPAkAuxFOYtYDf583Ga1wazqnQ LxHz8h+B8esePR2F 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170404_091035_288399_642BD4C8 X-CRM114-Status: GOOD ( 14.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: benjamin.gaignard@st.com, patrice.chotard@st.com, linux-kernel@vger.kernel.org, kernel@stlinux.com, Lee Jones , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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);