[PATCH v4 3/9] thermal/drivers/mediatek/lvts: Fail probe if temp_factor is zero

Laura Nao posted 9 patches 1 week, 3 days ago
There is a newer version of this series
[PATCH v4 3/9] thermal/drivers/mediatek/lvts: Fail probe if temp_factor is zero
Posted by Laura Nao 1 week, 3 days ago
temp_factor is used in lvts_temp_to_raw() and lvts_raw_to_temp(). If
platform data is incorrect and temp_factor is zero, it could cause a
division by zero. Fail the probe early to prevent a kernel crash.

Signed-off-by: Laura Nao <laura.nao@collabora.com>
---
 drivers/thermal/mediatek/lvts_thermal.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index 1c54d0b75b1a..b49441d82ffd 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -1346,6 +1346,11 @@ static int lvts_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return irq;
 
+	if (!lvts_data->temp_factor)
+		return dev_err_probe(
+			dev, -EINVAL,
+			"temp_factor should never be zero; check platform data.\n");
+
 	golden_temp_offset = lvts_data->temp_offset;
 
 	ret = lvts_domain_init(dev, lvts_td, lvts_data);

-- 
2.39.5
Re: [PATCH v4 3/9] thermal/drivers/mediatek/lvts: Fail probe if temp_factor is zero
Posted by Daniel Lezcano 1 week ago
On 11/21/25 12:16, Laura Nao wrote:
> temp_factor is used in lvts_temp_to_raw() and lvts_raw_to_temp(). If
> platform data is incorrect and temp_factor is zero, it could cause a
> division by zero. Fail the probe early to prevent a kernel crash.
> 
> Signed-off-by: Laura Nao <laura.nao@collabora.com>
> ---
>   drivers/thermal/mediatek/lvts_thermal.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> index 1c54d0b75b1a..b49441d82ffd 100644
> --- a/drivers/thermal/mediatek/lvts_thermal.c
> +++ b/drivers/thermal/mediatek/lvts_thermal.c
> @@ -1346,6 +1346,11 @@ static int lvts_probe(struct platform_device *pdev)
>   	if (irq < 0)
>   		return irq;
>   
> +	if (!lvts_data->temp_factor)
> +		return dev_err_probe(
> +			dev, -EINVAL,
> +			"temp_factor should never be zero; check platform data.\n");
> +

 From my POV, this is not really useful. The temp_factor is set for each 
version statically in the code. The scope is limited to the driver, IOW 
it is not a parameter other subsystems passes to the driver.

If it is NULL, then shame on the submitter who did not test the driver 
before sending ;)



-- 
<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 v4 3/9] thermal/drivers/mediatek/lvts: Fail probe if temp_factor is zero
Posted by Laura Nao 6 days, 14 hours ago
On 11/24/25 18:56, Daniel Lezcano wrote:
> On 11/21/25 12:16, Laura Nao wrote:
>> temp_factor is used in lvts_temp_to_raw() and lvts_raw_to_temp(). If
>> platform data is incorrect and temp_factor is zero, it could cause a
>> division by zero. Fail the probe early to prevent a kernel crash.
>>
>> Signed-off-by: Laura Nao <laura.nao@collabora.com>
>> ---
>>   drivers/thermal/mediatek/lvts_thermal.c | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
>> index 1c54d0b75b1a..b49441d82ffd 100644
>> --- a/drivers/thermal/mediatek/lvts_thermal.c
>> +++ b/drivers/thermal/mediatek/lvts_thermal.c
>> @@ -1346,6 +1346,11 @@ static int lvts_probe(struct platform_device *pdev)
>>       if (irq < 0)
>>           return irq;
>>   +    if (!lvts_data->temp_factor)
>> +        return dev_err_probe(
>> +            dev, -EINVAL,
>> +            "temp_factor should never be zero; check platform data.\n");
>> + 
>
> From my POV, this is not really useful. The temp_factor is set for each version statically in the code. The scope is limited to the driver, IOW it is not a parameter other subsystems passes to the driver.
>
> If it is NULL, then shame on the submitter who did not test the driver before sending ;)
>

Ack - I'll drop the patch in the next revision.

Thanks,

Laura
Re: [PATCH v4 3/9] thermal/drivers/mediatek/lvts: Fail probe if temp_factor is zero
Posted by AngeloGioacchino Del Regno 1 week, 3 days ago
Il 21/11/25 12:16, Laura Nao ha scritto:
> temp_factor is used in lvts_temp_to_raw() and lvts_raw_to_temp(). If
> platform data is incorrect and temp_factor is zero, it could cause a
> division by zero. Fail the probe early to prevent a kernel crash.
> 
> Signed-off-by: Laura Nao <laura.nao@collabora.com>
> ---
>   drivers/thermal/mediatek/lvts_thermal.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> index 1c54d0b75b1a..b49441d82ffd 100644
> --- a/drivers/thermal/mediatek/lvts_thermal.c
> +++ b/drivers/thermal/mediatek/lvts_thermal.c
> @@ -1346,6 +1346,11 @@ static int lvts_probe(struct platform_device *pdev)
>   	if (irq < 0)
>   		return irq;
>   
> +	if (!lvts_data->temp_factor)
> +		return dev_err_probe(
> +			dev, -EINVAL,
> +			"temp_factor should never be zero; check platform data.\n");
> +

		return dev_err_probe(dev, -EINVAL,
				     "temp_factor should never be zero; check platform data.\n");

That's the only nitpick that I've got here, and I'm fine either way, anyway, as
this then kind of boils down to personal preference, in a way.

So, regardless of this getting fixed (by the maintainer or by you) or not:

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

>   	golden_temp_offset = lvts_data->temp_offset;
>   
>   	ret = lvts_domain_init(dev, lvts_td, lvts_data);
>