From patchwork Wed Jan 20 18:48:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= X-Patchwork-Id: 12033419 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE2C6C433E0 for ; Wed, 20 Jan 2021 18:49:52 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 42F2D206FA for ; Wed, 20 Jan 2021 18:49:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 42F2D206FA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=mnkptkUFbB02xy/TkxcsauKFQt17yS8Zx8dhhY8II50=; b=TAJ/oiTcU++s4yjsk49rEQqbrp F+bFxuGX6Zlinq+Ca1Vc62CtW77U+IhPyMG3kmyuAgSdsHGF34B8qg4X0THWOepfea1cRaGKXpP9s ARBQNtncptJqAt+R3agC2H++Q+/0B+A5HC1aSRLVSOfAgR9l4UFKF7qmFopI6hr1sYc2j8oSlN693 s2uEHbaryJBsF92b46CNjHSydwFnKlCc008ioqu8286Zh0DulSDbDHpazKRV226CuD3rrMQ8H2kpg SeZT65g2vtztCB0mNEifdobQOx7/6dpikNZj4pt4JlfDA5u4K5KXbdfYBnik/QrpO3XDCL9ItoB/K xtx1Zt6Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2IWg-0003fu-Ob; Wed, 20 Jan 2021 18:48:18 +0000 Received: from mail-wm1-f51.google.com ([209.85.128.51]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l2IWd-0003ez-F4; Wed, 20 Jan 2021 18:48:16 +0000 Received: by mail-wm1-f51.google.com with SMTP id c127so3737605wmf.5; Wed, 20 Jan 2021 10:48:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uxPmbiajECo9YExCxiewn6BUGuPfDNtaPp5Y2cOf+vw=; b=nKMLx/+uz3ne91/cR1ztZADBl4IL3vr1dM1R2KyJ5vZq6sftlBrtCQYehmbgdl7Hwh Nx9z6jqTFUjyONjHyuVpqmvI/NxasjFzwSwP1dohl48hrSKQK50QsqdQwdsKk2KIU8m4 RKP66vCNiZhu3llq0PRZf3PZBXtAqTA+FOHnAUtRRFBByP0j7bhFgp/KkkrDVzNrWTSt y+XZwVEkpw/Df50EagfsQ6157FKdnkUdHBR/ZQ3Qh0eN65olsm1xexdNAon3F2kLQklS ARpe9ZoHNNjyraC5l/bWY8Romv7lPOVfURPi0rMciu27gq6GHBCDnwmLRKs34sxFhq4x AEeg== X-Gm-Message-State: AOAM531LcpEbV2ku3RwfLyfcGvfC8fIeD8J8wuOgoheJ6v3kPVmVBUfW BIKojQlX0BjeDFuXSisYOy0= X-Google-Smtp-Source: ABdhPJwtn2xpshugzYAvflARryBYa82pNPYQWztaOHR67Bzcg8Dpc4zdRyBK9jvQ3DfPLD+GcFYXig== X-Received: by 2002:a1c:c90c:: with SMTP id f12mr5726969wmb.98.1611168492620; Wed, 20 Jan 2021 10:48:12 -0800 (PST) Received: from workstation.lan ([95.155.85.46]) by smtp.gmail.com with ESMTPSA id v11sm5466474wrt.25.2021.01.20.10.48.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jan 2021 10:48:11 -0800 (PST) From: =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= To: Matthias Brugger Subject: [PATCH] PCI: mediatek: Add missing of_node_put() to fix reference leak Date: Wed, 20 Jan 2021 18:48:10 +0000 Message-Id: <20210120184810.3068794-1-kw@linux.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210120_134815_513824_895415CA X-CRM114-Status: GOOD ( 13.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lorenzo Pieralisi , linux-pci@vger.kernel.org, Ryder Lee , linux-mediatek@lists.infradead.org, Bjorn Helgaas , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. Signed-off-by: Krzysztof WilczyƄski --- 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)