mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-15 21:23:23 +00:00
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>
This commit is contained in:
parent
d8afb8cc8b
commit
d303e3dd8d
@ -259,6 +259,7 @@ static int thermometer_add_tz(const char *path, const char *name, int polling,
|
|||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
char tz_path[PATH_MAX];
|
char tz_path[PATH_MAX];
|
||||||
|
struct tz *tz;
|
||||||
|
|
||||||
sprintf(tz_path, CLASS_THERMAL"/%s/temp", path);
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
thermometer->tz = realloc(thermometer->tz,
|
tz = realloc(thermometer->tz, sizeof(*thermometer->tz) * (thermometer->nr_tz + 1));
|
||||||
sizeof(*thermometer->tz) * (thermometer->nr_tz + 1));
|
if (!tz) {
|
||||||
if (!thermometer->tz) {
|
|
||||||
ERROR("Failed to allocate thermometer->tz\n");
|
ERROR("Failed to allocate thermometer->tz\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
thermometer->tz = tz;
|
||||||
thermometer->tz[thermometer->nr_tz].fd_temp = fd;
|
thermometer->tz[thermometer->nr_tz].fd_temp = fd;
|
||||||
thermometer->tz[thermometer->nr_tz].name = strdup(name);
|
thermometer->tz[thermometer->nr_tz].name = strdup(name);
|
||||||
thermometer->tz[thermometer->nr_tz].polling = polling;
|
thermometer->tz[thermometer->nr_tz].polling = polling;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user