public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] tools/thermal: Fix common realloc mistake
@ 2024-11-14  8:40 zhangjiao2
  2024-11-14 17:46 ` Daniel Lezcano
  0 siblings, 1 reply; 2+ messages in thread
From: zhangjiao2 @ 2024-11-14  8:40 UTC (permalink / raw)
  To: daniel.lezcano; +Cc: rafael, linux-pm, linux-kernel, zhang jiao

From: zhang jiao <zhangjiao2@cmss.chinamobile.com>

If the 'realloc' fails, the thermal zones pointer is set to NULL. This
makes all thermal zones references which were previously successfully
initialized to be lost.

Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
---
v1->v2:
	Modify commit info and use right type.

 tools/thermal/thermometer/thermometer.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/thermal/thermometer/thermometer.c b/tools/thermal/thermometer/thermometer.c
index 1a87a0a77f9f..6df6ffdc571a 100644
--- a/tools/thermal/thermometer/thermometer.c
+++ b/tools/thermal/thermometer/thermometer.c
@@ -259,6 +259,7 @@ static int thermometer_add_tz(const char *path, const char *name, int polling,
 {
 	int fd;
 	char tz_path[PATH_MAX];
+	struct tz *tz;
 
 	sprintf(tz_path, CLASS_THERMAL"/%s/temp", path);
 
@@ -268,12 +269,13 @@ static int thermometer_add_tz(const char *path, const char *name, int polling,
 		return -1;
 	}
 
-	thermometer->tz = realloc(thermometer->tz,
+	tz = realloc(thermometer->tz,
 				  sizeof(*thermometer->tz) * (thermometer->nr_tz + 1));
-	if (!thermometer->tz) {
+	if (!tz) {
 		ERROR("Failed to allocate thermometer->tz\n");
 		return -1;
 	}
+	thermometer->tz = tz;
 
 	thermometer->tz[thermometer->nr_tz].fd_temp = fd;
 	thermometer->tz[thermometer->nr_tz].name = strdup(name);
-- 
2.33.0




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

* Re: [PATCH v2] tools/thermal: Fix common realloc mistake
  2024-11-14  8:40 [PATCH v2] tools/thermal: Fix common realloc mistake zhangjiao2
@ 2024-11-14 17:46 ` Daniel Lezcano
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Lezcano @ 2024-11-14 17:46 UTC (permalink / raw)
  To: zhangjiao2; +Cc: rafael, linux-pm, linux-kernel

On 14/11/2024 09:40, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> 
> If the 'realloc' fails, the thermal zones pointer is set to NULL. This
> makes all thermal zones references which were previously successfully
> initialized to be lost.
> 
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.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] 2+ messages in thread

end of thread, other threads:[~2024-11-14 17:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-14  8:40 [PATCH v2] tools/thermal: Fix common realloc mistake zhangjiao2
2024-11-14 17:46 ` Daniel Lezcano

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