Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3522757pxf; Mon, 15 Mar 2021 11:26:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXtKl/tdpu2hIllhV0DrQ9fanZGMr4Q7jZ35EHuLdOAI3yJ+gUi6UM6IlYtAmp7JBpTzy+ X-Received: by 2002:a05:6402:220a:: with SMTP id cq10mr31579557edb.345.1615832794856; Mon, 15 Mar 2021 11:26:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832794; cv=none; d=google.com; s=arc-20160816; b=WNZ7MZsoZdiMpImwgJn8sod/Qj2AO/AajUQx3771EPBD9+kfhsePbp5RdEhgDnHLXD o38kHKeAS4LfqJx0KfNAQOenjmozTjXBbO3M/Dqi6D4B+0Smm8dEj5SmXBbL8xkOhevl JduiuK5JCM33bmQll/lwIqkL8Z/7Q3HE31ZALl5Wa0ajDsRZ0enM+Y/jKhhUjAWAz+8U toSbaucNQX1jHNf1hRTUL4bPI/x49uWGhCboacx3tAAmqTk6fl3sR96tqlG+biO2fN/I LGjZX/SaWKWERGqK5vQZ1HQ43OvQPsE3wL4Yx17yy6oIsmxnHJOD0H7U7oho7Rpnt36f 1V6g== 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=zoVSKX7Pnu98GzOCsrKWP9BFkRcixPB6iIsCT8fH+/zG+3xd7Nrp5y8UoET2RTGJ+5 jTfCYcXUVG7lCknNK6i2PBPxhWl8CVGOi3VQEiwEvd0wReyMGzyCXY9Oy/Z1dkt/Bhe2 1JmyNZmneVpkV/2wN14wDKGLUmYIN7FchzLXdu4MG1yLL8SxTb3p4Y9Hwsmcqjj/qI2+ IWPGwdp0RSzuuo3OPoIT9XtzNWRp+z5O89F03kS3IsF9gdmElFUaYUfVbpbTFxI1SNag YQ8Ig/OqnRFs1Ew2MRBKVkh6up84uTeJUaWiSeUGC5nZcsPjqoF7ntZ/ig3NLFrxmLH5 eK7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Wdt3zQpU; 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 bq17si2354414ejb.391.2021.03.15.11.25.58; Mon, 15 Mar 2021 11:26:34 -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=Wdt3zQpU; 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 S239009AbhCOO1e (ORCPT + 99 others); Mon, 15 Mar 2021 10:27:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:37670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233105AbhCOOAk (ORCPT ); Mon, 15 Mar 2021 10:00:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8520864F83; Mon, 15 Mar 2021 14:00:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816826; bh=crG9gWp9IMJ+prHgTgVtp2fwvPLbxGDd4h4QNbdJBMY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wdt3zQpUXfFgDX4v8JzqugoZvn8DnX8KRQlkEqyXyNzc2xlZH41a3V1Ubarelbwd0 NH0UsfkJKg9WfBGmHPWNadGxHqVtxWvKK3DsH3fKLg7lxxhkhv8fb3Fgs+h+4BRN6P UsYtC91spsSzIeiR9cMcdXVFgynnjbrlwd/CUKP8= 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.11 148/306] PCI: mediatek: Add missing of_node_put() to fix reference leak Date: Mon, 15 Mar 2021 14:53:31 +0100 Message-Id: <20210315135512.646600334@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@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