Skip to contentSkip to conversation

nvme-hwmon: consistently ignore errors from nvme_hwmon_init

PATCH In review Christoph Hellwig 4 participants 5 messages Oct 19, 2022

Subsystems (2)
lore
Share & tools
lore

Christoph Hellwig

author maintainer
#0 lore raw

PATCH v2 1/1 nvme-hwmon: consistently ignore errors from nvme_hwmon_init

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.

---

Changes since v1:
- switch to ignoring the errors in the caller.

 drivers/nvme/host/core.c  |  6 +++++-
 drivers/nvme/host/hwmon.c | 13 ++++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)
drivers/nvme/host/core.c +5 -1
index 9cbe7854d4883..dc42206005855 100644
@@ -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;
 	}
 
drivers/nvme/host/hwmon.c +8 -5
index 0a586d7129201..23918bb7bdca2 100644
@@ -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)
Signature · 1 line
2.30.2
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Christoph Hellwig

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.

Quoted 68 lines

---

Changes since v1:
- switch to ignoring the errors in the caller.

  drivers/nvme/host/core.c  |  6 +++++-
  drivers/nvme/host/hwmon.c | 13 ++++++++-----
  2 files changed, 13 insertions(+), 6 deletions(-)
drivers/nvme/host/core.c +5 -1
index 9cbe7854d4883..dc42206005855 100644
@@ -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;
  	}
 
drivers/nvme/host/hwmon.c +8 -5
index 0a586d7129201..23918bb7bdca2 100644
@@ -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)
Reviewed-by on v2 1/1
#2 lore raw
In reply to Christoph Hellwig
Quoted 9 lines · Christoph Hellwig

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.

---

Changes since v1:
- switch to ignoring the errors in the caller.

Great! Thanks.

-Sergey

Quoted 67 lines
 drivers/nvme/host/core.c  |  6 +++++-
 drivers/nvme/host/hwmon.c | 13 ++++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)
drivers/nvme/host/core.c +5 -1
index 9cbe7854d4883..dc42206005855 100644
@@ -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;
 	}
 
drivers/nvme/host/hwmon.c +8 -5
index 0a586d7129201..23918bb7bdca2 100644
@@ -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)
Signature · 1 line
2.30.2
maintainer
#3 lore raw
In reply to Christoph Hellwig
Quoted 4 lines

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.

Maybe I'm missing something, but nvme_hwmon_init is not called from the reset flow, only in the first init, I don't understand how the commit msg follows the code.

Quoted 70 lines

---

Changes since v1:
- switch to ignoring the errors in the caller.

  drivers/nvme/host/core.c  |  6 +++++-
  drivers/nvme/host/hwmon.c | 13 ++++++++-----
  2 files changed, 13 insertions(+), 6 deletions(-)
drivers/nvme/host/core.c +5 -1
index 9cbe7854d4883..dc42206005855 100644
@@ -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;
  	}
 
drivers/nvme/host/hwmon.c +8 -5
index 0a586d7129201..23918bb7bdca2 100644
@@ -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)
author maintainer
#4 lore raw
Quoted 8 lines · Sagi Grimberg
Quoted 4 lines

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.

Maybe I'm missing something, but nvme_hwmon_init is not called from the reset flow, only in the first init, I don't understand how the commit msg follows the code.

If the controller is reset during initialization we'll get EINTR here.