From patchwork Mon Apr 8 11:03:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10889303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 78761922 for ; Mon, 8 Apr 2019 11:04:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F86928699 for ; Mon, 8 Apr 2019 11:04:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 535F0286C2; Mon, 8 Apr 2019 11:04:12 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1621286C4 for ; Mon, 8 Apr 2019 11:04:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726528AbfDHLEL (ORCPT ); Mon, 8 Apr 2019 07:04:11 -0400 Received: from lb3-smtp-cloud7.xs4all.net ([194.109.24.31]:57557 "EHLO lb3-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726462AbfDHLEG (ORCPT ); Mon, 8 Apr 2019 07:04:06 -0400 Received: from marune.fritz.box ([IPv6:2001:983:e9a7:1:1170:5c87:411e:5806]) by smtp-cloud7.xs4all.net with ESMTPA id DS4HhTHSRNG8zDS4JhlZOE; Mon, 08 Apr 2019 13:04:04 +0200 From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Neil Armstrong , Sylwester Nawrocki , Benjamin Gaignard , Thierry Reding , Ettore Chimenti , Wen Yang , Hans Verkuil Subject: [PATCH 1/7] cec-notifier: add cec_notifier_find_hdmi_dev helper Date: Mon, 8 Apr 2019 13:03:55 +0200 Message-Id: <20190408110401.3345-2-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190408110401.3345-1-hverkuil-cisco@xs4all.nl> References: <20190408110401.3345-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfLfSxf2AE183XfVVV6a2UI5fWTLb1QG/s1qtjC0Ua/wMBndy1sPfxlIxGHM5STR4zSj/Lt5IzFLx7G9yPKYmaE3SZASt5x53vt9DqIfMFzPU3m8fJszo 4qxh7gPZbg/ZDTbLREIF8C+D8bFg9S5ztYjRkWUxA/SavgSI3C+rNp9LiBAulbvhqISTZDUEkPPOO8fYoRqZzbNQ5ax9pp2r1EucYz6CbIg/HSxGdlRYPLtY xWlbj0LB/hTrBztSuNvstStN6r2ZfRjDXV90Aj0qw9Fh9oN0Mr4yiHVNPqRRX/UG71uTIupcL2UNmaJO8UaHktnNT1DcEqCfTAkkdC4aefTkoU699APhMJo5 48lfdn9jSMIWyRJIaum867Z7+iJT/LYABKKA7i6LZat9Ez+cOwtTnVQjyPo31styIjtDraTqBJI0Xj7eTG4zd/BhsMPzcLNu+ohABQ+9fxeLRWEO+EodVr1x y6EbhNTZ5RasFnnc2TzEcllOgCThtfLJtHRiNQ== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add helper function to parse the DT for the hdmi-phandle property and find the corresponding struct device pointer. It takes care to avoid increasing the device refcount since all we need is the device pointer. This pointer is used in the notifier list as a key, but it is never accessed by the CEC driver. Signed-off-by: Hans Verkuil Reported-by: Wen Yang --- drivers/media/cec/cec-notifier.c | 24 ++++++++++++++++++++++++ include/media/cec-notifier.h | 19 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/media/cec/cec-notifier.c b/drivers/media/cec/cec-notifier.c index dd2078b27a41..870b3788e9f7 100644 --- a/drivers/media/cec/cec-notifier.c +++ b/drivers/media/cec/cec-notifier.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -127,3 +128,26 @@ void cec_notifier_unregister(struct cec_notifier *n) cec_notifier_put(n); } EXPORT_SYMBOL_GPL(cec_notifier_unregister); + +struct device *cec_notifier_find_hdmi_dev(struct device *dev) +{ + struct platform_device *hdmi_pdev; + struct device *hdmi_dev = NULL; + struct device_node *np; + + np = of_parse_phandle(dev->of_node, "hdmi-phandle", 0); + + if (!np) { + dev_err(dev, "Failed to find hdmi node in device tree\n"); + return ERR_PTR(-ENODEV); + } + hdmi_pdev = of_find_device_by_node(np); + of_node_put(np); + if (hdmi_pdev) { + hdmi_dev = &hdmi_pdev->dev; + put_device(hdmi_dev); + return hdmi_dev; + } + return ERR_PTR(-EPROBE_DEFER); +} +EXPORT_SYMBOL_GPL(cec_notifier_find_hdmi_dev); diff --git a/include/media/cec-notifier.h b/include/media/cec-notifier.h index 814eeef35a5c..ff4d6e0ea3d4 100644 --- a/include/media/cec-notifier.h +++ b/include/media/cec-notifier.h @@ -9,7 +9,7 @@ #ifndef LINUX_CEC_NOTIFIER_H #define LINUX_CEC_NOTIFIER_H -#include +#include #include struct device; @@ -87,6 +87,17 @@ void cec_notifier_unregister(struct cec_notifier *n); void cec_register_cec_notifier(struct cec_adapter *adap, struct cec_notifier *notifier); +/** + * cec_notifier_find_hdmi_dev - find the hdmi device from "hdmi-phandle" + * @dev: the device with the "hdmi-phandle" device tree property + * + * Returns the device pointer referenced by the "hdmi-phandle" property. + * Note that the refcount of the returned device is not incremented. + * This device pointer is only used as a key value in the notifier + * list, but it is never accessed by the CEC driver. + */ +struct device *cec_notifier_find_hdmi_dev(struct device *dev); + #else static inline struct cec_notifier *cec_notifier_get_conn(struct device *dev, const char *conn) @@ -122,6 +133,12 @@ static inline void cec_register_cec_notifier(struct cec_adapter *adap, struct cec_notifier *notifier) { } + +static inline struct device *cec_notifier_find_hdmi_dev(struct device *dev) +{ + return ERR_PTR(-ENODEV); +} + #endif /** From patchwork Mon Apr 8 11:03:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10889293 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9EE17922 for ; Mon, 8 Apr 2019 11:04:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B5DC286FF for ; Mon, 8 Apr 2019 11:04:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 798242870E; Mon, 8 Apr 2019 11:04:07 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EC0228701 for ; Mon, 8 Apr 2019 11:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726507AbfDHLEG (ORCPT ); Mon, 8 Apr 2019 07:04:06 -0400 Received: from lb3-smtp-cloud7.xs4all.net ([194.109.24.31]:46103 "EHLO lb3-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726456AbfDHLEG (ORCPT ); Mon, 8 Apr 2019 07:04:06 -0400 Received: from marune.fritz.box ([IPv6:2001:983:e9a7:1:1170:5c87:411e:5806]) by smtp-cloud7.xs4all.net with ESMTPA id DS4HhTHSRNG8zDS4KhlZOP; Mon, 08 Apr 2019 13:04:04 +0200 From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Neil Armstrong , Sylwester Nawrocki , Benjamin Gaignard , Thierry Reding , Ettore Chimenti , Wen Yang , Hans Verkuil Subject: [PATCH 2/7] meson: ao-cec: use new cec_notifier_find_hdmi_dev helper Date: Mon, 8 Apr 2019 13:03:56 +0200 Message-Id: <20190408110401.3345-3-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190408110401.3345-1-hverkuil-cisco@xs4all.nl> References: <20190408110401.3345-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfLfSxf2AE183XfVVV6a2UI5fWTLb1QG/s1qtjC0Ua/wMBndy1sPfxlIxGHM5STR4zSj/Lt5IzFLx7G9yPKYmaE3SZASt5x53vt9DqIfMFzPU3m8fJszo 4qxh7gPZbg/ZDTbLREIF8C+D8bFg9S5ztYjRkWUxA/SavgSI3C+rNp9LiBAulbvhqISTZDUEkPPOO8fYoRqZzbNQ5ax9pp2r1EucYz6CbIg/HSxGdlRYPLtY xWlbj0LB/hTrBztSuNvstStN6r2ZfRjDXV90Aj0qw9Fh9oN0Mr4yiHVNPqRRX/UG71uTIupcL2UNmaJO8UaHktnNT1DcEqCfTAkkdC4aefTkoU699APhMJo5 48lfdn9jSMIWyRJIaum867Z7+iJT/LYABKKA7i6LZat9Ez+cOwtTnVQjyPo31styIjtDraTqBJI0Xj7eTG4zd/BhsMPzcLNu+ohABQ+9fxeLRWEO+EodVr1x y6EbhNTZ5RasFnnc2TzEcllOgCThtfLJtHRiNQ== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The meson CEC driver increased the HDMI device refcount when it shouldn't. Use the new helper function to ensure that that doesn't happen and to simplify the driver code. Signed-off-by: Hans Verkuil Acked-by: Neil Armstrong --- drivers/media/platform/meson/ao-cec.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/meson/ao-cec.c b/drivers/media/platform/meson/ao-cec.c index cd4be38ab5ac..c8b374741a7c 100644 --- a/drivers/media/platform/meson/ao-cec.c +++ b/drivers/media/platform/meson/ao-cec.c @@ -601,20 +601,14 @@ static const struct cec_adap_ops meson_ao_cec_ops = { static int meson_ao_cec_probe(struct platform_device *pdev) { struct meson_ao_cec_device *ao_cec; - struct platform_device *hdmi_dev; - struct device_node *np; + struct device *hdmi_dev; struct resource *res; int ret, irq; - np = of_parse_phandle(pdev->dev.of_node, "hdmi-phandle", 0); - if (!np) { - dev_err(&pdev->dev, "Failed to find hdmi node\n"); - return -ENODEV; - } + hdmi_dev = cec_notifier_find_hdmi_dev(&pdev->dev); - hdmi_dev = of_find_device_by_node(np); - if (hdmi_dev == NULL) - return -EPROBE_DEFER; + if (IS_ERR(hdmi_dev)) + return PTR_ERR(hdmi_dev); ao_cec = devm_kzalloc(&pdev->dev, sizeof(*ao_cec), GFP_KERNEL); if (!ao_cec) @@ -622,7 +616,7 @@ static int meson_ao_cec_probe(struct platform_device *pdev) spin_lock_init(&ao_cec->cec_reg_lock); - ao_cec->notify = cec_notifier_get(&hdmi_dev->dev); + ao_cec->notify = cec_notifier_get(hdmi_dev); if (!ao_cec->notify) return -ENOMEM; From patchwork Mon Apr 8 11:03:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10889301 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B9C951390 for ; Mon, 8 Apr 2019 11:04:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A230428699 for ; Mon, 8 Apr 2019 11:04:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A02A5286F1; Mon, 8 Apr 2019 11:04:10 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36F9C28699 for ; Mon, 8 Apr 2019 11:04:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726523AbfDHLEI (ORCPT ); Mon, 8 Apr 2019 07:04:08 -0400 Received: from lb2-smtp-cloud7.xs4all.net ([194.109.24.28]:41679 "EHLO lb2-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725984AbfDHLEF (ORCPT ); Mon, 8 Apr 2019 07:04:05 -0400 Received: from marune.fritz.box ([IPv6:2001:983:e9a7:1:1170:5c87:411e:5806]) by smtp-cloud7.xs4all.net with ESMTPA id DS4HhTHSRNG8zDS4KhlZOa; Mon, 08 Apr 2019 13:04:04 +0200 From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Neil Armstrong , Sylwester Nawrocki , Benjamin Gaignard , Thierry Reding , Ettore Chimenti , Wen Yang , Hans Verkuil Subject: [PATCH 3/7] s5p_cec: use new cec_notifier_find_hdmi_dev helper Date: Mon, 8 Apr 2019 13:03:57 +0200 Message-Id: <20190408110401.3345-4-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190408110401.3345-1-hverkuil-cisco@xs4all.nl> References: <20190408110401.3345-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfLfSxf2AE183XfVVV6a2UI5fWTLb1QG/s1qtjC0Ua/wMBndy1sPfxlIxGHM5STR4zSj/Lt5IzFLx7G9yPKYmaE3SZASt5x53vt9DqIfMFzPU3m8fJszo 4qxh7gPZbg/ZDTbLREIF8C+D8bFg9S5ztYjRkWUxA/SavgSI3C+rNp9LiBAulbvhqISTZDUEkPPOO8fYoRqZzbNQ5ax9pp2r1EucYz6CbIg/HSxGdlRYPLtY xWlbj0LB/hTrBztSuNvstStN6r2ZfRjDXV90Aj0qw9Fh9oN0Mr4yiHVNPqRRX/UG71uTIupcL2UNmaJO8UaHktnNT1DcEqCfTAkkdC4aefTkoU699APhMJo5 48lfdn9jSMIWyRJIaum867Z7+iJT/LYABKKA7i6LZat9Ez+cOwtTnVQjyPo31styIjtDraTqBJI0Xj7eTG4zd/BhsMPzcLNu+ohABQ+9fxeLRWEO+EodVr1x y6EbhNTZ5RasFnnc2TzEcllOgCThtfLJtHRiNQ== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The S5P CEC driver increased the HDMI device refcount when it shouldn't. Use the new helper function to ensure that that doesn't happen and to simplify the driver code. Signed-off-by: Hans Verkuil --- drivers/media/platform/s5p-cec/s5p_cec.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/media/platform/s5p-cec/s5p_cec.c b/drivers/media/platform/s5p-cec/s5p_cec.c index 8837e2678bde..7e2c94816c55 100644 --- a/drivers/media/platform/s5p-cec/s5p_cec.c +++ b/drivers/media/platform/s5p-cec/s5p_cec.c @@ -178,22 +178,16 @@ static const struct cec_adap_ops s5p_cec_adap_ops = { static int s5p_cec_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct device_node *np; - struct platform_device *hdmi_dev; + struct device *hdmi_dev; struct resource *res; struct s5p_cec_dev *cec; bool needs_hpd = of_property_read_bool(pdev->dev.of_node, "needs-hpd"); int ret; - np = of_parse_phandle(pdev->dev.of_node, "hdmi-phandle", 0); + hdmi_dev = cec_notifier_find_hdmi_dev(dev); - if (!np) { - dev_err(&pdev->dev, "Failed to find hdmi node in device tree\n"); - return -ENODEV; - } - hdmi_dev = of_find_device_by_node(np); - if (hdmi_dev == NULL) - return -EPROBE_DEFER; + if (IS_ERR(hdmi_dev)) + return PTR_ERR(hdmi_dev); cec = devm_kzalloc(&pdev->dev, sizeof(*cec), GFP_KERNEL); if (!cec) @@ -224,7 +218,7 @@ static int s5p_cec_probe(struct platform_device *pdev) if (IS_ERR(cec->reg)) return PTR_ERR(cec->reg); - cec->notifier = cec_notifier_get(&hdmi_dev->dev); + cec->notifier = cec_notifier_get(hdmi_dev); if (cec->notifier == NULL) return -ENOMEM; From patchwork Mon Apr 8 11:03:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10889297 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D19121390 for ; Mon, 8 Apr 2019 11:04:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B89F9286A2 for ; Mon, 8 Apr 2019 11:04:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B641A286B5; Mon, 8 Apr 2019 11:04:09 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A189286A8 for ; Mon, 8 Apr 2019 11:04:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726512AbfDHLEH (ORCPT ); Mon, 8 Apr 2019 07:04:07 -0400 Received: from lb1-smtp-cloud7.xs4all.net ([194.109.24.24]:60226 "EHLO lb1-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726471AbfDHLEG (ORCPT ); Mon, 8 Apr 2019 07:04:06 -0400 Received: from marune.fritz.box ([IPv6:2001:983:e9a7:1:1170:5c87:411e:5806]) by smtp-cloud7.xs4all.net with ESMTPA id DS4HhTHSRNG8zDS4KhlZOn; Mon, 08 Apr 2019 13:04:04 +0200 From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Neil Armstrong , Sylwester Nawrocki , Benjamin Gaignard , Thierry Reding , Ettore Chimenti , Wen Yang , Hans Verkuil Subject: [PATCH 4/7] stih_cec: use new cec_notifier_find_hdmi_dev helper Date: Mon, 8 Apr 2019 13:03:58 +0200 Message-Id: <20190408110401.3345-5-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190408110401.3345-1-hverkuil-cisco@xs4all.nl> References: <20190408110401.3345-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfLfSxf2AE183XfVVV6a2UI5fWTLb1QG/s1qtjC0Ua/wMBndy1sPfxlIxGHM5STR4zSj/Lt5IzFLx7G9yPKYmaE3SZASt5x53vt9DqIfMFzPU3m8fJszo 4qxh7gPZbg/ZDTbLREIF8C+D8bFg9S5ztYjRkWUxA/SavgSI3C+rNp9LiBAulbvhqISTZDUEkPPOO8fYoRqZzbNQ5ax9pp2r1EucYz6CbIg/HSxGdlRYPLtY xWlbj0LB/hTrBztSuNvstStN6r2ZfRjDXV90Aj0qw9Fh9oN0Mr4yiHVNPqRRX/UG71uTIupcL2UNmaJO8UaHktnNT1DcEqCfTAkkdC4aefTkoU699APhMJo5 48lfdn9jSMIWyRJIaum867Z7+iJT/LYABKKA7i6LZat9Ez+cOwtTnVQjyPo31styIjtDraTqBJI0Xj7eTG4zd/BhsMPzcLNu+ohABQ+9fxeLRWEO+EodVr1x y6EbhNTZ5RasFnnc2TzEcllOgCThtfLJtHRiNQ== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The STI CEC driver increased the HDMI device refcount when it shouldn't. Use the new helper function to ensure that that doesn't happen and to simplify the driver code. Signed-off-by: Hans Verkuil Acked-by: Benjamin Gaignard --- drivers/media/platform/sti/cec/stih-cec.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/drivers/media/platform/sti/cec/stih-cec.c b/drivers/media/platform/sti/cec/stih-cec.c index d34099f75990..678d7cb38637 100644 --- a/drivers/media/platform/sti/cec/stih-cec.c +++ b/drivers/media/platform/sti/cec/stih-cec.c @@ -301,26 +301,19 @@ static int stih_cec_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct resource *res; struct stih_cec *cec; - struct device_node *np; - struct platform_device *hdmi_dev; + struct device *hdmi_dev; int ret; + hdmi_dev = cec_notifier_find_hdmi_dev(dev); + + if (IS_ERR(hdmi_dev)) + return PTR_ERR(hdmi_dev); + cec = devm_kzalloc(dev, sizeof(*cec), GFP_KERNEL); if (!cec) return -ENOMEM; - np = of_parse_phandle(pdev->dev.of_node, "hdmi-phandle", 0); - - if (!np) { - dev_err(&pdev->dev, "Failed to find hdmi node in device tree\n"); - return -ENODEV; - } - - hdmi_dev = of_find_device_by_node(np); - if (!hdmi_dev) - return -EPROBE_DEFER; - - cec->notifier = cec_notifier_get(&hdmi_dev->dev); + cec->notifier = cec_notifier_get(hdmi_dev); if (!cec->notifier) return -ENOMEM; From patchwork Mon Apr 8 11:03:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10889305 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C640922 for ; Mon, 8 Apr 2019 11:04:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3401E286AE for ; Mon, 8 Apr 2019 11:04:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31A55286D3; Mon, 8 Apr 2019 11:04:14 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C121628708 for ; Mon, 8 Apr 2019 11:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726509AbfDHLEG (ORCPT ); Mon, 8 Apr 2019 07:04:06 -0400 Received: from lb1-smtp-cloud7.xs4all.net ([194.109.24.24]:50583 "EHLO lb1-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726464AbfDHLEG (ORCPT ); Mon, 8 Apr 2019 07:04:06 -0400 Received: from marune.fritz.box ([IPv6:2001:983:e9a7:1:1170:5c87:411e:5806]) by smtp-cloud7.xs4all.net with ESMTPA id DS4HhTHSRNG8zDS4KhlZP2; Mon, 08 Apr 2019 13:04:04 +0200 From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Neil Armstrong , Sylwester Nawrocki , Benjamin Gaignard , Thierry Reding , Ettore Chimenti , Wen Yang , Hans Verkuil Subject: [PATCH 5/7] tegra_cec: use new cec_notifier_find_hdmi_dev helper Date: Mon, 8 Apr 2019 13:03:59 +0200 Message-Id: <20190408110401.3345-6-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190408110401.3345-1-hverkuil-cisco@xs4all.nl> References: <20190408110401.3345-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfLfSxf2AE183XfVVV6a2UI5fWTLb1QG/s1qtjC0Ua/wMBndy1sPfxlIxGHM5STR4zSj/Lt5IzFLx7G9yPKYmaE3SZASt5x53vt9DqIfMFzPU3m8fJszo 4qxh7gPZbg/ZDTbLREIF8C+D8bFg9S5ztYjRkWUxA/SavgSI3C+rNp9LiBAulbvhqISTZDUEkPPOO8fYoRqZzbNQ5ax9pp2r1EucYz6CbIg/HSxGdlRYPLtY xWlbj0LB/hTrBztSuNvstStN6r2ZfRjDXV90Aj0qw9Fh9oN0Mr4yiHVNPqRRX/UG71uTIupcL2UNmaJO8UaHktnNT1DcEqCfTAkkdC4aefTkoU699APhMJo5 48lfdn9jSMIWyRJIaum867Z7+iJT/LYABKKA7i6LZat9Ez+cOwtTnVQjyPo31styIjtDraTqBJI0Xj7eTG4zd/BhsMPzcLNu+ohABQ+9fxeLRWEO+EodVr1x y6EbhNTZ5RasFnnc2TzEcllOgCThtfLJtHRiNQ== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The Tegra CEC driver increased the HDMI device refcount when it shouldn't. Use the new helper function to ensure that that doesn't happen and to simplify the driver code. Signed-off-by: Hans Verkuil --- drivers/media/platform/tegra-cec/tegra_cec.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/media/platform/tegra-cec/tegra_cec.c b/drivers/media/platform/tegra-cec/tegra_cec.c index aba488cd0e64..074d647f2908 100644 --- a/drivers/media/platform/tegra-cec/tegra_cec.c +++ b/drivers/media/platform/tegra-cec/tegra_cec.c @@ -327,21 +327,15 @@ static const struct cec_adap_ops tegra_cec_ops = { static int tegra_cec_probe(struct platform_device *pdev) { - struct platform_device *hdmi_dev; - struct device_node *np; + struct device *hdmi_dev; struct tegra_cec *cec; struct resource *res; int ret = 0; - np = of_parse_phandle(pdev->dev.of_node, "hdmi-phandle", 0); + hdmi_dev = cec_notifier_find_hdmi_dev(&pdev->dev); - if (!np) { - dev_err(&pdev->dev, "Failed to find hdmi node in device tree\n"); + if (!hdmi_dev) return -ENODEV; - } - hdmi_dev = of_find_device_by_node(np); - if (hdmi_dev == NULL) - return -EPROBE_DEFER; cec = devm_kzalloc(&pdev->dev, sizeof(struct tegra_cec), GFP_KERNEL); @@ -400,7 +394,7 @@ static int tegra_cec_probe(struct platform_device *pdev) goto clk_error; } - cec->notifier = cec_notifier_get(&hdmi_dev->dev); + cec->notifier = cec_notifier_get(hdmi_dev); if (!cec->notifier) { ret = -ENOMEM; goto clk_error; From patchwork Mon Apr 8 11:04:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10889295 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 04EB8922 for ; Mon, 8 Apr 2019 11:04:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1A25286B5 for ; Mon, 8 Apr 2019 11:04:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFA87286E0; Mon, 8 Apr 2019 11:04:08 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87AA62870B for ; Mon, 8 Apr 2019 11:04:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726515AbfDHLEH (ORCPT ); Mon, 8 Apr 2019 07:04:07 -0400 Received: from lb1-smtp-cloud7.xs4all.net ([194.109.24.24]:50129 "EHLO lb1-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726482AbfDHLEF (ORCPT ); Mon, 8 Apr 2019 07:04:05 -0400 Received: from marune.fritz.box ([IPv6:2001:983:e9a7:1:1170:5c87:411e:5806]) by smtp-cloud7.xs4all.net with ESMTPA id DS4HhTHSRNG8zDS4KhlZPC; Mon, 08 Apr 2019 13:04:04 +0200 From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Neil Armstrong , Sylwester Nawrocki , Benjamin Gaignard , Thierry Reding , Ettore Chimenti , Wen Yang , Hans Verkuil Subject: [PATCH 6/7] seco-cec: decrement HDMI device refcount Date: Mon, 8 Apr 2019 13:04:00 +0200 Message-Id: <20190408110401.3345-7-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190408110401.3345-1-hverkuil-cisco@xs4all.nl> References: <20190408110401.3345-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfLfSxf2AE183XfVVV6a2UI5fWTLb1QG/s1qtjC0Ua/wMBndy1sPfxlIxGHM5STR4zSj/Lt5IzFLx7G9yPKYmaE3SZASt5x53vt9DqIfMFzPU3m8fJszo 4qxh7gPZbg/ZDTbLREIF8C+D8bFg9S5ztYjRkWUxA/SavgSI3C+rNp9LiBAulbvhqISTZDUEkPPOO8fYoRqZzbNQ5ax9pp2r1EucYz6CbIg/HSxGdlRYPLtY xWlbj0LB/hTrBztSuNvstStN6r2ZfRjDXV90Aj0qw9Fh9oN0Mr4yiHVNPqRRX/UG71uTIupcL2UNmaJO8UaHktnNT1DcEqCfTAkkdC4aefTkoU699APhMJo5 48lfdn9jSMIWyRJIaum867Z7+iJT/LYABKKA7i6LZat9Ez+cOwtTnVQjyPo31styIjtDraTqBJI0Xj7eTG4zd/BhsMPzcLNu+ohABQ+9fxeLRWEO+EodVr1x y6EbhNTZ5RasFnnc2TzEcllOgCThtfLJtHRiNQ== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The SECO CEC driver never decremented the HDMI device refcount. CEC drivers only need the HDMI device pointer as a key in the notifier list, it never accesses the device, so there is no need to keep a reference. Signed-off-by: Hans Verkuil Acked-by: Ettore Chimenti --- drivers/media/platform/seco-cec/seco-cec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/platform/seco-cec/seco-cec.c b/drivers/media/platform/seco-cec/seco-cec.c index a425a10540c1..e5080d6f5b2d 100644 --- a/drivers/media/platform/seco-cec/seco-cec.c +++ b/drivers/media/platform/seco-cec/seco-cec.c @@ -536,6 +536,7 @@ static int secocec_cec_get_notifier(struct cec_notifier **notify) return -EPROBE_DEFER; *notify = cec_notifier_get_conn(d, m->conn); + put_device(d); return 0; } From patchwork Mon Apr 8 11:04:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10889299 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D70F922 for ; Mon, 8 Apr 2019 11:04:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 603E9286C2 for ; Mon, 8 Apr 2019 11:04:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E54A28696; Mon, 8 Apr 2019 11:04:10 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 135B22869B for ; Mon, 8 Apr 2019 11:04:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726511AbfDHLEH (ORCPT ); Mon, 8 Apr 2019 07:04:07 -0400 Received: from lb1-smtp-cloud7.xs4all.net ([194.109.24.24]:44566 "EHLO lb1-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726489AbfDHLEG (ORCPT ); Mon, 8 Apr 2019 07:04:06 -0400 Received: from marune.fritz.box ([IPv6:2001:983:e9a7:1:1170:5c87:411e:5806]) by smtp-cloud7.xs4all.net with ESMTPA id DS4HhTHSRNG8zDS4KhlZPP; Mon, 08 Apr 2019 13:04:04 +0200 From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Neil Armstrong , Sylwester Nawrocki , Benjamin Gaignard , Thierry Reding , Ettore Chimenti , Wen Yang , Hans Verkuil Subject: [PATCH 7/7] cros-ec-cec: decrement HDMI device refcount Date: Mon, 8 Apr 2019 13:04:01 +0200 Message-Id: <20190408110401.3345-8-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190408110401.3345-1-hverkuil-cisco@xs4all.nl> References: <20190408110401.3345-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfLfSxf2AE183XfVVV6a2UI5fWTLb1QG/s1qtjC0Ua/wMBndy1sPfxlIxGHM5STR4zSj/Lt5IzFLx7G9yPKYmaE3SZASt5x53vt9DqIfMFzPU3m8fJszo 4qxh7gPZbg/ZDTbLREIF8C+D8bFg9S5ztYjRkWUxA/SavgSI3C+rNp9LiBAulbvhqISTZDUEkPPOO8fYoRqZzbNQ5ax9pp2r1EucYz6CbIg/HSxGdlRYPLtY xWlbj0LB/hTrBztSuNvstStN6r2ZfRjDXV90Aj0qw9Fh9oN0Mr4yiHVNPqRRX/UG71uTIupcL2UNmaJO8UaHktnNT1DcEqCfTAkkdC4aefTkoU699APhMJo5 48lfdn9jSMIWyRJIaum867Z7+iJT/LYABKKA7i6LZat9Ez+cOwtTnVQjyPo31styIjtDraTqBJI0Xj7eTG4zd/BhsMPzcLNu+ohABQ+9fxeLRWEO+EodVr1x y6EbhNTZ5RasFnnc2TzEcllOgCThtfLJtHRiNQ== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The CrosEC CEC driver never decremented the HDMI device refcount. CEC drivers only need the HDMI device pointer as a key in the notifier list, it never accesses the device, so there is no need to keep a reference. Signed-off-by: Hans Verkuil --- drivers/media/platform/cros-ec-cec/cros-ec-cec.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/platform/cros-ec-cec/cros-ec-cec.c b/drivers/media/platform/cros-ec-cec/cros-ec-cec.c index 7bc4d8a9af28..068df9888dbf 100644 --- a/drivers/media/platform/cros-ec-cec/cros-ec-cec.c +++ b/drivers/media/platform/cros-ec-cec/cros-ec-cec.c @@ -236,6 +236,7 @@ static int cros_ec_cec_get_notifier(struct device *dev, return -EPROBE_DEFER; *notify = cec_notifier_get_conn(d, m->conn); + put_device(d); return 0; } }