Skip to contentSkip to conversation

thermal/core: fix error code in __thermal_cooling_device_register()

PATCH Applied Dan Carpenter 3 participants 3 messages Oct 28, 2022 – Oct 31, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal/core: fix error code in __thermal_cooling_device_register()

Return an error pointer if ->get_max_state() fails. The current code returns NULL which will cause an oops in the callers.

Fixes c408b3d1d9bb ("thermal: Validate new state in cur_state_store()")
---
 drivers/thermal/thermal_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thermal/thermal_core.c +2 -1
index 4ba7b524e5de..c4d18e462de8 100644
@@ -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);
Signature · 1 line
2.35.1
maintainer Applied
#1 lore raw
Quoted 15 lines · Dan Carpenter

Return an error pointer if ->get_max_state() fails. The current code returns NULL which will cause an oops in the callers.

Fixes c408b3d1d9bb ("thermal: Validate new state in cur_state_store()")
---
 drivers/thermal/thermal_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thermal/thermal_core.c +0 -0
index 4ba7b524e5de..c4d18e462de8 100644

drivers/thermal/thermal_core.c __thermal_cooling_device_register(struct device_node *np,

Quoted 10 lines
drivers/thermal/thermal_core.c +2 -2
@@ -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);
--

Applied, thanks!

Acked-by on v1 1/1
#2 lore raw
In reply to Dan Carpenter
Quoted 14 lines · Dan Carpenter

Return an error pointer if ->get_max_state() fails. The current code returns NULL which will cause an oops in the callers.

Fixes c408b3d1d9bb ("thermal: Validate new state in cur_state_store()")
---
 drivers/thermal/thermal_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/thermal/thermal_core.c +0 -0
index 4ba7b524e5de..c4d18e462de8 100644

drivers/thermal/thermal_core.c __thermal_cooling_device_register(struct device_node *np, · line 899

Quoted 9 lines
drivers/thermal/thermal_core.c +2 -1
@@ -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);

Bad mistake.

Signature · 1 line
viresh