Commit 0e03357d authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Lipeng Sang
Browse files

nvme-hwmon: consistently ignore errors from nvme_hwmon_init

stable inclusion
from stable-v5.10.152
commit 770b7e3a2c1f32e82c5c9143d0a3670e9ea95a5f
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I73HJ0

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=770b7e3a2c1f32e82c5c9143d0a3670e9ea95a5f



--------------------------------

[ Upstream commit 6b8cf940 ]

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
Reviewed-by: default avatarSerge Semin <fancer.lancer@gmail.com>
Stable-dep-of: c94b7f9b ("nvme-hwmon: kmalloc the NVME SMART log buffer")
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarLipeng Sang <sanglipeng1@jd.com>
parent 9cabb0fb
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -3195,8 +3195,12 @@ int nvme_init_identify(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;
	}

+8 −5
Original line number Diff line number Diff line
@@ -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)