Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH] thermal/drivers/mediatek/lvts_thermal: Return error in case of invalid efuse data
@ 2024-06-03 12:06 Julien Panis
  2024-06-04 16:19 ` Nicolas Pitre
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Julien Panis @ 2024-06-03 12:06 UTC (permalink / raw)
  To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Matthias Brugger, AngeloGioacchino Del Regno, Nicolas Pitre
  Cc: linux-pm, linux-kernel, linux-arm-kernel, linux-mediatek,
	Julien Panis

This patch prevents from registering thermal entries and letting the
driver misbehave if efuse data is invalid. A device is not properly
calibrated if the golden temperature is zero.

Signed-off-by: Julien Panis <jpanis@baylibre.com>
---
Guard against invalid calibration data, following this discussion:
https://lore.kernel.org/all/ad047631-16b8-42ce-8a8d-1429e6af4517@collabora.com/
---
 drivers/thermal/mediatek/lvts_thermal.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
index 0bb3a495b56e..185d5a32711f 100644
--- a/drivers/thermal/mediatek/lvts_thermal.c
+++ b/drivers/thermal/mediatek/lvts_thermal.c
@@ -769,7 +769,11 @@ static int lvts_golden_temp_init(struct device *dev, u8 *calib,
 	 */
 	gt = (((u32 *)calib)[0] >> lvts_data->gt_calib_bit_offset) & 0xff;
 
-	if (gt && gt < LVTS_GOLDEN_TEMP_MAX)
+	/* A zero value for gt means that device has invalid efuse data */
+	if (!gt)
+		return -ENODATA;
+
+	if (gt < LVTS_GOLDEN_TEMP_MAX)
 		golden_temp = gt;
 
 	golden_temp_offset = golden_temp * 500 + lvts_data->temp_offset;

---
base-commit: 632483ea8004edfadd035de36e1ab2c7c4f53158
change-id: 20240603-mtk-thermal-calib-check-ba2ec24a1c32

Best regards,
-- 
Julien Panis <jpanis@baylibre.com>


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] thermal/drivers/mediatek/lvts_thermal: Return error in case of invalid efuse data
  2024-06-03 12:06 [PATCH] thermal/drivers/mediatek/lvts_thermal: Return error in case of invalid efuse data Julien Panis
@ 2024-06-04 16:19 ` Nicolas Pitre
  2024-06-04 16:26 ` Daniel Lezcano
  2024-06-04 16:29 ` AngeloGioacchino Del Regno
  2 siblings, 0 replies; 6+ messages in thread
From: Nicolas Pitre @ 2024-06-04 16:19 UTC (permalink / raw)
  To: Julien Panis
  Cc: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
	Matthias Brugger, AngeloGioacchino Del Regno, linux-pm,
	linux-kernel, linux-arm-kernel, linux-mediatek

On Mon, 3 Jun 2024, Julien Panis wrote:

> This patch prevents from registering thermal entries and letting the
> driver misbehave if efuse data is invalid. A device is not properly
> calibrated if the golden temperature is zero.
> 
> Signed-off-by: Julien Panis <jpanis@baylibre.com>

Reviewed-by: Nicolas Pitre <npitre@baylibre.com>

