Blob Blame History Raw
From: Daniel Wagner <dwagner@suse.de>
Date: Fri, 12 Feb 2021 10:30:15 +0100
Subject: nvme-hwmon: Return error code when registration fails
Patch-mainline: v5.12-rc2
Git-commit: 78570f8873c8cd44c12714c7fa7db2601ec5617d
References: bsc#1177326

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 |    1 +
 1 file changed, 1 insertion(+)

--- a/drivers/nvme/host/hwmon.c
+++ b/drivers/nvme/host/hwmon.c
@@ -252,6 +252,7 @@ int nvme_hwmon_init(struct nvme_ctrl *ct
 	if (IS_ERR(hwmon)) {
 		dev_warn(dev, "Failed to instantiate hwmon device\n");
 		kfree(data);
+		return PTR_ERR(hwmon);
 	}
 
 	ctrl->hwmon_device = hwmon;