Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3518475pxf; Mon, 15 Mar 2021 11:19:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0pO6ZdY9GEiDbQ72RSvnHMRvDPAyyk3T9prXkfGYZaczwHLDqpm4YNsf6Rs/DLmZgFgqt X-Received: by 2002:a05:6402:34c4:: with SMTP id w4mr32574275edc.367.1615832397290; Mon, 15 Mar 2021 11:19:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832397; cv=none; d=google.com; s=arc-20160816; b=M/8KI4VOwV3fBMu97WQdrwE7j8Gc8715g3GoduVW3wkrsmxp4hjdH4g2Gkvx1/iBOv 1R4coS+xD9FIjCmxfgd8gLMZEdn2x2vTeAEeFQ2dYa+SgKHuu06YxHQ5GnkBzoiBBL7I d7ueTuYyU/AHxQVezSGijofK0gvccd3ppvB2G+84seUfDZlw/d7E6vZh5HspWOrCoN/b CAv28WO0HB+EYEozpfhOw5SshqDwmi2xh55lJOTe+CFDAqCTqLvhjPQ2f9HcNCV4wbWx VjeXqRRFNhuXKaoD2a9VsKynfHNWZ7h1vtD58Ktjv7yWuTJvuUIFdN6gZQMeKz100pa6 3OCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=W5AwgK5UF5nz/65XJsC+6arZdFKm2bmEEnhH1cA7wKI=; b=Vv6+TOD4BqDW9cvzqpserBxQ3YJVUx7SSYN9eb3GdJyThKOZd3Oj7nOh3R3Yz+ZBoB /LnZHRMr8spgakhMufxbx1w1iBYe4uPx/vuIS4St/XUzj20OEqJhms+kTXZB4iV1R8PB 6Nu0h/MZgmR+WuxUGFVNoc1vZLWo1fbdAjnBYCHbLV4WEYsxIFXKjNwbIA7LjoTDG4sH yLbo3yPY558fuo55I6LIaDV+l5buQ0yhKYyp35QSt+N/dqwnKWntPPHzFzxSn4bNp1v9 J38nUY7mW/PZo2PFg0POQNBg3li0BDcofxGJBUfOAZNX7zsV0JCYj8w0gadsCfljfmJ7 AQnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="iIrVDTl/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m19si11186583eds.451.2021.03.15.11.19.34; Mon, 15 Mar 2021 11:19:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="iIrVDTl/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237432AbhCOOSU (ORCPT + 99 others); Mon, 15 Mar 2021 10:18:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:35904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232566AbhCON7k (ORCPT ); Mon, 15 Mar 2021 09:59:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4F00364F72; Mon, 15 Mar 2021 13:59:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816763; bh=Nz2xwJi6XdbnD7TBFUYIxggCsFZU+PO1l6tYi0kS0qA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iIrVDTl/T2ti5/pvylYIgy7ijlGR8ZduvTyMWKHtAj5Z+ud1Vv237FgKLLYd6JU4X L0XrBrddFNMx19K7k85Jl4A/o6UlDFFPgMqY5niJTVwrc32n//EP5WoWDqNpGj1419 i+yUlm+LvQprcXVMfTNJ5FM8J2atlePz/a43akFw= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Lorenzo Pieralisi , Sasha Levin Subject: [PATCH 4.19 052/120] PCI: mediatek: Add missing of_node_put() to fix reference leak Date: Mon, 15 Mar 2021 14:56:43 +0100 Message-Id: <20210315135721.694658178@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135720.002213995@linuxfoundation.org> References: <20210315135720.002213995@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Krzysztof Wilczyński [ Upstream commit 42814c438aac79746d310f413a27d5b0b959c5de ] The for_each_available_child_of_node helper internally makes use of the of_get_next_available_child() which performs an of_node_get() on each iteration when searching for next available child node. Should an available child node be found, then it would return a device node pointer with reference count incremented, thus early return from the middle of the loop requires an explicit of_node_put() to prevent reference count leak. To stop the reference leak, explicitly call of_node_put() before returning after an error occurred. Link: https://lore.kernel.org/r/20210120184810.3068794-1-kw@linux.com Signed-off-by: Krzysztof Wilczyński Signed-off-by: Lorenzo Pieralisi Signed-off-by: Sasha Levin --- drivers/pci/controller/pcie-mediatek.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c index ca06d8bc01e7..066e9e00de11 100644 --- a/drivers/pci/controller/pcie-mediatek.c +++ b/drivers/pci/controller/pcie-mediatek.c @@ -1089,14 +1089,14 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie) err = of_pci_get_devfn(child); if (err < 0) { dev_err(dev, "failed to parse devfn: %d\n", err); - return err; + goto error_put_node; } slot = PCI_SLOT(err); err = mtk_pcie_parse_port(pcie, child, slot); if (err) - return err; + goto error_put_node; } err = mtk_pcie_subsys_powerup(pcie); @@ -1112,6 +1112,9 @@ static int mtk_pcie_setup(struct mtk_pcie *pcie) mtk_pcie_subsys_powerdown(pcie); return 0; +error_put_node: + of_node_put(child); + return err; } static int mtk_pcie_request_resources(struct mtk_pcie *pcie) -- 2.30.1