Skip to content

Commit d303e3d

Browse files
zhang jiaodlezcano
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Lezcano <[email protected]>
1 parent d8afb8c commit d303e3d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

tools/thermal/thermometer/thermometer.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ static int thermometer_add_tz(const char *path, const char *name, int polling,
259259
{
260260
int fd;
261261
char tz_path[PATH_MAX];
262+
struct tz *tz;
262263

263264
sprintf(tz_path, CLASS_THERMAL"/%s/temp", path);
264265

@@ -268,13 +269,13 @@ static int thermometer_add_tz(const char *path, const char *name, int polling,
268269
return -1;
269270
}
270271

271-
thermometer->tz = realloc(thermometer->tz,
272-
sizeof(*thermometer->tz) * (thermometer->nr_tz + 1));
273-
if (!thermometer->tz) {
272+
tz = realloc(thermometer->tz, sizeof(*thermometer->tz) * (thermometer->nr_tz + 1));
273+
if (!tz) {
274274
ERROR("Failed to allocate thermometer->tz\n");
275275
return -1;
276276
}
277277

278+
thermometer->tz = tz;
278279
thermometer->tz[thermometer->nr_tz].fd_temp = fd;
279280
thermometer->tz[thermometer->nr_tz].name = strdup(name);
280281
thermometer->tz[thermometer->nr_tz].polling = polling;

0 commit comments

Comments
 (0)