Skip to content

Commit

Permalink
nvme-hwmon: consistently ignore errors from nvme_hwmon_init
Browse files Browse the repository at this point in the history
[ Upstream commit 6b8cf94 ]

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>
Stable-dep-of: c94b7f9 ("nvme-hwmon: kmalloc the NVME SMART log buffer")
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Christoph Hellwig authored and gregkh committed Oct 29, 2022
1 parent 4777260 commit dece37b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 5 additions & 1 deletion drivers/nvme/host/core.c
Expand Up @@ -3256,8 +3256,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;
}

Expand Down
13 changes: 8 additions & 5 deletions drivers/nvme/host/hwmon.c
Expand Up @@ -230,28 +230,31 @@ 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);

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",
data, &nvme_hwmon_chip_info,
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)
Expand Down

0 comments on commit dece37b

Please sign in to comment.