[PATCH] nvme: Fix memory leak on error path of nvme_init
Andrew Goodbody
andrew.goodbody at linaro.org
Wed Jul 2 18:02:10 CEST 2025
The use of log_msg_ret to log a message and return an error meant that
memory allocated earlier in the function was not freed on this error
path. Instead log the message in the same way that log_msg_ret would do
and then goto the cleanup code to free the memory.
This issue found by Smatch.
Signed-off-by: Andrew Goodbody <andrew.goodbody at linaro.org>
---
drivers/nvme/nvme.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c
index 7c58ceb78f5..2b14437f69c 100644
--- a/drivers/nvme/nvme.c
+++ b/drivers/nvme/nvme.c
@@ -912,8 +912,10 @@ int nvme_init(struct udevice *udev)
goto free_id;
ret = bootdev_setup_for_sibling_blk(ns_udev, "nvme_bootdev");
- if (ret)
- return log_msg_ret("bootdev", ret);
+ if (ret) {
+ log_err("bootdev: returning err=%d\n", ret);
+ goto free_id;
+ }
ret = blk_probe_or_unbind(ns_udev);
if (ret)
---
base-commit: 7027b445cc0bfb86204ecb1f1fe596f5895048d9
change-id: 20250702-nvme_fix-c3c6925a4ba8
Best regards,
--
Andrew Goodbody <andrew.goodbody at linaro.org>
More information about the U-Boot
mailing list