* [PATCH] tools/thermal/thermometer: close fd on realloc failure
@ 2026-06-20 7:41 amarjeet
2026-06-20 12:26 ` [PATCH v2] " amarjeet
0 siblings, 1 reply; 3+ messages in thread
From: amarjeet @ 2026-06-20 7:41 UTC (permalink / raw)
To: Rafael J . Wysocki, Daniel Lezcano
Cc: Zhang Rui, Lukasz Luba, linux-pm, linux-kernel
From: Amarjeet <amarjeet@intel.com>
thermometer_add_tz() opens tz_path and then reallocates thermometer->tz.
If realloc fails, the function returns without closing fd.
Close fd before returning on realloc failure to avoid leaking a file descriptor.
Signed-off-by: Amarjeet <amarjeet@intel.com>
---
tools/thermal/thermometer/thermometer.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/thermal/thermometer/thermometer.c b/tools/thermal/thermometer/thermometer.c
index 022865da8e3c..103db7a2a8e4 100644
--- a/tools/thermal/thermometer/thermometer.c
+++ b/tools/thermal/thermometer/thermometer.c
@@ -266,6 +266,7 @@ static int thermometer_add_tz(const char *path, const char *name, int polling,
fd = open(tz_path, O_RDONLY);
if (fd < 0) {
ERROR("Failed to open '%s': %m\n", tz_path);
+ close(fd);
return -1;
}
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2] tools/thermal/thermometer: close fd on realloc failure
2026-06-20 7:41 [PATCH] tools/thermal/thermometer: close fd on realloc failure amarjeet
@ 2026-06-20 12:26 ` amarjeet
2026-07-22 15:44 ` Rafael J. Wysocki (Intel)
0 siblings, 1 reply; 3+ messages in thread
From: amarjeet @ 2026-06-20 12:26 UTC (permalink / raw)
To: Rafael J . Wysocki, Daniel Lezcano
Cc: Zhang Rui, Lukasz Luba, linux-pm, linux-kernel
From: Amarjeet <amarjeet@intel.com>
thermometer_add_tz() opens tz_path and then reallocates thermometer->tz.
If realloc fails, the function returns without closing fd.
Close fd before returning on realloc failure to avoid leaking a file descriptor.
Signed-off-by: Amarjeet <amarjeet@intel.com>
---
v2:
- drop close(fd) on open() failure path
- keep close(fd) only on realloc failure path
---
tools/thermal/thermometer/thermometer.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/thermal/thermometer/thermometer.c b/tools/thermal/thermometer/thermometer.c
index 022865da8e3c..1ae6c3ecedb4 100644
--- a/tools/thermal/thermometer/thermometer.c
+++ b/tools/thermal/thermometer/thermometer.c
@@ -272,6 +272,7 @@ static int thermometer_add_tz(const char *path, const char *name, int polling,
tz = realloc(thermometer->tz, sizeof(*thermometer->tz) * (thermometer->nr_tz + 1));
if (!tz) {
ERROR("Failed to allocate thermometer->tz\n");
+ close(fd);
return -1;
}
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] tools/thermal/thermometer: close fd on realloc failure
2026-06-20 12:26 ` [PATCH v2] " amarjeet
@ 2026-07-22 15:44 ` Rafael J. Wysocki (Intel)
0 siblings, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-07-22 15:44 UTC (permalink / raw)
To: amarjeet
Cc: Rafael J . Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
linux-pm, linux-kernel
On Sat, Jun 20, 2026 at 2:27 PM <amarjeet@intel.com> wrote:
>
> From: Amarjeet <amarjeet@intel.com>
>
> thermometer_add_tz() opens tz_path and then reallocates thermometer->tz.
> If realloc fails, the function returns without closing fd.
>
> Close fd before returning on realloc failure to avoid leaking a file descriptor.
>
> Signed-off-by: Amarjeet <amarjeet@intel.com>
>
> ---
> v2:
> - drop close(fd) on open() failure path
> - keep close(fd) only on realloc failure path
> ---
> tools/thermal/thermometer/thermometer.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/thermal/thermometer/thermometer.c b/tools/thermal/thermometer/thermometer.c
> index 022865da8e3c..1ae6c3ecedb4 100644
> --- a/tools/thermal/thermometer/thermometer.c
> +++ b/tools/thermal/thermometer/thermometer.c
> @@ -272,6 +272,7 @@ static int thermometer_add_tz(const char *path, const char *name, int polling,
> tz = realloc(thermometer->tz, sizeof(*thermometer->tz) * (thermometer->nr_tz + 1));
> if (!tz) {
> ERROR("Failed to allocate thermometer->tz\n");
> + close(fd);
> return -1;
> }
>
> --
Applied as 7.3 material, thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-07-22 15:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-20 7:41 [PATCH] tools/thermal/thermometer: close fd on realloc failure amarjeet
2026-06-20 12:26 ` [PATCH v2] " amarjeet
2026-07-22 15:44 ` Rafael J. Wysocki (Intel)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®