Re: [PATCH v2] drivers: loongson: fix memory leak in loongson2_guts_probe

From: WANG Xuerui
Date: Sun Mar 05 2023 - 22:04:20 EST


On 2023/3/6 10:53, Dongliang Mu wrote:
drivers/soc/loongson/loongson2_guts.c:150 loongson2_guts_probe()
warn: 'guts->regs' from ioremap() not released on lines: 131,135,139,143.

Fix this by modifying ioremap to devm_ioremap.

Note that, this patch is not tested due to the loongson architecture.

Signed-off-by: Dongliang Mu <dzm91@xxxxxxxxxxx>
---
v1->v2: instead of modifying error handling code, directly change
ioremap to devm_ioremap.
drivers/soc/loongson/loongson2_guts.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/soc/loongson/loongson2_guts.c b/drivers/soc/loongson/loongson2_guts.c
index bace4bc8e03b..a053e3fdae09 100644
--- a/drivers/soc/loongson/loongson2_guts.c
+++ b/drivers/soc/loongson/loongson2_guts.c
@@ -107,7 +107,7 @@ static int loongson2_guts_probe(struct platform_device *pdev)
guts->little_endian = of_property_read_bool(np, "little-endian");
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- guts->regs = ioremap(res->start, res->end - res->start + 1);
+ guts->regs = devm_ioremap(dev, res->start, res->end - res->start + 1);

resource_size(res) is exactly "res->end - res->start + 1", you may use that to simplify code now that you touched this line.

if (IS_ERR(guts->regs))
return PTR_ERR(guts->regs);

Otherwise LGTM, thanks! Untested by me though,

Reviewed-by: WANG Xuerui <git@xxxxxxxxxx>

--
WANG "xen0n" Xuerui

Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/