Skip to content

Commit c4a413e

Browse files
YAN SHIbroonie
authored andcommitted
regulator: stm32-pwr: fix of_iomap leak
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 devm_platform_ioremap_resource(). devm_platform_ioremap_resource() 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 as the return value of devm_platform_ioremap_resource() can either be a pointer to the remapped memory or an ERR_PTR() encoded error code if the operation fails. Fixes: dc62f95 ("regulator: stm32-pwr: Fix return value check in stm32_pwr_regulator_probe()") Signed-off-by: YAN SHI <[email protected]> Reported-by: kernel test robot <[email protected]> Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Reviewed-by: Dongliang Mu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 53e59b5 commit c4a413e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

drivers/regulator/stm32-pwr.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,16 @@ static const struct regulator_desc stm32_pwr_desc[] = {
129129

130130
static int stm32_pwr_regulator_probe(struct platform_device *pdev)
131131
{
132-
struct device_node *np = pdev->dev.of_node;
133132
struct stm32_pwr_reg *priv;
134133
void __iomem *base;
135134
struct regulator_dev *rdev;
136135
struct regulator_config config = { };
137136
int i, ret = 0;
138137

139-
base = of_iomap(np, 0);
140-
if (!base) {
138+
base = devm_platform_ioremap_resource(pdev, 0);
139+
if (IS_ERR(base)) {
141140
dev_err(&pdev->dev, "Unable to map IO memory\n");
142-
return -ENOMEM;
141+
return PTR_ERR(base);
143142
}
144143

145144
config.dev = &pdev->dev;

0 commit comments

Comments
 (0)