diff mbox series

ACPI: thermal: Fix a small leak in acpi_thermal_add()

Message ID 37eb30ba-1dc9-42e7-a22e-af44f6270e67@moroto.mountain (mailing list archive)
State Mainlined, archived
Headers show
Series ACPI: thermal: Fix a small leak in acpi_thermal_add() | expand

Commit Message

Dan Carpenter Sept. 27, 2023, 12:37 p.m. UTC
Free "tz" if the "trip" allocation fails.

Fixes: 5fc2189f9335 ("ACPI: thermal: Create and populate trip points table earlier")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
 drivers/acpi/thermal.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Rafael J. Wysocki Sept. 27, 2023, 1 p.m. UTC | #1
On Wed, Sep 27, 2023 at 2:37 PM Dan Carpenter <dan.carpenter@linaro.org> wrote:
>
> Free "tz" if the "trip" allocation fails.
>
> Fixes: 5fc2189f9335 ("ACPI: thermal: Create and populate trip points table earlier")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
>  drivers/acpi/thermal.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
> index 10720a038846..f8a95939c88d 100644
> --- a/drivers/acpi/thermal.c
> +++ b/drivers/acpi/thermal.c
> @@ -928,8 +928,10 @@ static int acpi_thermal_add(struct acpi_device *device)
>         acpi_thermal_guess_offset(tz, crit_temp);
>
>         trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL);
> -       if (!trip)
> -               return -ENOMEM;
> +       if (!trip) {
> +               result = -ENOMEM;
> +               goto free_memory;
> +       }
>
>         tz->trip_table = trip;
>
> --

Applied, thanks!
diff mbox series

Patch

diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 10720a038846..f8a95939c88d 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -928,8 +928,10 @@  static int acpi_thermal_add(struct acpi_device *device)
 	acpi_thermal_guess_offset(tz, crit_temp);
 
 	trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL);
-	if (!trip)
-		return -ENOMEM;
+	if (!trip) {
+		result = -ENOMEM;
+		goto free_memory;
+	}
 
 	tz->trip_table = trip;