Skip to contentSkip to conversation

platform/surface: surfacepro3_button: Check ACPI_COMPANION()

PATCH In review Rafael J. Wysocki 4 participants 5 messages May 12 – May 19

Subsystems (4)
lore
Share & tools
lore

Rafael J. Wysocki

author maintainer
#0 lore raw

PATCH 1/1 platform/surface: surfacepro3_button: Check ACPI_COMPANION()

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

Every platform driver can be forced to match a device that doesn't match its list of device IDs because of device_match_driver_override(), so platform drivers that rely on the existence of a device's ACPI companion object need to verify its presence.

Accordingly, add a requisite ACPI_COMPANION() check against NULL to the surfacepro3_button driver.

Fixes d913a5a12b40 ("platform/surface: surfacepro3_button: Convert to a platform driver")
---
 drivers/platform/surface/surfacepro3_button.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/platform/surface/surfacepro3_button.c +7 -3
@@ -185,12 +185,15 @@ static bool surface_button_check_MSHW004
 
 static int surface_button_probe(struct platform_device *pdev)
 {
-	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
 	struct surface_button *button;
+	struct acpi_device *device;
 	struct input_dev *input;
-	const char *hid = acpi_device_hid(device);
 	int error;
 
+	device = ACPI_COMPANION(&pdev->dev);
+	if (!device)
+		return -ENODEV;
+
 	if (strncmp(acpi_device_bid(device), SURFACE_BUTTON_OBJ_NAME,
 	    strlen(SURFACE_BUTTON_OBJ_NAME)))
 		return -ENODEV;
@@ -210,7 +213,8 @@ static int surface_button_probe(struct p
 	}
 
 	strscpy(acpi_device_name(device), SURFACE_BUTTON_DEVICE_NAME);
-	snprintf(button->phys, sizeof(button->phys), "%s/buttons", hid);
+	snprintf(button->phys, sizeof(button->phys), "%s/buttons",
+		 acpi_device_hid(device));
 
 	input->name = acpi_device_name(device);
 	input->phys = button->phys;
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Rafael J. Wysocki

Every platform driver can be forced to match a device that doesn't match its list of device IDs because of device_match_driver_override(), so platform drivers that rely on the existence of a device's ACPI companion object need to verify its presence.

Accordingly, add a requisite ACPI_COMPANION() check against NULL to the surfacepro3_button driver.

...

drivers/platform/surface/surfacepro3_button.c static int surface_button_probe(struct p · line 217

Quoted 4 lines
drivers/platform/surface/surfacepro3_button.c +2 -1
 	strscpy(acpi_device_name(device), SURFACE_BUTTON_DEVICE_NAME);
-	snprintf(button->phys, sizeof(button->phys), "%s/buttons", hid);
+	snprintf(button->phys, sizeof(button->phys), "%s/buttons",
+		 acpi_device_hid(device));

I'm wondering if some CIs will now generate a snprintf() warning (this was in the original code if the compiler can prove no truncation
of the string, though).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#2 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Rafael J. Wysocki

Every platform driver can be forced to match a device that doesn't match its list of device IDs because of device_match_driver_override(), so platform drivers that rely on the existence of a device's ACPI companion object need to verify its presence.

Quoted 4 lines
Quoted 2 lines

Accordingly, add a requisite ACPI_COMPANION() check against NULL to the surfacepro3_button driver.

Thanks!

Quoted 10 lines

...

drivers/platform/surface/surfacepro3_button.c static int surface_button_probe(struct p · line 217

Quoted 4 lines
      strscpy(acpi_device_name(device), SURFACE_BUTTON_DEVICE_NAME);
drivers/platform/surface/surfacepro3_button.c +2 -1
-     snprintf(button->phys, sizeof(button->phys), "%s/buttons", hid);
+     snprintf(button->phys, sizeof(button->phys), "%s/buttons",
+              acpi_device_hid(device));

I'm wondering if some CIs will now generate a snprintf() warning (this was in the original code if the compiler can prove no truncation
of the string, though).

Then I can send another patch to make that warning go away ...

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

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

Every platform driver can be forced to match a device that doesn't match its list of device IDs because of device_match_driver_override(), so platform drivers that rely on the existence of a device's ACPI companion object need to verify its presence.

Quoted 5 lines

Accordingly, add a requisite ACPI_COMPANION() check against NULL to the surfacepro3_button driver.

Fixes d913a5a12b40 ("platform/surface: surfacepro3_button: Convert to a platform driver")

Thanks for the fix, also learned that an override triggers a force attach.

thanks,
Chenyu

maintainer
#4 lore raw
In reply to Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki

Every platform driver can be forced to match a device that doesn't match its list of device IDs because of device_match_driver_override(), so platform drivers that rely on the existence of a device's ACPI companion object need to verify its presence.

Accordingly, add a requisite ACPI_COMPANION() check against NULL to the surfacepro3_button driver.

[...]

Thank you for your contribution, it has been applied to my local review-ilpo-fixes branch. Note it will show up in the public platform-drivers-x86/review-ilpo-fixes branch only once I've pushed my local branch there, which might take a while.

The list of commits applied:
[1/1] platform/surface: surfacepro3_button: Check ACPI_COMPANION()

      commit: 5798b46271e229dab05e47537ac30b76f81728da

--
i.