Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3526018pxf; Mon, 15 Mar 2021 11:30:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzegtQXpURI2TVhNJZvDnoZi/ceVCYL0cj4S2/WzIOHshUGxl8B1sxd4OsM9BifB/tUaRge X-Received: by 2002:a17:906:5d06:: with SMTP id g6mr25212654ejt.216.1615833048140; Mon, 15 Mar 2021 11:30:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833048; cv=none; d=google.com; s=arc-20160816; b=cSHqaAiDKuiQkVdYIa1/PjyiXM5FowLsGVnXj2UqtgtfVn+7LmcC0gtwsOURGpvp1b BvRqsPYtphO+aQUR4Htsp3n4aDXaQuVluXfr6EoMDTAQxShJtmEj9EsXg5ihAn/EX0iR UptANhXdeGD8Ds1LKocPMJQPm/5lPhx3bHqHTLiWX8XyVKt4JKyy4TxVezlP5+PnnvT9 KAAtsa+/6bDBBj9izlIVd+77eWAzZxItywRIDuNTRQ+GM8SFN/WD1pXGnptOnmkou3OL uS2z47jSDC6S/fP7uGnC8aAGW3OUFmp7HXITbCE1j7edMxaMsFJCKfKFNYw0zPLvAEAc +SJg== 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=r/18oCCppihpcJfwEi2f0+7lQpVMympKshahI/0HArA=; b=bqgBTwz+ODAZV1chAou8vMaZ73ToGRc+vm+thtxixjdj0yCmxUYM7ADeWMpuv+nRal JMC2/ZeBejC6KfMffrKW7z56/GMcZ23uhaYtnbB+ufMoSEmfAtyIPBvmzuOqIiV0cFGn /koLldO3kMGxIhW/OufwMTMRBV6J/VM/vMUX/ydLFAQ+3MMYLYAHtQG4d7JM2dHteQS6 +ie3SzB6PxGxtB7Z2aonlZXcZBErHK+PlODevHR3J7NSsJf9G63/oOQzqct8x2Rjb1Zl bRyJdpVuR0dxBpe+Bkm/0sNHXL2h/CO//wlHdrlXwObz6M3ElusCHrCF3yao0dH5XshC o/Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=k+EuYcaD; 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 qw16si10626682ejb.673.2021.03.15.11.30.25; Mon, 15 Mar 2021 11:30:48 -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=k+EuYcaD; 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 S239979AbhCOOdV (ORCPT + 99 others); Mon, 15 Mar 2021 10:33:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:36788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233250AbhCOOBN (ORCPT ); Mon, 15 Mar 2021 10:01:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E981664FCE; Mon, 15 Mar 2021 14:00:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816853; bh=crG9gWp9IMJ+prHgTgVtp2fwvPLbxGDd4h4QNbdJBMY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k+EuYcaDxuNZagl/I4V4oQlMm32nMZVnog0HTbK6c4UUxNRIkS4ZUx3m7GZ5kMZ69 3suphzIhtfaXgQ7ncekpq1FSwabLXJ/kAXUpSkFohB+aoeC51Myzv6AESURGRgeQps e/5dsSM527cdzEbLTZoQ5vp3epOuMqlBHbp1CfLM= 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 5.10 152/290] PCI: mediatek: Add missing of_node_put() to fix reference leak Date: Mon, 15 Mar 2021 14:54:05 +0100 Message-Id: <20210315135547.056737606@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@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 cf4c18f0c25a..23548b517e4b 100644 --- a/drivers/pci/controller/pcie-mediatek.c +++ b/drivers/pci/controller/pcie-mediatek.c @@ -1035,14 +1035,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); @@ -1058,6 +1058,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_probe(struct platform_device *pdev) -- 2.30.1