Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp4528638imj; Tue, 12 Feb 2019 18:36:53 -0800 (PST) X-Google-Smtp-Source: AHgI3IY2hEoNVh6dv+z4gGwkB84o1q7v2B2D88WI0D/jZKHzfr/hQzjNozWCVJ3yCHuz4OW1bc0H X-Received: by 2002:a63:d70a:: with SMTP id d10mr6628973pgg.286.1550025413112; Tue, 12 Feb 2019 18:36:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550025413; cv=none; d=google.com; s=arc-20160816; b=H8RFYB8yVIFiGTd9JkfxI9vDdYJzmcbQMitc1jXdf7NOX8JdU8lFn0MC5s18vgGOm1 TrWzHLYU2PCgIHJq4n/GFqalxx5z5oICVpC5epDbybAV+5WSVUTeUhQIAO67PPffOrTu 4pk+Ou7tob8FNu5YiPgjzSz4/jQsPZcLQBhLlpd83gu4Yx7k9+Yx8XT35eGPe0iBiFx+ EPj5fVzq593SCi1DjlL69zuRubDYct4cywPlfIzM7WeHPMtpxl7LWqSEGwbqfFPIR/WW nAidZNq7Uq9Fwz8QYsRd/oNnZVQyUOph1qjohUlOBgL6cFEp3ET4cDVJQjQ4cecWWxpf m7cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=TNPZZQK/RqCAwfYVlRfdR9hDF2jWezeeg2mu5eq+D3Y=; b=BQy0qrd9Bzo4IKt7E1vTRf+vbA2Ana7ZmAsbFp7W8/E8QCg1XrXmKBZARLG+elEM4T Y84RC/M73bKpSI7G+d297pcPrhYIsgOZMxm6TPl3nC9WlRAVubnXllZK9NWQLrl3Hq09 V4Gn6ReVKKw8TNdw9Do6+/QQE0JNLjA8Qb9a3MyRpIKfpkVNun+fczOAcSu6eqnGLCn3 pKLsB5pndcO/zL1PFOkZqTGIGg4ytJ3xPrUKXvi475iPtAaDeprbZXWOt6wEtianxGMT we/+E23NVes7LHSmWnxR290DNPG2LUnm6HuY6iEOfo8FQqhnQaa0xQna+3Nf14FwCsoX CAaw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d65si14783101pfc.201.2019.02.12.18.36.37; Tue, 12 Feb 2019 18:36:53 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731864AbfBLXqe (ORCPT + 99 others); Tue, 12 Feb 2019 18:46:34 -0500 Received: from mxhk.zte.com.cn ([63.217.80.70]:60686 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731439AbfBLXqe (ORCPT ); Tue, 12 Feb 2019 18:46:34 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 8E7E9A730E51313FCED6; Wed, 13 Feb 2019 07:46:31 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id x1CNkRGn001887; Wed, 13 Feb 2019 07:46:27 +0800 (GMT-8) (envelope-from wen.yang99@zte.com.cn) Received: from fox-host8.localdomain ([10.74.120.8]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2019021307464640-25782376 ; Wed, 13 Feb 2019 07:46:46 +0800 From: Wen Yang To: hans.verkuil@cisco.com Cc: mchehab@kernel.org, thierry.reding@gmail.com, jonathanh@nvidia.com, linux-tegra@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, xue.zhihong@zte.com.cn, wang.yi59@zte.com.cn, Wen Yang , "Hans Verkuil (hansverk)" , Wen Yang Subject: [PATCH v2 2/4] media: tegra-cec: fix possible object reference leak Date: Wed, 13 Feb 2019 07:45:29 +0800 Message-Id: <1550015129-41867-1-git-send-email-wen.yang99@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2019-02-13 07:46:46, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2019-02-13 07:46:20, Serialize complete at 2019-02-13 07:46:20 X-MAIL: mse01.zte.com.cn x1CNkRGn001887 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The call to of_parse_phandle() returns a node pointer with refcount incremented thus it must be explicitly decremented here after the last usage. The of_find_device_by_node() takes a reference to the underlying device structure, we also should release that reference. Hans Verkuil says: The cec driver should never take a reference of the hdmi device. It never accesses the HDMI device, it only needs the HDMI device pointer as a key in the notifier list. The real problem is that several CEC drivers take a reference of the HDMI device and never release it. So those drivers need to be fixed. This patch fixes those two issues. Fixes: 9d2d60687c9a ("media: tegra-cec: add Tegra HDMI CEC driver") Suggested-by: Hans Verkuil (hansverk) Signed-off-by: Wen Yang Cc: Hans Verkuil (hansverk) Cc: Hans Verkuil Cc: Mauro Carvalho Chehab Cc: Thierry Reding Cc: Jonathan Hunter Cc: Wen Yang Cc: linux-tegra@vger.kernel.org Cc: linux-media@vger.kernel.org --- v2->v1: - move of_node_put() to just after the 'hdmi_dev = of_find_device_by_node(np)'. - put_device() can be done before the cec = devm_kzalloc line. drivers/media/platform/tegra-cec/tegra_cec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/platform/tegra-cec/tegra_cec.c b/drivers/media/platform/tegra-cec/tegra_cec.c index aba488c..e99991b 100644 --- a/drivers/media/platform/tegra-cec/tegra_cec.c +++ b/drivers/media/platform/tegra-cec/tegra_cec.c @@ -340,9 +340,11 @@ static int tegra_cec_probe(struct platform_device *pdev) return -ENODEV; } hdmi_dev = of_find_device_by_node(np); + of_node_put(np); if (hdmi_dev == NULL) return -EPROBE_DEFER; + put_device(&hdmi_dev->dev); cec = devm_kzalloc(&pdev->dev, sizeof(struct tegra_cec), GFP_KERNEL); if (!cec) -- 2.9.5