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: 40598 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cvR2t-00065m-7A; Tue, 04 Apr 2017 16:11:03 +0000 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.84_2/mailfrontend-8) with esmtp id 1cvR2r-0001JJ-jF; Tue, 04 Apr 2017 18:11:03 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932131AbdDDQK7 (ORCPT + 1 other); Tue, 4 Apr 2017 12:10:59 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:38065 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932187AbdDDQKN (ORCPT ); Tue, 4 Apr 2017 12:10:13 -0400 Received: by mail-wm0-f41.google.com with SMTP id t189so32429200wmt.1 for ; Tue, 04 Apr 2017 09:10:12 -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=kduUadx/zO4ZDuoPWVTDXP1bsxGmVXs+9Rira9SXA8969nb04NR6cAqSFxJ0EEt1iP ms234XZfiI4bmeD2NepbiQKUZyz9SWgh2AAXdTz4QBR09BO4PE05a6xCWUb4fdiUPYZA jwjCm1jkxx5z6Sfj1QEtmEqnnRi730aoh7AxAla48ixf6Y/rkRNKboGl2Mqyw/luXNDC iNtpA1DUQHfJCFySoJ3XX/v4AKML7TivjJ17GoFSAOKlSUhcs1kMkQNOt8hxvVznkOYP 4fw5HhIAVt2fG9HKb39TInRrd1cvwuGUNtZZLs8lSvSxFrIQnL0iY0fGMHYTcftrm6uF NDUA== X-Gm-Message-State: AFeK/H1+EAGc7oCtPmgWMt1QpTDzSbk3/jc4Rfuz7wLC/qzdBPcxEf8W rxWRBM5dKi+mYq49 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-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2017.4.4.160018 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, DKIM_SIGNATURE 0, IN_REP_TO 0, LEGITIMATE_SIGNS 0, MSG_THREAD 0, MULTIPLE_REAL_RCPTS 0, NO_URI_HTTPS 0, REFERENCES 0, __ANY_URI 0, __CC_NAME 0, __CC_NAME_DIFF_FROM_ACC 0, __CC_REAL_NAMES 0, __FROM_DOMAIN_IN_ANY_CC2 0, __FROM_DOMAIN_IN_RCPT 0, __HAS_CC_HDR 0, __HAS_FROM 0, __HAS_LIST_ID 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_TEXT_P 0, __MIME_TEXT_P1 0, __MULTIPLE_RCPTS_CC_X2 0, __NO_HTML_TAG_RAW 0, __REFERENCES 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS , __YOUTUBE_RCVD 0' 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);