Skip to contentSkip to conversation

ACPI / PM: Fix error code path for power resources initialization

PATCH In review Rafael J. Wysocki 3 participants 3 messages Jun 17, 2013 – Jun 19, 2013 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI / PM: Fix error code path for power resources initialization

From: Rafael J. Wysocki <[email protected]>

Commit 781d737 (ACPI: Drop power resources driver) introduced a bug in the power resources initialization error code path causing a NULL pointer to be referenced in acpi_release_power_resource() if there's an error triggering a jump to the 'err' label in acpi_add_power_resource(). This happens because the list_node field of struct acpi_power_resource has not been initialized yet at this point and doing a list_del() on it is a bad idea.

To prevent this problem from occuring, initialize the list_node field of struct acpi_power_resource upfront.

---
 drivers/acpi/power.c |    1 +
 1 file changed, 1 insertion(+)
drivers/acpi/power.c +1 -0
Index: linux-pm/drivers/acpi/power.c
===================================================================
@@ -882,6 +882,7 @@ int acpi_add_power_resource(acpi_handle
 				ACPI_STA_DEFAULT);
 	mutex_init(&resource->resource_lock);
 	INIT_LIST_HEAD(&resource->dependent);
+	INIT_LIST_HEAD(&resource->list_node);
 	resource->name = device->pnp.bus_id;
 	strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
 	strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Commit 781d737 (ACPI: Drop power resources driver) introduced a bug in the power resources initialization error code path causing a NULL pointer to be referenced in acpi_release_power_resource() if there's an error triggering a jump to the 'err' label in acpi_add_power_resource(). This happens because the list_node field of struct acpi_power_resource has not been initialized yet at this point and doing a list_del() on it is a bad idea.

Quoted 6 lines

To prevent this problem from occuring, initialize the list_node field of struct acpi_power_resource upfront.

Thanks,
Yasuaki Ishimatsu

Quoted 22 lines
---
  drivers/acpi/power.c |    1 +
  1 file changed, 1 insertion(+)

Index: linux-pm/drivers/acpi/power.c
===================================================================

drivers/acpi/power.c +1 -1
@@ -882,6 +882,7 @@ int acpi_add_power_resource(acpi_handle
  				ACPI_STA_DEFAULT);
  	mutex_init(&resource->resource_lock);
  	INIT_LIST_HEAD(&resource->dependent);
+	INIT_LIST_HEAD(&resource->list_node);
  	resource->name = device->pnp.bus_id;
  	strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
  	strcpy(acpi_device_class(device), ACPI_POWER_CLASS);
 
--

To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Reviewed-by on v1 1/1
#2 lore raw
In reply to Rafael J. Wysocki
Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Commit 781d737 (ACPI: Drop power resources driver) introduced a bug in the power resources initialization error code path causing a NULL pointer to be referenced in acpi_release_power_resource() if there's an error triggering a jump to the 'err' label in acpi_add_power_resource(). This happens because the list_node field of struct acpi_power_resource has not been initialized yet at this point and doing a list_del() on it is a bad idea.

Quoted 4 lines

To prevent this problem from occuring, initialize the list_node field of struct acpi_power_resource upfront.

Quoted 18 lines
---
 drivers/acpi/power.c |    1 +
 1 file changed, 1 insertion(+)

Index: linux-pm/drivers/acpi/power.c
===================================================================

drivers/acpi/power.c +1 -0
@@ -882,6 +882,7 @@ int acpi_add_power_resource(acpi_handle
 				ACPI_STA_DEFAULT);
 	mutex_init(&resource->resource_lock);
 	INIT_LIST_HEAD(&resource->dependent);
+	INIT_LIST_HEAD(&resource->list_node);
 	resource->name = device->pnp.bus_id;
 	strcpy(acpi_device_name(device), ACPI_POWER_DEVICE_NAME);
 	strcpy(acpi_device_class(device), ACPI_POWER_CLASS);