Skip to contentSkip to conversation

driver core: location: Free struct acpi_pld_info *pld before return false

PATCH New Hanjun Guo 1 participant 1 message Nov 22, 2022 Driver core

lore
Share & tools
lore

Hanjun Guo

author
#0 lore raw

PATCH 1/1 driver core: location: Free struct acpi_pld_info *pld before return false

struct acpi_pld_info *pld should be freed before the return of allocation failure, to prevent memory leak, add the ACPI_FREE() to fix it.

Fixes bc443c31def5 ("driver core: location: Check for allocations failure")
---
 drivers/base/physical_location.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/base/physical_location.c +4 -1
index 87af641..951819e 100644
@@ -24,8 +24,11 @@ bool dev_add_physical_location(struct device *dev)
 
 	dev->physical_location =
 		kzalloc(sizeof(*dev->physical_location), GFP_KERNEL);
-	if (!dev->physical_location)
+	if (!dev->physical_location) {
+		ACPI_FREE(pld);
 		return false;
+	}
+
 	dev->physical_location->panel = pld->panel;
 	dev->physical_location->vertical_position = pld->vertical_position;
 	dev->physical_location->horizontal_position = pld->horizontal_position;
Signature · 1 line
1.7.12.4