> ---
> Guard against invalid calibration data, following this discussion:
> https://lore.kernel.org/all/ad047631-16b8-42ce-8a8d-1429e6af4517@collabora.com/
> ---
>  drivers/thermal/mediatek/lvts_thermal.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> index 0bb3a495b56e..185d5a32711f 100644
> --- a/drivers/thermal/mediatek/lvts_thermal.c
> +++ b/drivers/thermal/mediatek/lvts_thermal.c
> @@ -769,7 +769,11 @@ static int lvts_golden_temp_init(struct device *dev, u8 *calib,
>  	 */
>  	gt = (((u32 *)calib)[0] >> lvts_data->gt_calib_bit_offset) & 0xff;
>  
> -	if (gt && gt < LVTS_GOLDEN_TEMP_MAX)
> +	/* A zero value for gt means that device has invalid efuse data */
> +	if (!gt)
> +		return -ENODATA;
> +
> +	if (gt < LVTS_GOLDEN_TEMP_MAX)
>  		golden_temp = gt;
>  
>  	golden_temp_offset = golden_temp * 500 + lvts_data->temp_offset;
> 
> ---
> base-commit: 632483ea8004edfadd035de36e1ab2c7c4f53158
> change-id: 20240603-mtk-thermal-calib-check-ba2ec24a1c32
> 
> Best regards,
> -- 
> Julien Panis <jpanis@baylibre.com>
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] thermal/drivers/mediatek/lvts_thermal: Return error in case of invalid efuse data
  2024-06-03 12:06 [PATCH] thermal/drivers/mediatek/lvts_thermal: Return error in case of invalid efuse data Julien Panis
  2024-06-04 16:19 ` Nicolas Pitre
@ 2024-06-04 16:26 ` Daniel Lezcano
  2024-06-04 16:29 ` AngeloGioacchino Del Regno
  2 siblings, 0 replies; 6+ messages in thread
From: Daniel Lezcano @ 2024-06-04 16:26 UTC (permalink / raw)
  To: Julien Panis, Rafael J. Wysocki, Zhang Rui, Lukasz Luba,
	Matthias Brugger, AngeloGioacchino Del Regno, Nicolas Pitre
  Cc: linux-pm, linux-kernel, linux-arm-kernel, linux-mediatek

On 03/06/2024 14:06, Julien Panis wrote:
> This patch prevents from registering thermal entries and letting the
> driver misbehave if efuse data is invalid. A device is not properly
> calibrated if the golden temperature is zero.
> 
> Signed-off-by: Julien Panis <jpanis@baylibre.com>
> ---

Applied, thanks

-- 
<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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] thermal/drivers/mediatek/lvts_thermal: Return error in case of invalid efuse data
  2024-06-03 12:06 [PATCH] thermal/drivers/mediatek/lvts_thermal: Return error in case of invalid efuse data Julien Panis
  2024-06-04 16:19 ` Nicolas Pitre
  2024-06-04 16:26 ` Daniel Lezcano
@ 2024-06-04 16:29 ` AngeloGioacchino Del Regno
  2024-06-04 16:33   ` Nicolas Pitre
  2 siblings, 1 reply; 6+ messages in thread
From: AngeloGioacchino Del Regno @ 2024-06-04 16:29 UTC (permalink / raw)
  To: Julien Panis, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
	Lukasz Luba, Matthias Brugger, Nicolas Pitre
  Cc: linux-pm, linux-kernel, linux-arm-kernel, linux-mediatek

Il 03/06/24 14:06, Julien Panis ha scritto:
> This patch prevents from registering thermal entries and letting the
> driver misbehave if efuse data is invalid. A device is not properly
> calibrated if the golden temperature is zero.
> 
> Signed-off-by: Julien Panis <jpanis@baylibre.com>

Fixes tag, please.

Regards,
Angelo

> ---
> Guard against invalid calibration data, following this discussion:
> https://lore.kernel.org/all/ad047631-16b8-42ce-8a8d-1429e6af4517@collabora.com/
> ---
>   drivers/thermal/mediatek/lvts_thermal.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c
> index 0bb3a495b56e..185d5a32711f 100644
> --- a/drivers/thermal/mediatek/lvts_thermal.c
> +++ b/drivers/thermal/mediatek/lvts_thermal.c
> @@ -769,7 +769,11 @@ static int lvts_golden_temp_init(struct device *dev, u8 *calib,
>   	 */
>   	gt = (((u32 *)calib)[0] >> lvts_data->gt_calib_bit_offset) & 0xff;
>   
> -	if (gt && gt < LVTS_GOLDEN_TEMP_MAX)
> +	/* A zero value for gt means that device has invalid efuse data */
> +	if (!gt)
> +		return -ENODATA;
> +
> +	if (gt < LVTS_GOLDEN_TEMP_MAX)
>   		golden_temp = gt;
>   
>   	golden_temp_offset = golden_temp * 500 + lvts_data->temp_offset;
> 
> ---
> base-commit: 632483ea8004edfadd035de36e1ab2c7c4f53158
> change-id: 20240603-mtk-thermal-calib-check-ba2ec24a1c32
> 
> Best regards,



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] thermal/drivers/mediatek/lvts_thermal: Return error in case of invalid efuse data
  2024-06-04 16:29 ` AngeloGioacchino Del Regno
@ 2024-06-04 16:33   ` Nicolas Pitre
  2024-06-05 10:33     ` AngeloGioacchino Del Regno
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Pitre @ 2024-06-04 16:33 UTC (permalink / raw)
  To: AngeloGioacchino Del Regno
  Cc: Julien Panis, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
	Lukasz Luba, Matthias Brugger, linux-pm, linux-kernel,
	linux-arm-kernel, linux-mediatek

On Tue, 4 Jun 2024, AngeloGioacchino Del Regno wrote:

> Il 03/06/24 14:06, Julien Panis ha scritto:
> > This patch prevents from registering thermal entries and letting the
> > driver misbehave if efuse data is invalid. A device is not properly
> > calibrated if the golden temperature is zero.
> > 
> > Signed-off-by: Julien Panis <jpanis@baylibre.com>
> 
> Fixes tag, please.

What should it refer to? This is arguably a robustness enhancement for a 
defficiency that has been there all along.


Nicolas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] thermal/drivers/mediatek/lvts_thermal: Return error in case of invalid efuse data
  2024-06-04 16:33   ` Nicolas Pitre
@ 2024-06-05 10:33     ` AngeloGioacchino Del Regno
  0 siblings, 0 replies; 6+ messages in thread
From: AngeloGioacchino Del Regno @ 2024-06-05 10:33 UTC (permalink / raw)
  To: Nicolas Pitre
  Cc: Julien Panis, Rafael J. Wysocki, Daniel Lezcano, Zhang Rui,
	Lukasz Luba, Matthias Brugger, linux-pm, linux-kernel,
	linux-arm-kernel, linux-mediatek

Il 04/06/24 18:33, Nicolas Pitre ha scritto:
> On Tue, 4 Jun 2024, AngeloGioacchino Del Regno wrote:
> 
>> Il 03/06/24 14:06, Julien Panis ha scritto:
>>> This patch prevents from registering thermal entries and letting the
>>> driver misbehave if efuse data is invalid. A device is not properly
>>> calibrated if the golden temperature is zero.
>>>
>>> Signed-off-by: Julien Panis <jpanis@baylibre.com>
>>
>> Fixes tag, please.
> 
> What should it refer to? This is arguably a robustness enhancement for a
> defficiency that has been there all along.
> 
> 

If that's been there since day 1, the fixes tag should be the day 1 commit,
of course.

I see that as an important bugfix and not just a robustness enhancement, as
SoCs with uncalibrated LVTS would *not work*, as the kernel would shut down
the system before even loading the userspace.

Regards,
Angelo


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-06-05 10:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-03 12:06 [PATCH] thermal/drivers/mediatek/lvts_thermal: Return error in case of invalid efuse data Julien Panis
2024-06-04 16:19 ` Nicolas Pitre
2024-06-04 16:26 ` Daniel Lezcano
2024-06-04 16:29 ` AngeloGioacchino Del Regno
2024-06-04 16:33   ` Nicolas Pitre
2024-06-05 10:33     ` AngeloGioacchino Del Regno

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox