Skip to contentSkip to conversation

ACPI : dock: add error handling for acpi_bus_get_device

PATCH In review Zhouyang Jia 2 participants 2 messages Jun 12, 2018 – Jun 14, 2018 ACPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPI : dock: add error handling for acpi_bus_get_device

When acpi_bus_get_device fails, the lack of error-handling code may cause unexpected results.

This patch adds error-handling code after calling acpi_bus_get_device.

---
 drivers/acpi/dock.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/dock.c +3 -1
index e3fc1f0..02fc134 100644
@@ -504,7 +504,9 @@ static ssize_t show_docked(struct device *dev,
 	struct dock_station *dock_station = dev->platform_data;
 	struct acpi_device *adev = NULL;
 
-	acpi_bus_get_device(dock_station->handle, &adev);
+	if (acpi_bus_get_device(dock_station->handle, &adev))
+		return -ENODEV;
+
 	return snprintf(buf, PAGE_SIZE, "%u\n", acpi_device_enumerated(adev));
 }
 static DEVICE_ATTR(docked, S_IRUGO, show_docked, NULL);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 2 lines · Zhouyang Jia

When acpi_bus_get_device fails, the lack of error-handling code may cause unexpected results.

It is perfectly predictable in this particular case: adev will be NULL and acpi_device_enumerated(adev) will return false.

Quoted 1 line

This patch adds error-handling code after calling acpi_bus_get_device.

Which is not necessary.

Thanks,
Rafael