Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3517859pxf; Mon, 15 Mar 2021 11:18:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxglbsYt4NvIFav62qx8tgi/awWGX1My/4Af9in3PjYNaAM25laVh+3MITKxvBtootiilqj X-Received: by 2002:a17:906:405b:: with SMTP id y27mr25732592ejj.332.1615832333385; Mon, 15 Mar 2021 11:18:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832333; cv=none; d=google.com; s=arc-20160816; b=FLA0NWbG6RqUIY+vf8L4lYL2twk2UqPOBoANIxveVORjs0RVoKgxollddjzvZV0StI ofKekg6ws4q80PxbH91WDeGVqSYTBG0EMNozbHPwwxYSs9RHA5NBAR4gR1CwP+JJ6q0b 9GMW5uy9RgvwxejEYLOQKYOg+dgN8y8qWrovtwpck5hqMmcadMEEJ16dkFmLuJ1zjn3g HqagaFTP+rvzmcFOHTNGYBtS9mwnjI7lVbWLAdj3yPnPkxJgs9BVkPtrj78dbiZlt1Cs KFP7nkL3UV4g2FdZjxsMJR08Lcm62AUv2DWqaPPW+OLH+QY37T4+HvNghdLfz0NpEARS Jc3w== 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=w4dznZKXNSck++ERZZv5iB+Mm6uC7LCSppDEgvcOEko=; b=tW+QoepC+jI2s8AZfXf4iSCWBGmcCps/yac6F9vvkxWLTo0zfh+MyZlEE5r207vwSE MFD8f1vCYa6rr2eK55UYb6MIFWVx39rVtbcS65N5m4GQeAOVVubQu9FivzcQ9Yvh3MiB FGDUJQbI0cnB5tGQfV1/fWHBnhcz28VCQ+gMYg7p+KxLSMqiCaBMwzYiIAjWCvn9akaE 5zJH+IhajHyk41v9qCjfr6WHk+f1X2zSCcbAicINtLKEWxpKuRVsyj7nASbSXDVzXh7v 6mgdZJvgOiiqo0GuopjfxuswltIZrVYUwHGYjdEyP7msyU7KkNEMEM86fY2xuMHr1Owj M+qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qNHAsHSi; 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 ho7si10969910ejc.686.2021.03.15.11.18.31; Mon, 15 Mar 2021 11:18:53 -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=qNHAsHSi; 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 S236913AbhCOOQa (ORCPT + 99 others); Mon, 15 Mar 2021 10:16:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:35610 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229828AbhCON7U (ORCPT ); Mon, 15 Mar 2021 09:59:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 228BE64F43; Mon, 15 Mar 2021 13:58:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816741; bh=50Xuy5NzZD7iZ5ddL4wtXPxtTC/vFPC95KHHeKUGfEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qNHAsHSiG9pnlO6AYUyMLfaNtru+ANdMerV4e86uzPsmx7gZm7F2bxXzmG9Gelcxf mhaoS1rIMlPKKNALh9HRr0G32IA6GPjF2YpNKDyPofkJjAa1bV03JTFpitBCopj4Fy mUVML5BcFXxS72fwbNhseRPwt/1myFAVknBuvsg8= 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.4 079/168] PCI: mediatek: Add missing of_node_put() to fix reference leak Date: Mon, 15 Mar 2021 14:55:11 +0100 Message-Id: <20210315135552.989774904@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135550.333963635@linuxfoundation.org> References: <20210315135550.333963635@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 626a7c352dfd..728a59655825 100644 --- a/drivers/pci/controller/pcie-mediatek.c +++ b/drivers/pci/controller/pcie-mediatek.c @@ -1063,14 +1063,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); @@ -1086,6 +1086,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