Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp4527621imj; Tue, 12 Feb 2019 18:35:34 -0800 (PST) X-Google-Smtp-Source: AHgI3IZk8SCoiwCjs0Fm7O0iyOANkyhl/RQjAonRn9NUtj2L1bo4JstORRLe5iKaTzRVr7Pb+xId X-Received: by 2002:a62:1346:: with SMTP id b67mr1503661pfj.195.1550025333955; Tue, 12 Feb 2019 18:35:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550025333; cv=none; d=google.com; s=arc-20160816; b=NFCKJe3mHJXxXGK66GkYr7movd8plPmmk4RP4iPQw9raTo/XQXbcou92LPKnDNBowa 8BQt/TrSVpsdf8nHZrFHVZgR5a4O6HELfOZlpYPvssHYk5YLidXkuI8ueuLmWmINQLZy EN6zfzj/ShmdpR9OrOC8VhcdDTd6mnxKErGTBymTycSuk3DPujSdQO0MM5NMlaVzlpij ltUyOwSoX84Fifie/ct6Xyp4kXboxY2JhDENDZmPIaLP9aYHbaA0Zx703r8BbkWaHb1A QrqCA8AHjJupbRbbllXv3fomMAh6P5WMm2wBhtjrKHCIQcdQpFh+RcgoHuYIXdsiwkVV ZFFw== 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=TedTexY5fKOuKq2da06mTbcSQuqwROmfv4D1z9knfmo=; b=trzKouwwRM0BfnzUxCAhdwLGqy4fQHFRs2+XuWxalOVoOPN6mohfYH0+XkqP1kBs3G Bm0bkCZFYHWhrSQ2uzR59JWDYCYYFNs0XsGPvL2gb3QBeWeetpIpSODd23YLDEdUqzQ0 1E8+c3Z/vxw7XBQacbej0sMwciNLnNPsJdwEKSz0k195xPLvCYxW6ByUnkYMFkv28NMC 5jLYRa6KlscSIaDW+DCu0OVP3Yra8J0Je1iCYMxThUMxt9qfv8q7U7M0r6bFo8PiSfzp vaeFJOBj+BOPRPlVsICR3/bfJcoRaxvEsY8JkGKZPgISVGc0uyspxSzWKVRSDRudShue snug== 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 h7si4278806pgi.417.2019.02.12.18.35.17; Tue, 12 Feb 2019 18:35:33 -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 S1729523AbfBLXpo (ORCPT + 99 others); Tue, 12 Feb 2019 18:45:44 -0500 Received: from out1.zte.com.cn ([202.103.147.172]:43784 "EHLO mxct.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727039AbfBLXpo (ORCPT ); Tue, 12 Feb 2019 18:45:44 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 8E590E239FC4DE14821F; Wed, 13 Feb 2019 07:45:41 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id x1CNjZ1E001782; Wed, 13 Feb 2019 07:45:36 +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 2019021307455443-25782367 ; Wed, 13 Feb 2019 07:45:54 +0800 From: Wen Yang To: narmstrong@baylibre.com Cc: mchehab@kernel.org, khilman@baylibre.com, linux-media@lists.freedesktop.org, linux-amlogic@lists.infradead.org, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.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 1/4] media: platform: meson-ao-cec: fix possible object reference leak Date: Wed, 13 Feb 2019 07:44:35 +0800 Message-Id: <1550015075-41548-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:45:54, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2019-02-13 07:45:28, Serialize complete at 2019-02-13 07:45:28 X-MAIL: mse01.zte.com.cn x1CNjZ1E001782 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: 7ec2c0f72cb1 ("media: platform: Add Amlogic Meson AO CEC Controller driver") Suggested-by: Hans Verkuil (hansverk) Signed-off-by: Wen Yang Cc: Hans Verkuil (hansverk) Cc: Neil Armstrong Cc: Mauro Carvalho Chehab Cc: Kevin Hilman Cc: Wen Yang Cc: linux-media@lists.freedesktop.org Cc: linux-amlogic@lists.infradead.org Cc: linux-media@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.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/meson/ao-cec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/platform/meson/ao-cec.c b/drivers/media/platform/meson/ao-cec.c index cd4be38..f757ece 100644 --- a/drivers/media/platform/meson/ao-cec.c +++ b/drivers/media/platform/meson/ao-cec.c @@ -613,9 +613,11 @@ static int meson_ao_cec_probe(struct platform_device *pdev) } hdmi_dev = of_find_device_by_node(np); + of_node_put(np); if (hdmi_dev == NULL) return -EPROBE_DEFER; + put_device(&hdmi_dev->dev); ao_cec = devm_kzalloc(&pdev->dev, sizeof(*ao_cec), GFP_KERNEL); if (!ao_cec) return -ENOMEM; -- 2.9.5