Skip to content

Commit 59e330f

Browse files
keithbuschChristoph Hellwig
authored andcommitted
nvme: return errors for hwmon init
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>
1 parent 4a2dd2c commit 59e330f

3 files changed

Lines changed: 16 additions & 12 deletions

File tree

drivers/nvme/host/core.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,8 +3236,11 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)
32363236
if (ret < 0)
32373237
return ret;
32383238

3239-
if (!ctrl->identified)
3240-
nvme_hwmon_init(ctrl);
3239+
if (!ctrl->identified) {
3240+
ret = nvme_hwmon_init(ctrl);
3241+
if (ret < 0)
3242+
return ret;
3243+
}
32413244

32423245
ctrl->identified = true;
32433246

drivers/nvme/host/hwmon.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,8 @@ static int nvme_set_temp_thresh(struct nvme_ctrl *ctrl, int sensor, bool under,
5959

6060
static int nvme_hwmon_get_smart_log(struct nvme_hwmon_data *data)
6161
{
62-
int ret;
63-
64-
ret = nvme_get_log(data->ctrl, NVME_NSID_ALL, NVME_LOG_SMART, 0,
62+
return nvme_get_log(data->ctrl, NVME_NSID_ALL, NVME_LOG_SMART, 0,
6563
NVME_CSI_NVM, &data->log, sizeof(data->log), 0);
66-
67-
return ret <= 0 ? ret : -EIO;
6864
}
6965

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

228-
void nvme_hwmon_init(struct nvme_ctrl *ctrl)
224+
int nvme_hwmon_init(struct nvme_ctrl *ctrl)
229225
{
230226
struct device *dev = ctrl->dev;
231227
struct nvme_hwmon_data *data;
@@ -234,7 +230,7 @@ void nvme_hwmon_init(struct nvme_ctrl *ctrl)
234230

235231
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
236232
if (!data)
237-
return;
233+
return 0;
238234

239235
data->ctrl = ctrl;
240236
mutex_init(&data->read_lock);
@@ -244,7 +240,7 @@ void nvme_hwmon_init(struct nvme_ctrl *ctrl)
244240
dev_warn(ctrl->device,
245241
"Failed to read smart log (error %d)\n", err);
246242
devm_kfree(dev, data);
247-
return;
243+
return err;
248244
}
249245

250246
hwmon = devm_hwmon_device_register_with_info(dev, "nvme", data,
@@ -254,4 +250,6 @@ void nvme_hwmon_init(struct nvme_ctrl *ctrl)
254250
dev_warn(dev, "Failed to instantiate hwmon device\n");
255251
devm_kfree(dev, data);
256252
}
253+
254+
return 0;
257255
}

drivers/nvme/host/nvme.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,12 @@ static inline struct nvme_ns *nvme_get_ns_from_dev(struct device *dev)
827827
}
828828

829829
#ifdef CONFIG_NVME_HWMON
830-
void nvme_hwmon_init(struct nvme_ctrl *ctrl);
830+
int nvme_hwmon_init(struct nvme_ctrl *ctrl);
831831
#else
832-
static inline void nvme_hwmon_init(struct nvme_ctrl *ctrl) { }
832+
static inline int nvme_hwmon_init(struct nvme_ctrl *ctrl)
833+
{
834+
return 0;
835+
}
833836
#endif
834837

835838
u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns,

0 commit comments

Comments
 (0)