diff options
author | 2024-11-14 16:40:39 +0800 | |
---|---|---|
committer | 2024-11-15 14:29:03 +0100 | |
commit | d303e3dd8d4648f2a1bb19944d4fb1c4a5030354 (patch) | |
tree | 05708051cf645f2e64f5dc7242899254efd41a2f | |
parent | thermal/drivers/k3_j72xx_bandgap: Simplify code in k3_bgp_read_temp() (diff) | |
download | wireguard-linux-d303e3dd8d4648f2a1bb19944d4fb1c4a5030354.tar.xz wireguard-linux-d303e3dd8d4648f2a1bb19944d4fb1c4a5030354.zip |
tools/thermal: Fix common realloc mistake
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.
[dlezcano] : Fixed indentation
Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
Link: https://lore.kernel.org/r/20241114084039.42149-1-zhangjiao2@cmss.chinamobile.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Diffstat (limited to '')
-rw-r--r-- | tools/thermal/thermometer/thermometer.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/tools/thermal/thermometer/thermometer.c b/tools/thermal/thermometer/thermometer.c index 1a87a0a77f9f..022865da8e3c 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,13 +269,13 @@ static int thermometer_add_tz(const char *path, const char *name, int polling, return -1; } - thermometer->tz = realloc(thermometer->tz, - sizeof(*thermometer->tz) * (thermometer->nr_tz + 1)); - if (!thermometer->tz) { + tz = realloc(thermometer->tz, sizeof(*thermometer->tz) * (thermometer->nr_tz + 1)); + 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); thermometer->tz[thermometer->nr_tz].polling = polling; |