From patchwork Fri Jun 3 13:02:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaoqian Lin X-Patchwork-Id: 12869050 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E7DDC43334 for ; Fri, 3 Jun 2022 13:04:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=aPQqTECQETFkWRZo5rU89VTTzJeoPc3RQOib3lZf5Hg=; b=miZ+D7qXxaub2y 4w8atk89wjg2kdsIgtMc+G3wIU9tjsPDT/W0jNj8nTfxzv+s758YMLxi/smE+H2F69f80dKYvjOdb icsRgonG4RrdoRY//ZCKLdC0s9g3BsD3NKXHbigbWaPgFVmuDEpi73U+YNZELolGl4y93//htfYRU bKVIX5S9BNwQvppk8BWOAuPFonbddmTAuhdv7wVH+pNhNW9dkQbMBcU/7ElVKsmaVe4i/Z4+ShDbY T5R5WUtQzoMxobuFo2N+bFivPXCq8uvEHDIjSbw2nn+1risEMC7EtTtVw8JFxSpZX7f6gC+8YveNk ariRxUIa0exPxszUkPYg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nx6xD-007VMn-L8; Fri, 03 Jun 2022 13:03:03 +0000 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nx6x9-007VLp-KJ for linux-arm-kernel@lists.infradead.org; Fri, 03 Jun 2022 13:03:01 +0000 Received: by mail-pg1-x52f.google.com with SMTP id c14so7138205pgu.13 for ; Fri, 03 Jun 2022 06:02:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=tZJCVfkDNbBay4i/IKmSG4KPm/5ghCVouz6lrlhw4Pw=; b=MaWVICMaC/zGZ8g1mJjK/S0Pes5zL9LKaGTSWgBPnNdKuaNH7uyWn8YMDKDuM51oKq mKOClKlUG5Zn4q8hPp5oZztaHoPCO8DNOkro105LglfXuiConNRJDSaa/EEq+De/gm2I GyK69usJrjyrhKNjCkNOoyLFDaMxMLY/+XkbIMmtaUUbpxugSod15WR/6j3Fm7VKLnd2 qOEFuUkp0Hsib9+2bvM5pTg0vwy0Azg870k1/3irrGCHJO+041R1dgh1w2x2X420Br9l def1NPqAr9NmK72VAF3geosOcjft4ULE8LcT6uFbeWQLg5yMvv1gSt0nAlizzgqri7dY oHEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=tZJCVfkDNbBay4i/IKmSG4KPm/5ghCVouz6lrlhw4Pw=; b=8NjHDIbzPFjjDd42frj8S7jA4Lx3wfWkOGPv+W/L8tXiBvppBY6OoRj4i0M5CN1Gxt sGy8PqvCJ4lF8BTgZRYGB2IJCljXd3oBA9wmre7EecGCcxGJaGqiifhxfssVEP7sXW1g //VwconaLzFg8XeHw3rvQ37k9eQwKvwg4hXBqhVXJ5EUXWvGiySS0jXAy/0yC065pw1w GX1FKUSs4ZDsQrhWQb4WPGENUHiYtTYupFIPaQPoL/Wbkkb/3eUBdGR/9UDyYtczPui7 DD3bTxJdrigwrWmKBNQ/uZX0783njKRVBgGEpWG8ngFAgQrTT3p5UAE5hbZguroJSTD0 I7Mw== X-Gm-Message-State: AOAM530dQKzdWRi7R7G316NYzevigmI+cJexH/NAgQPQ8ej7e+YiYrjq GtiAGUgEArquna9s1GMh9tk= X-Google-Smtp-Source: ABdhPJzf0mIOPrgihIY3TMa9YP5IUgr7IfJUpVPWFFzNJXZoYQ/Ue6+qTI2DgBc4hrEuoRDWZdcrMA== X-Received: by 2002:a63:ff5a:0:b0:3fc:c8d7:f3e0 with SMTP id s26-20020a63ff5a000000b003fcc8d7f3e0mr8934157pgk.77.1654261376751; Fri, 03 Jun 2022 06:02:56 -0700 (PDT) Received: from localhost.localdomain ([202.120.234.246]) by smtp.googlemail.com with ESMTPSA id ge20-20020a17090b0e1400b001df4c5cab51sm5155472pjb.15.2022.06.03.06.02.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 06:02:56 -0700 (PDT) From: Miaoqian Lin To: Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Miaoqian Lin , Lucas Stach , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] soc: imx: gpc: Fix refcount leak in imx_gpc_probe Date: Fri, 3 Jun 2022 17:02:43 +0400 Message-Id: <20220603130245.36151-1-linmq006@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220603_060259_706400_3AD7C695 X-CRM114-Status: GOOD ( 14.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org of_get_child_by_name() returns a node pointer with refcount incremented, we should use of_node_put() on it when not need anymore. Add missing of_node_put() to avoid refcount leak. Fixes: 721cabf6c660 ("soc: imx: move PGC handling to a new GPC driver") Signed-off-by: Miaoqian Lin --- changes in v2: - update Fixes tag. v1 Link: https://lore.kernel.org/r/20220602132355.29847-1-linmq006@gmail.com --- drivers/soc/imx/gpc.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/soc/imx/gpc.c b/drivers/soc/imx/gpc.c index 90a8b2c0676f..5df47e6d7585 100644 --- a/drivers/soc/imx/gpc.c +++ b/drivers/soc/imx/gpc.c @@ -419,8 +419,10 @@ static int imx_gpc_probe(struct platform_device *pdev) return 0; base = devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(base)) - return PTR_ERR(base); + if (IS_ERR(base)) { + ret = PTR_ERR(base); + goto put_pgc_node; + } regmap = devm_regmap_init_mmio_clk(&pdev->dev, NULL, base, &imx_gpc_regmap_config); @@ -428,7 +430,7 @@ static int imx_gpc_probe(struct platform_device *pdev) ret = PTR_ERR(regmap); dev_err(&pdev->dev, "failed to init regmap: %d\n", ret); - return ret; + goto put_pgc_node; } /* @@ -464,15 +466,18 @@ static int imx_gpc_probe(struct platform_device *pdev) int domain_index; ipg_clk = devm_clk_get(&pdev->dev, "ipg"); - if (IS_ERR(ipg_clk)) - return PTR_ERR(ipg_clk); + if (IS_ERR(ipg_clk)) { + ret = PTR_ERR(ipg_clk); + goto put_pgc_node; + } + ipg_rate_mhz = clk_get_rate(ipg_clk) / 1000000; for_each_child_of_node(pgc_node, np) { ret = of_property_read_u32(np, "reg", &domain_index); if (ret) { of_node_put(np); - return ret; + goto put_pgc_node; } if (domain_index >= of_id_data->num_domains) continue; @@ -481,7 +486,8 @@ static int imx_gpc_probe(struct platform_device *pdev) domain_index); if (!pd_pdev) { of_node_put(np); - return -ENOMEM; + ret = -ENOMEM; + goto put_pgc_node; } ret = platform_device_add_data(pd_pdev, @@ -490,7 +496,7 @@ static int imx_gpc_probe(struct platform_device *pdev) if (ret) { platform_device_put(pd_pdev); of_node_put(np); - return ret; + goto put_pgc_node; } domain = pd_pdev->dev.platform_data; domain->regmap = regmap; @@ -503,12 +509,17 @@ static int imx_gpc_probe(struct platform_device *pdev) if (ret) { platform_device_put(pd_pdev); of_node_put(np); - return ret; + goto put_pgc_node; } } } + of_node_put(pgc_node); return 0; + +put_pgc_node: + of_node_put(pgc_node); + return ret; } static int imx_gpc_remove(struct platform_device *pdev)