]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
nvme: Fix memory leak on error path of nvme_init
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Wed, 2 Jul 2025 16:02:10 +0000 (17:02 +0100)
committerTom Rini <trini@konsulko.com>
Thu, 10 Jul 2025 14:41:23 +0000 (08:41 -0600)
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@linaro.org>
drivers/nvme/nvme.c

index 7c58ceb78f515ccaa56abe9616f09159e422e0d0..2b14437f69c2a42a6acd82125f259957c8111dad 100644 (file)
@@ -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)