lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250722095752.28245-1-laura.nao@collabora.com>
Date: Tue, 22 Jul 2025 11:57:52 +0200
From: Laura Nao <laura.nao@...labora.com>
To: wenst@...omium.org
Cc: andrew-ct.chen@...iatek.com,
	angelogioacchino.delregno@...labora.com,
	arnd@...db.de,
	bchihi@...libre.com,
	colin.i.king@...il.com,
	conor+dt@...nel.org,
	daniel.lezcano@...aro.org,
	devicetree@...r.kernel.org,
	kernel@...labora.com,
	krzk+dt@...nel.org,
	lala.lin@...iatek.com,
	laura.nao@...labora.com,
	linux-arm-kernel@...ts.infradead.org,
	linux-kernel@...r.kernel.org,
	linux-mediatek@...ts.infradead.org,
	linux-pm@...r.kernel.org,
	lukasz.luba@....com,
	matthias.bgg@...il.com,
	nfraprado@...labora.com,
	rafael@...nel.org,
	robh@...nel.org,
	rui.zhang@...el.com,
	srini@...nel.org,
	u.kleine-koenig@...libre.com
Subject: Re: [PATCH 3/9] thermal/drivers/mediatek/lvts: Guard against zero temp_factor in lvts_raw_to_temp

On 7/21/25 12:08, Chen-Yu Tsai wrote:
> On Mon, Jul 21, 2025 at 4:26 PM Laura Nao <laura.nao@...labora.com> wrote:
>>
>> Add a guard against zero temp_factor in lvts_raw_to_temp() to prevent
>> division by zero and ensure safe conversion.
>>
>> Fixes: 6725a29321e4 ("thermal/drivers/mediatek/lvts_thermal: Make coeff configurable")
>> Signed-off-by: Laura Nao <laura.nao@...labora.com>
>
> Code wise,
>
> Reviewed-by: Chen-Yu Tsai <wenst@...omium.org>
>
> However I assume this would only happen with bad platform data? The
> factor should _never_ be zero. Maybe also issue a warning in the probe
> function?
>

Yes, this should only occur with incorrect platform data. Adding a
warning in the probe function sounds like a good idea to catch 
any misconfiguration early. I’ll include that in the next revision.

Thanks,

Laura

> ChenYu
>
>> ---
>>  drivers/thermal/mediatek/lvts_thermal.c | 9 ++++++---
>>  1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
>> index 8d5259b9d03b..b80c2929ae74 100644
>> --- a/drivers/thermal/mediatek/lvts_thermal.c
>> +++ b/drivers/thermal/mediatek/lvts_thermal.c
>> @@ -280,11 +280,14 @@ static int lvts_raw_to_temp(u32 raw_temp, int temp_factor)
>>
>>  static u32 lvts_temp_to_raw(int temperature, int temp_factor)
>>  {
>> -       u32 raw_temp = ((s64)(golden_temp_offset - temperature)) << 14;
>> +       u32 raw_temp;
>>
>> -       raw_temp = div_s64(raw_temp, -temp_factor);
>> +       if (temp_factor == 0)
>> +               return temperature;
>>
>> -       return raw_temp;
>> +       raw_temp = ((s64)(golden_temp_offset - temperature)) << 14;
>> +
>> +       return div_s64(raw_temp, -temp_factor);
>>  }
>>
>>  static int lvts_get_temp(struct thermal_zone_device *tz, int *temp)
>> --
>> 2.39.5
>>
>>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