[PATCH] nvme-hwmon: consistently ignore errors from nvme_hwmon_init
Christoph Hellwig
hch at lst.de
Tue Oct 18 08:32:40 PDT 2022
An NVMe controller works perfectly fine even when the hwmon
initialization fails. Stop returning errors that do not come from a
controller reset from nvme_hwmon_init to handle this case consistently.
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
drivers/nvme/host/hwmon.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/drivers/nvme/host/hwmon.c b/drivers/nvme/host/hwmon.c
index 0a586d7129201..0a550b82c183d 100644
--- a/drivers/nvme/host/hwmon.c
+++ b/drivers/nvme/host/hwmon.c
@@ -226,11 +226,11 @@ int nvme_hwmon_init(struct nvme_ctrl *ctrl)
struct device *dev = ctrl->device;
struct nvme_hwmon_data *data;
struct device *hwmon;
- int err;
+ int err = 0;
data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data)
- return 0;
+ goto err;
data->ctrl = ctrl;
mutex_init(&data->read_lock);
@@ -238,8 +238,7 @@ int nvme_hwmon_init(struct nvme_ctrl *ctrl)
err = nvme_hwmon_get_smart_log(data);
if (err) {
dev_warn(dev, "Failed to read smart log (error %d)\n", err);
- kfree(data);
- return err;
+ goto err_free_data;
}
hwmon = hwmon_device_register_with_info(dev, "nvme",
@@ -247,11 +246,22 @@ int nvme_hwmon_init(struct nvme_ctrl *ctrl)
NULL);
if (IS_ERR(hwmon)) {
dev_warn(dev, "Failed to instantiate hwmon device\n");
- kfree(data);
- return PTR_ERR(hwmon);
+ err = PTR_ERR(hwmon);
+ goto err_free_data;
}
ctrl->hwmon_device = hwmon;
return 0;
+
+err_free_data:
+ kfree(data);
+err:
+ /*
+ * Do not return errors unless we are in a controller reset.
+ * The controller works perfectly fine without the hwmon registration.
+ */
+ if (err == -EINTR)
+ return -EINTR;
+ return 0;
}
void nvme_hwmon_exit(struct nvme_ctrl *ctrl)
--
2.30.2
More information about the Linux-nvme
mailing list