Skip to content

Commit 0da7824

Browse files
ISCAS-Vulabandersson
authored andcommitted
soc: qcom: cmd-db: Use devm_memremap() to fix memory leak in cmd_db_dev_probe
If cmd_db_magic_matches() fails after memremap() succeeds, the function returns -EINVAL without unmapping the memory region, causing a potential resource leak. Switch to devm_memremap to automatically manage the map resource. Fixes: 312416d ("drivers: qcom: add command DB driver") Suggested-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> Signed-off-by: Haotian Zhang <vulab@iscas.ac.cn> Link: https://lore.kernel.org/r/20251216013933.773-1-vulab@iscas.ac.cn Signed-off-by: Bjorn Andersson <andersson@kernel.org>
1 parent 0539c5a commit 0da7824

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

drivers/soc/qcom/cmd-db.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,16 @@ static int cmd_db_dev_probe(struct platform_device *pdev)
349349
return -EINVAL;
350350
}
351351

352-
cmd_db_header = memremap(rmem->base, rmem->size, MEMREMAP_WC);
353-
if (!cmd_db_header) {
354-
ret = -ENOMEM;
352+
cmd_db_header = devm_memremap(&pdev->dev, rmem->base, rmem->size, MEMREMAP_WC);
353+
if (IS_ERR(cmd_db_header)) {
354+
ret = PTR_ERR(cmd_db_header);
355355
cmd_db_header = NULL;
356356
return ret;
357357
}
358358

359359
if (!cmd_db_magic_matches(cmd_db_header)) {
360360
dev_err(&pdev->dev, "Invalid Command DB Magic\n");
361+
cmd_db_header = NULL;
361362
return -EINVAL;
362363
}
363364

0 commit comments

Comments
 (0)