Re: [PATCH] tpm: acpi: Fix memory leak at tpm_read_log_acpi() error path
From: Jarkko Sakkinen
Date: Mon Nov 09 2026 - 10:32:13 EST
On Mon, Nov 09, 2026 at 09:25:24AM +0100, Takashi Iwai wrote:
> When devm_add_action() returns an error, we do NULL-clear
> log->bios_event_log unnecessarily before calling tpm_bios_log_free(),
> and it would lead to a memory leak of the allocated log buffer.
I don't understand this. "NULL-clear" is gibberish when the actual
bug is just spurious clear of log->bios_event_log. Also we are not
doing anything we are not computers.
>
> Fix it by simply jumping to the err.
>
> Fixes: a3a860bc0fd6 ("tpm: Change to kvalloc() in eventlog/acpi.c")
> Cc: <stable@xxxxxxxxxxxxxxx>
Put Cc before fixes.
> Signed-off-by: Takashi Iwai <tiwai@xxxxxxx>
> ---
> drivers/char/tpm/eventlog/acpi.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/char/tpm/eventlog/acpi.c b/drivers/char/tpm/eventlog/acpi.c
> index cf02ec646f46..50770cafa835 100644
> --- a/drivers/char/tpm/eventlog/acpi.c
> +++ b/drivers/char/tpm/eventlog/acpi.c
> @@ -167,10 +167,8 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
> }
>
> ret = devm_add_action(&chip->dev, tpm_bios_log_free, log->bios_event_log);
> - if (ret) {
> - log->bios_event_log = NULL;
> + if (ret)
> goto err;
> - }
>
> return format;
>
> --
> 2.53.0
>
Br, Jarkko