]> git.baikalelectronics.ru Git - kernel.git/commitdiff
nvme-hwmon: Return error code when registration fails
authorDaniel Wagner <dwagner@suse.de>
Fri, 12 Feb 2021 09:30:15 +0000 (10:30 +0100)
committerChristoph Hellwig <hch@lst.de>
Fri, 5 Mar 2021 12:41:03 +0000 (13:41 +0100)
The hwmon pointer wont be NULL if the registration fails. Though the
exit code path will assign it to ctrl->hwmon_device. Later
nvme_hwmon_exit() will try to free the invalid pointer. Avoid this by
returning the error code from hwmon_device_register_with_info().

Fixes: ed7770f66286 ("nvme/hwmon: rework to avoid devm allocation")
Signed-off-by: Daniel Wagner <dwagner@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/hwmon.c

index 8f9e96986780e6f831a90022f305a93f5d3fc9b1..0a586d7129201761d411c13b7e20425d4287c5c8 100644 (file)
@@ -248,6 +248,7 @@ int nvme_hwmon_init(struct nvme_ctrl *ctrl)
        if (IS_ERR(hwmon)) {
                dev_warn(dev, "Failed to instantiate hwmon device\n");
                kfree(data);
+               return PTR_ERR(hwmon);
        }
        ctrl->hwmon_device = hwmon;
        return 0;