Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH] thermal/drivers/sun8i: Free calibration nvmem after reading it
@ 2023-07-19  0:58 Mark Brown
  2023-07-19 19:56 ` Jernej Škrabec
  2023-08-16  8:52 ` Daniel Lezcano
  0 siblings, 2 replies; 3+ messages in thread
From: Mark Brown @ 2023-07-19  0:58 UTC (permalink / raw)
  To: Vasily Khoruzhick, Yangtao Li, Rafael J. Wysocki, Daniel Lezcano,
	Amit Kucheria, Zhang Rui, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland
  Cc: linux-pm, linux-arm-kernel, linux-sunxi, linux-kernel, Mark Brown

The sun8i thermal driver reads calibration data via the nvmem API at
startup, updating the device configuration and not referencing the data
again.  Rather than explicitly freeing the nvmem data the driver relies
on devm_ to release it, even though the data is never referenced again.
The allocation is still tracked so it's not leaked but this is notable
when looking at the code and is a little wasteful so let's instead
explicitly free the nvmem after we're done with it.

Signed-off-by: Mark Brown <broonie@kernel.org>
---
 drivers/thermal/sun8i_thermal.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c
index 195f3c5d0b38..af3098717e3c 100644
--- a/drivers/thermal/sun8i_thermal.c
+++ b/drivers/thermal/sun8i_thermal.c
@@ -286,7 +286,7 @@ static int sun8i_ths_calibrate(struct ths_device *tmdev)
 	size_t callen;
 	int ret = 0;
 
-	calcell = devm_nvmem_cell_get(dev, "calibration");
+	calcell = nvmem_cell_get(dev, "calibration");
 	if (IS_ERR(calcell)) {
 		if (PTR_ERR(calcell) == -EPROBE_DEFER)
 			return -EPROBE_DEFER;
@@ -316,6 +316,8 @@ static int sun8i_ths_calibrate(struct ths_device *tmdev)
 
 	kfree(caldata);
 out:
+	if (!IS_ERR(calcell))
+		nvmem_cell_put(calcell);
 	return ret;
 }
 

---
base-commit: fdf0eaf11452d72945af31804e2a1048ee1b574c
change-id: 20230718-thermal-sun8i-free-nvmem-3e9e21306e3e

Best regards,
-- 
Mark Brown <broonie@kernel.org>


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

* Re: [PATCH] thermal/drivers/sun8i: Free calibration nvmem after reading it
  2023-07-19  0:58 [PATCH] thermal/drivers/sun8i: Free calibration nvmem after reading it Mark Brown
@ 2023-07-19 19:56 ` Jernej Škrabec
  2023-08-16  8:52 ` Daniel Lezcano
  1 sibling, 0 replies; 3+ messages in thread
From: Jernej Škrabec @ 2023-07-19 19:56 UTC (permalink / raw)
  To: Vasily Khoruzhick, Yangtao Li, Rafael J. Wysocki, Daniel Lezcano,
	Amit Kucheria, Zhang Rui, Chen-Yu Tsai, Samuel Holland,
	Mark Brown
  Cc: linux-pm, linux-arm-kernel, linux-sunxi, linux-kernel, Mark Brown

Dne sreda, 19. julij 2023 ob 02:58:54 CEST je Mark Brown napisal(a):
> The sun8i thermal driver reads calibration data via the nvmem API at
> startup, updating the device configuration and not referencing the data
> again.  Rather than explicitly freeing the nvmem data the driver relies
> on devm_ to release it, even though the data is never referenced again.
> The allocation is still tracked so it's not leaked but this is notable
> when looking at the code and is a little wasteful so let's instead
> explicitly free the nvmem after we're done with it.
> 
> Signed-off-by: Mark Brown <broonie@kernel.org>

Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Best regards,
Jernej

> ---
>  drivers/thermal/sun8i_thermal.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/sun8i_thermal.c
> b/drivers/thermal/sun8i_thermal.c index 195f3c5d0b38..af3098717e3c 100644
> --- a/drivers/thermal/sun8i_thermal.c
> +++ b/drivers/thermal/sun8i_thermal.c
> @@ -286,7 +286,7 @@ static int sun8i_ths_calibrate(struct ths_device *tmdev)
> size_t callen;
>  	int ret = 0;
> 
> -	calcell = devm_nvmem_cell_get(dev, "calibration");
> +	calcell = nvmem_cell_get(dev, "calibration");
>  	if (IS_ERR(calcell)) {
>  		if (PTR_ERR(calcell) == -EPROBE_DEFER)
>  			return -EPROBE_DEFER;
> @@ -316,6 +316,8 @@ static int sun8i_ths_calibrate(struct ths_device *tmdev)
> 
>  	kfree(caldata);
>  out:
> +	if (!IS_ERR(calcell))
> +		nvmem_cell_put(calcell);
>  	return ret;
>  }
> 
> 
> ---
> base-commit: fdf0eaf11452d72945af31804e2a1048ee1b574c
> change-id: 20230718-thermal-sun8i-free-nvmem-3e9e21306e3e
> 
> Best regards,





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

* Re: [PATCH] thermal/drivers/sun8i: Free calibration nvmem after reading it
  2023-07-19  0:58 [PATCH] thermal/drivers/sun8i: Free calibration nvmem after reading it Mark Brown
  2023-07-19 19:56 ` Jernej Škrabec
@ 2023-08-16  8:52 ` Daniel Lezcano
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Lezcano @ 2023-08-16  8:52 UTC (permalink / raw)
  To: Mark Brown, Vasily Khoruzhick, Yangtao Li, Rafael J. Wysocki,
	Amit Kucheria, Zhang Rui, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland
  Cc: linux-pm, linux-arm-kernel, linux-sunxi, linux-kernel

On 19/07/2023 02:58, Mark Brown wrote:
> The sun8i thermal driver reads calibration data via the nvmem API at
> startup, updating the device configuration and not referencing the data
> again.  Rather than explicitly freeing the nvmem data the driver relies
> on devm_ to release it, even though the data is never referenced again.
> The allocation is still tracked so it's not leaked but this is notable
> when looking at the code and is a little wasteful so let's instead
> explicitly free the nvmem after we're done with it.
> 
> Signed-off-by: Mark Brown <broonie@kernel.org>

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] 3+ messages in thread

end of thread, other threads:[~2023-08-16  8:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-19  0:58 [PATCH] thermal/drivers/sun8i: Free calibration nvmem after reading it Mark Brown
2023-07-19 19:56 ` Jernej Škrabec
2023-08-16  8:52 ` Daniel Lezcano

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