]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
clk: renesas: r9a06g032: Fix memory leak in error path
authorHaotian Zhang <vulab@iscas.ac.cn>
Thu, 30 Oct 2025 06:16:03 +0000 (14:16 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Jan 2026 12:09:29 +0000 (13:09 +0100)
[ Upstream commit f8def051bbcf8677f64701e9699bf6d11e2780cd ]

The current code uses of_iomap() to map registers but never calls
iounmap() on any error path after the mapping. This causes a memory
leak when probe fails after successful ioremap, for example when
of_clk_add_provider() or r9a06g032_add_clk_domain() fails.

Replace of_iomap() with devm_of_iomap() to automatically unmap the
region on probe failure. Update the error check accordingly to use
IS_ERR() and PTR_ERR() since devm_of_iomap() returns ERR_PTR on error.

Fixes: 4c3d88526eba ("clk: renesas: Renesas R9A06G032 clock driver")
Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://patch.msgid.link/20251030061603.1954-1-vulab@iscas.ac.cn
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/clk/renesas/r9a06g032-clocks.c

index 3e43ae8480ddffb8823ecf69e3de93a4af716853..5df686ed21a4ea559483b96dd03c582e32e53f89 100644 (file)
@@ -918,9 +918,10 @@ static int __init r9a06g032_clocks_probe(struct platform_device *pdev)
        if (IS_ERR(mclk))
                return PTR_ERR(mclk);
 
-       clocks->reg = of_iomap(np, 0);
-       if (WARN_ON(!clocks->reg))
-               return -ENOMEM;
+       clocks->reg = devm_of_iomap(dev, np, 0, NULL);
+       if (IS_ERR(clocks->reg))
+               return PTR_ERR(clocks->reg);
+
        for (i = 0; i < ARRAY_SIZE(r9a06g032_clocks); ++i) {
                const struct r9a06g032_clkdesc *d = &r9a06g032_clocks[i];
                const char *parent_name = d->source ?