[PATCH v8 19/29] thermal/of: Remove of_thermal_get_crit_temp()

Daniel Lezcano posted 29 patches 3 years, 4 months ago
[PATCH v8 19/29] thermal/of: Remove of_thermal_get_crit_temp()
Posted by Daniel Lezcano 3 years, 4 months ago
The generic version of of_thermal_get_crit_temp() can be used. Let's
remove this ops which is pointless.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/thermal/thermal_of.c | 15 ---------------
 1 file changed, 15 deletions(-)

diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index 494e9c319541..bd872183e521 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -19,20 +19,6 @@
 
 #include "thermal_core.h"
 
-static int of_thermal_get_crit_temp(struct thermal_zone_device *tz,
-				    int *temp)
-{
-	int i;
-
-	for (i = 0; i < tz->num_trips; i++)
-		if (tz->trips[i].type == THERMAL_TRIP_CRITICAL) {
-			*temp = tz->trips[i].temperature;
-			return 0;
-		}
-
-	return -EINVAL;
-}
-
 /***   functions parsing device tree nodes   ***/
 
 static int of_find_trip_id(struct device_node *np, struct device_node *trip)
@@ -529,7 +515,6 @@ struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor,
 		goto out_kfree_trips;
 	}
 
-	of_ops->get_crit_temp = of_ops->get_crit_temp ? : of_thermal_get_crit_temp;
 	of_ops->bind = thermal_of_bind;
 	of_ops->unbind = thermal_of_unbind;
 
-- 
2.34.1
Re: [PATCH v8 19/29] thermal/of: Remove of_thermal_get_crit_temp()
Posted by Marek Szyprowski 3 years, 4 months ago
Hi Daniel,

On 03.10.2022 11:25, Daniel Lezcano wrote:
> The generic version of of_thermal_get_crit_temp() can be used. Let's
> remove this ops which is pointless.
>
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

This patch breaks Exynos thermal driver as it introduces a NULL pointer 
dereference in exynos_tmu_initialize():

