Skip to content

Commit

Permalink
nvme-hwmon: Return error code when registration fails
Browse files Browse the repository at this point in the history
The hwmon pointer wont be NULL if the registration fails. Though the
exit code path will assign it to ctrl->hwmon_device. Later
nvme_hwmon_exit() will try to free the invalid pointer. Avoid this by
returning the error code from hwmon_device_register_with_info().

Fixes: ed7770f ("nvme/hwmon: rework to avoid devm allocation")
Signed-off-by: Daniel Wagner <dwagner@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Daniel Wagner authored and Christoph Hellwig committed Mar 5, 2021
1 parent 6e6a682 commit 78570f8
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions drivers/nvme/host/hwmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ int nvme_hwmon_init(struct nvme_ctrl *ctrl)
if (IS_ERR(hwmon)) {
dev_warn(dev, "Failed to instantiate hwmon device\n");
kfree(data);
return PTR_ERR(hwmon);
}
ctrl->hwmon_device = hwmon;
return 0;
Expand Down

0 comments on commit 78570f8

Please sign in to comment.