Skip to content

Commit 47ec9b4

Browse files
jic23ctmarinas
authored andcommitted
ACPI: processor: Fix memory leaks in error paths of processor_add()
If acpi_processor_get_info() returned an error, pr and the associated pr->throttling.shared_cpu_map were leaked. The unwind code was in the wrong order wrt to setup, relying on some unwind actions having no affect (clearing variables that were never set etc). That makes it harder to reason about so reorder and add appropriate labels to only undo what was actually set up in the first place. Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Gavin Shan <gshan@redhat.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://lore.kernel.org/r/20240529133446.28446-6-Jonathan.Cameron@huawei.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent fadf231 commit 47ec9b4

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

drivers/acpi/acpi_processor.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static int acpi_processor_add(struct acpi_device *device,
393393

394394
result = acpi_processor_get_info(device);
395395
if (result) /* Processor is not physically present or unavailable */
396-
return result;
396+
goto err_clear_driver_data;
397397

398398
BUG_ON(pr->id >= nr_cpu_ids);
399399

@@ -408,7 +408,7 @@ static int acpi_processor_add(struct acpi_device *device,
408408
"BIOS reported wrong ACPI id %d for the processor\n",
409409
pr->id);
410410
/* Give up, but do not abort the namespace scan. */
411-
goto err;
411+
goto err_clear_driver_data;
412412
}
413413
/*
414414
* processor_device_array is not cleared on errors to allow buggy BIOS
@@ -420,12 +420,12 @@ static int acpi_processor_add(struct acpi_device *device,
420420
dev = get_cpu_device(pr->id);
421421
if (!dev) {
422422
result = -ENODEV;
423-
goto err;
423+
goto err_clear_per_cpu;
424424
}
425425

426426
result = acpi_bind_one(dev, device);
427427
if (result)
428-
goto err;
428+
goto err_clear_per_cpu;
429429

430430
pr->dev = dev;
431431

@@ -436,10 +436,11 @@ static int acpi_processor_add(struct acpi_device *device,
436436
dev_err(dev, "Processor driver could not be attached\n");
437437
acpi_unbind_one(dev);
438438

439-
err:
440-
free_cpumask_var(pr->throttling.shared_cpu_map);
441-
device->driver_data = NULL;
439+
err_clear_per_cpu:
442440
per_cpu(processors, pr->id) = NULL;
441+
err_clear_driver_data:
442+
device->driver_data = NULL;
443+
free_cpumask_var(pr->throttling.shared_cpu_map);
443444
err_free_pr:
444445
kfree(pr);
445446
return result;

0 commit comments

Comments
 (0)