From nobody Wed Feb 11 16:52:59 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50823C7619A for ; Wed, 12 Apr 2023 03:37:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229580AbjDLDhH (ORCPT ); Tue, 11 Apr 2023 23:37:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229481AbjDLDhF (ORCPT ); Tue, 11 Apr 2023 23:37:05 -0400 Received: from hust.edu.cn (unknown [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C89AE30C8 for ; Tue, 11 Apr 2023 20:37:04 -0700 (PDT) Received: from foreverowl-virtual-machine.localdomain ([10.12.170.216]) (user=m202071378@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 33C3ZdbP003695-33C3ZdbS003695 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 12 Apr 2023 11:35:39 +0800 From: YAN SHI To: Liam Girdwood , Mark Brown , Maxime Coquelin , Alexandre Torgue , Wei Yongjun Cc: YAN SHI , kernel test robot , Dongliang Mu , linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] Regulator: stm32-pwr: fix of_iomap leak Date: Wed, 12 Apr 2023 11:35:29 +0800 Message-Id: <20230412033529.18890-1-m202071378@hust.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FEAS-AUTH-USER: m202071378@hust.edu.cn Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Smatch reports: drivers/regulator/stm32-pwr.c:166 stm32_pwr_regulator_probe() warn: 'base' from of_iomap() not released on lines: 151,166. In stm32_pwr_regulator_probe(), base is not released when devm_kzalloc() fails to allocate memory or devm_regulator_register() fails to register a new regulator device, which may cause a leak. To fix this issue, replace of_iomap() with=20 devm_platform_ioremap_resource(). devm_platform_ioremap_resource()=20 is a specialized function for platform devices. It allows 'base' to be automatically released whether the probe function succeeds or fails. Besides, use IS_ERR(base) instead of !base=20 as the return value of devm_platform_ioremap_resource()=20 can either be a pointer to the remapped memory or=20 an ERR_PTR() encoded error code if the operation fails. Fixes: dc62f951a6a8 ("regulator: stm32-pwr: Fix return value check in stm32= _pwr_regulator_probe()") Signed-off-by: YAN SHI Reported-by: kernel test robot Link: https://lore.kernel.org/oe-kbuild-all/202304111750.o2643eJN-lkp@intel= .com/ Reviewed-by: Dongliang Mu --- The issue is found by static analysis, and the patch remains untest. --- v1->v2: Remove unused variable 'np'. drivers/regulator/stm32-pwr.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/regulator/stm32-pwr.c b/drivers/regulator/stm32-pwr.c index 2a42acb7c24e..e5dd4db6403b 100644 --- a/drivers/regulator/stm32-pwr.c +++ b/drivers/regulator/stm32-pwr.c @@ -129,17 +129,16 @@ static const struct regulator_desc stm32_pwr_desc[] = =3D { =20 static int stm32_pwr_regulator_probe(struct platform_device *pdev) { - struct device_node *np =3D pdev->dev.of_node; struct stm32_pwr_reg *priv; void __iomem *base; struct regulator_dev *rdev; struct regulator_config config =3D { }; int i, ret =3D 0; =20 - base =3D of_iomap(np, 0); - if (!base) { + base =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(base)) { dev_err(&pdev->dev, "Unable to map IO memory\n"); - return -ENOMEM; + return PTR_ERR(base); } =20 config.dev =3D &pdev->dev; --=20 2.34.1