]> git.baikalelectronics.ru Git - kernel.git/commitdiff
nvme-hwmon: consistently ignore errors from nvme_hwmon_init
authorChristoph Hellwig <hch@lst.de>
Tue, 18 Oct 2022 14:55:55 +0000 (16:55 +0200)
committerChristoph Hellwig <hch@lst.de>
Wed, 19 Oct 2022 10:42:58 +0000 (12:42 +0200)
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@lst.de>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Serge Semin <fancer.lancer@gmail.com>
drivers/nvme/host/core.c
drivers/nvme/host/hwmon.c

index 9cbe7854d4883c5820b24773a30553132bf3567e..dc42206005855dce9ce9cc2ec60429995f246573 100644 (file)
@@ -3262,8 +3262,12 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl)
                return ret;
 
        if (!ctrl->identified && !nvme_discovery_ctrl(ctrl)) {
+               /*
+                * Do not return errors unless we are in a controller reset,
+                * the controller works perfectly fine without hwmon.
+                */
                ret = nvme_hwmon_init(ctrl);
-               if (ret < 0)
+               if (ret == -EINTR)
                        return ret;
        }
 
index 0a586d7129201761d411c13b7e20425d4287c5c8..23918bb7bdca2b1800dc8cabbd9d912845baa389 100644 (file)
@@ -230,7 +230,7 @@ int nvme_hwmon_init(struct nvme_ctrl *ctrl)
 
        data = kzalloc(sizeof(*data), GFP_KERNEL);
        if (!data)
-               return 0;
+               return -ENOMEM;
 
        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,15 @@ 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);
+       return err;
 }
 
 void nvme_hwmon_exit(struct nvme_ctrl *ctrl)