Skip to content

Commit

Permalink
nvme: return errors for hwmon init
Browse files Browse the repository at this point in the history
Initializing the nvme hwmon retrieves a log from the controller. If the
controller is broken, we need to return the appropriate error so that
subsequent initialization doesn't attempt to continue.

Reported-by: Tong Zhang <ztong0001@gmail.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Keith Busch authored and Christoph Hellwig committed Sep 22, 2020
1 parent 4a2dd2c commit 59e330f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
7 changes: 5 additions & 2 deletions drivers/nvme/host/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3236,8 +3236,11 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
if (ret < 0)
return ret;

if (!ctrl->identified)
nvme_hwmon_init(ctrl);
if (!ctrl->identified) {
ret = nvme_hwmon_init(ctrl);
if (ret < 0)
return ret;
}

ctrl->identified = true;

Expand Down
14 changes: 6 additions & 8 deletions drivers/nvme/host/hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ static int nvme_set_temp_thresh(struct nvme_ctrl *ctrl, int sensor, bool under,

static int nvme_hwmon_get_smart_log(struct nvme_hwmon_data *data)
{
int ret;

ret = nvme_get_log(data->ctrl, NVME_NSID_ALL, NVME_LOG_SMART, 0,
return nvme_get_log(data->ctrl, NVME_NSID_ALL, NVME_LOG_SMART, 0,
NVME_CSI_NVM, &data->log, sizeof(data->log), 0);

return ret <= 0 ? ret : -EIO;
}

static int nvme_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
Expand Down Expand Up @@ -225,7 +221,7 @@ static const struct hwmon_chip_info nvme_hwmon_chip_info = {
.info = nvme_hwmon_info,
};

void nvme_hwmon_init(struct nvme_ctrl *ctrl)
int nvme_hwmon_init(struct nvme_ctrl *ctrl)
{
struct device *dev = ctrl->dev;
struct nvme_hwmon_data *data;
Expand All @@ -234,7 +230,7 @@ void nvme_hwmon_init(struct nvme_ctrl *ctrl)

data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return;
return 0;

data->ctrl = ctrl;
mutex_init(&data->read_lock);
Expand All @@ -244,7 +240,7 @@ void nvme_hwmon_init(struct nvme_ctrl *ctrl)
dev_warn(ctrl->device,
"Failed to read smart log (error %d)\n", err);
devm_kfree(dev, data);
return;
return err;
}

hwmon = devm_hwmon_device_register_with_info(dev, "nvme", data,
Expand All @@ -254,4 +250,6 @@ void nvme_hwmon_init(struct nvme_ctrl *ctrl)
dev_warn(dev, "Failed to instantiate hwmon device\n");
devm_kfree(dev, data);
}

return 0;
}
7 changes: 5 additions & 2 deletions drivers/nvme/host/nvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -827,9 +827,12 @@ static inline struct nvme_ns *nvme_get_ns_from_dev(struct device *dev)
}

#ifdef CONFIG_NVME_HWMON
void nvme_hwmon_init(struct nvme_ctrl *ctrl);
int nvme_hwmon_init(struct nvme_ctrl *ctrl);
#else
static inline void nvme_hwmon_init(struct nvme_ctrl *ctrl) { }
static inline int nvme_hwmon_init(struct nvme_ctrl *ctrl)
{
return 0;
}
#endif

u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
Expand Down

0 comments on commit 59e330f

Please sign in to comment.