From 282b9a1c3d3a15a2fb0d5db8e45e866660817681 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Fri, 28 Oct 2022 18:02:34 +0300 Subject: [PATCH] thermal/core: fix error code in __thermal_cooling_device_register() [ Upstream commit 4e2729ef5aa8400c15a84a9de558217efc8ec7d8 ] Return an error pointer if ->get_max_state() fails. The current code returns NULL which will cause an oops in the callers. Fixes: 743160b98189 ("thermal: Validate new state in cur_state_store()") Signed-off-by: Dan Carpenter Signed-off-by: Rafael J. Wysocki Stable-dep-of: f165a55dea80 ("thermal: core: call put_device() only after device_register() fails") Signed-off-by: Sasha Levin --- drivers/thermal/thermal_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 328da2f1d3393..449e60c4a1b69 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -892,7 +892,8 @@ __thermal_cooling_device_register(struct device_node *np, cdev->device.class = &thermal_class; cdev->devdata = devdata; - if (cdev->ops->get_max_state(cdev, &cdev->max_state)) + ret = cdev->ops->get_max_state(cdev, &cdev->max_state); + if (ret) goto out_kfree_type; thermal_cooling_device_setup_sysfs(cdev); -- 2.39.5