8<--- cut here ---
Unable to handle kernel NULL pointer dereference at virtual address 00000000
[00000000] *pgd=00000000
Internal error: Oops: 80000005 [#1] PREEMPT SMP ARM
Modules linked in:
CPU: 1 PID: 1 Comm: swapper/0 Not tainted 6.0.0-rc1-00072-ge521efddb107 
#12941
Hardware name: Samsung Exynos (Flattened Device Tree)
dwc2 12480000.hsotg: new address 125
PC is at 0x0
LR is at exynos_tmu_initialize+0x4c/0x1e8
...
Process swapper/0 (pid: 1, stack limit = 0x(ptrval))
Stack: (0xf082dd78 to 0xf082e000)
...
  exynos_tmu_initialize from exynos_tmu_probe+0x2b0/0x728
  exynos_tmu_probe from platform_probe+0x5c/0xb8
  platform_probe from really_probe+0xe0/0x414
  really_probe from __driver_probe_device+0xa0/0x208
  __driver_probe_device from driver_probe_device+0x30/0xc0
  driver_probe_device from __driver_attach+0xf0/0x1f0
  __driver_attach from bus_for_each_dev+0x70/0xb0
  bus_for_each_dev from bus_add_driver+0x174/0x218
  bus_add_driver from driver_register+0x88/0x11c
  driver_register from do_one_initcall+0x64/0x380
  do_one_initcall from kernel_init_freeable+0x1c0/0x224
  kernel_init_freeable from kernel_init+0x18/0x12c
  kernel_init from ret_from_fork+0x14/0x2c
Exception stack(0xf082dfb0 to 0xf082dff8)
...
Code: bad PC value
---[ end trace 0000000000000000 ]---

If there is no replacement for tzd->ops->get_crit_temp(tzd, &temp), then 
please simply remove that call in exynos_tmu_initialize() to avoid 
breaking the initialization.

> ---
> drivers/thermal/thermal_of.c | 15 ---------------
> 1 file changed, 15 deletions(-)
>
> diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
> index 494e9c319541..bd872183e521 100644
> --- a/drivers/thermal/thermal_of.c
> +++ b/drivers/thermal/thermal_of.c
> @@ -19,20 +19,6 @@
> #include "thermal_core.h"
> -static int of_thermal_get_crit_temp(struct thermal_zone_device *tz,
> - int *temp)
> -{
> - int i;
> -
> - for (i = 0; i < tz->num_trips; i++)
> - if (tz->trips[i].type == THERMAL_TRIP_CRITICAL) {
> - *temp = tz->trips[i].temperature;
> - return 0;
> - }
> -
> - return -EINVAL;
> -}
> -
> /*** functions parsing device tree nodes ***/
> static int of_find_trip_id(struct device_node *np, struct device_node 
> *trip)
> @@ -529,7 +515,6 @@ struct thermal_zone_device 
> *thermal_of_zone_register(struct device_node *sensor,
> goto out_kfree_trips;
> }
> - of_ops->get_crit_temp = of_ops->get_crit_temp ? : 
> of_thermal_get_crit_temp;
> of_ops->bind = thermal_of_bind;
> of_ops->unbind = thermal_of_unbind;

Best regards

-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland

Re: [PATCH v8 19/29] thermal/of: Remove of_thermal_get_crit_temp()
Posted by Daniel Lezcano 3 years, 4 months ago
Hi Marek,

On 03/10/2022 14:50, Marek Szyprowski wrote:
> Hi Daniel,
> 
> On 03.10.2022 11:25, Daniel Lezcano wrote:
>> The generic version of of_thermal_get_crit_temp() can be used. Let's
>> remove this ops which is pointless.
>>
>> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> 
> This patch breaks Exynos thermal driver as it introduces a NULL pointer
> dereference in exynos_tmu_initialize():
> 

Thanks for testing and reporting, I've just sent a fix for that 
(unfortunately can not be tested from my side)



-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
[PATCH] thermal/drivers/exynos: Fix NULL pointer dereference when getting the critical temp
Posted by Daniel Lezcano 3 years, 4 months ago
The driver is assuming the get_critical temperature exists as it is
inherited by the thermal of ops. But this one has been removed in
favor of the generic one.

Use the generic thermal_zone_get_crit_temp() function instead

Fixes: 13bea86623b ("thermal/of: Remove of_thermal_get_crit_temp(")
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 drivers/thermal/samsung/exynos_tmu.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
index 5a1ffe2f3134..37465af59262 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -264,9 +264,8 @@ static int exynos_tmu_initialize(struct platform_device *pdev)
 	unsigned int status;
 	int ret = 0, temp;
 
-	if (data->soc != SOC_ARCH_EXYNOS5433) /* FIXME */
-		ret = tzd->ops->get_crit_temp(tzd, &temp);
-	if (ret) {
+	ret = thermal_zone_get_crit_temp(tzd, &temp);
+	if (ret && data->soc != SOC_ARCH_EXYNOS5433) { /* FIXME */
 		dev_err(&pdev->dev,
 			"No CRITICAL trip point defined in device tree!\n");
 		goto out;
-- 
2.34.1
Re: [PATCH] thermal/drivers/exynos: Fix NULL pointer dereference when getting the critical temp
Posted by Marek Szyprowski 3 years, 3 months ago
Hi Daniel,

On 03.10.2022 15:29, Daniel Lezcano wrote:
> The driver is assuming the get_critical temperature exists as it is
> inherited by the thermal of ops. But this one has been removed in
> favor of the generic one.
>
> Use the generic thermal_zone_get_crit_temp() function instead
>
> Fixes: 13bea86623b ("thermal/of: Remove of_thermal_get_crit_temp(")
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

This patch has been dropped from -next, is there are reason for that?


> ---
>   drivers/thermal/samsung/exynos_tmu.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
> index 5a1ffe2f3134..37465af59262 100644
> --- a/drivers/thermal/samsung/exynos_tmu.c
> +++ b/drivers/thermal/samsung/exynos_tmu.c
> @@ -264,9 +264,8 @@ static int exynos_tmu_initialize(struct platform_device *pdev)
>   	unsigned int status;
>   	int ret = 0, temp;
>   
> -	if (data->soc != SOC_ARCH_EXYNOS5433) /* FIXME */
> -		ret = tzd->ops->get_crit_temp(tzd, &temp);
> -	if (ret) {
> +	ret = thermal_zone_get_crit_temp(tzd, &temp);
> +	if (ret && data->soc != SOC_ARCH_EXYNOS5433) { /* FIXME */
>   		dev_err(&pdev->dev,
>   			"No CRITICAL trip point defined in device tree!\n");
>   		goto out;

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland
Re: [PATCH] thermal/drivers/exynos: Fix NULL pointer dereference when getting the critical temp
Posted by Daniel Lezcano 3 years, 3 months ago
On 17/10/2022 15:48, Marek Szyprowski wrote:
> Hi Daniel,
> 
> On 03.10.2022 15:29, Daniel Lezcano wrote:
>> The driver is assuming the get_critical temperature exists as it is
>> inherited by the thermal of ops. But this one has been removed in
>> favor of the generic one.
>>
>> Use the generic thermal_zone_get_crit_temp() function instead
>>
>> Fixes: 13bea86623b ("thermal/of: Remove of_thermal_get_crit_temp(")
>> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
>> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
> 
> This patch has been dropped from -next, is there are reason for that?

No, my mistake. I dropped it accidentally when I rebased the branch.

Thanks for pointing it out.


-- 
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
Re: [PATCH] thermal/drivers/exynos: Fix NULL pointer dereference when getting the critical temp
Posted by Marek Szyprowski 3 years, 4 months ago
On 03.10.2022 15:29, Daniel Lezcano wrote:
> The driver is assuming the get_critical temperature exists as it is
> inherited by the thermal of ops. But this one has been removed in
> favor of the generic one.
>
> Use the generic thermal_zone_get_crit_temp() function instead
>
> Fixes: 13bea86623b ("thermal/of: Remove of_thermal_get_crit_temp(")
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
> ---
>   drivers/thermal/samsung/exynos_tmu.c | 5 ++---
>   1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
> index 5a1ffe2f3134..37465af59262 100644
> --- a/drivers/thermal/samsung/exynos_tmu.c
> +++ b/drivers/thermal/samsung/exynos_tmu.c
> @@ -264,9 +264,8 @@ static int exynos_tmu_initialize(struct platform_device *pdev)
>   	unsigned int status;
>   	int ret = 0, temp;
>   
> -	if (data->soc != SOC_ARCH_EXYNOS5433) /* FIXME */
> -		ret = tzd->ops->get_crit_temp(tzd, &temp);
> -	if (ret) {
> +	ret = thermal_zone_get_crit_temp(tzd, &temp);
> +	if (ret && data->soc != SOC_ARCH_EXYNOS5433) { /* FIXME */
>   		dev_err(&pdev->dev,
>   			"No CRITICAL trip point defined in device tree!\n");
>   		goto out;

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland
Re: [PATCH] thermal/drivers/exynos: Fix NULL pointer dereference when getting the critical temp
Posted by Krzysztof Kozlowski 3 years, 4 months ago
On 03/10/2022 15:29, Daniel Lezcano wrote:
> The driver is assuming the get_critical temperature exists as it is
> inherited by the thermal of ops. But this one has been removed in
> favor of the generic one.
> 
> Use the generic thermal_zone_get_crit_temp() function instead
> 
> Fixes: 13bea86623b ("thermal/of: Remove of_thermal_get_crit_temp(")
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

Looks good.

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Best regards,
Krzysztof