Skip to content

Commit 3b14403

Browse files
committed
Merge tag 'intel-gpio-v6.10-2' of git://git.kernel.org/pub/scm/linux/kernel/git/andy/linux-gpio-intel
Pull intel-gpio fixes from Andy Shevchenko: - NULL pointer dereference fix in GPIO APCI library - Restore ACPI handle matching for GPIO devices represented in banks * tag 'intel-gpio-v6.10-2' of git://git.kernel.org/pub/scm/linux/kernel/git/andy/linux-gpio-intel: gpiolib: acpi: Fix failed in acpi_gpiochip_find() by adding parent node match gpiolib: acpi: Move ACPI device NULL check to acpi_can_fallback_to_crs()
2 parents b9dd56e + adbc49a commit 3b14403

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

drivers/gpio/gpiolib-acpi.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,24 @@ static bool acpi_gpio_deferred_req_irqs_done;
128128

129129
static int acpi_gpiochip_find(struct gpio_chip *gc, const void *data)
130130
{
131-
return device_match_acpi_handle(&gc->gpiodev->dev, data);
131+
/* First check the actual GPIO device */
132+
if (device_match_acpi_handle(&gc->gpiodev->dev, data))
133+
return true;
134+
135+
/*
136+
* When the ACPI device is artificially split to the banks of GPIOs,
137+
* where each of them is represented by a separate GPIO device,
138+
* the firmware node of the physical device may not be shared among
139+
* the banks as they may require different values for the same property,
140+
* e.g., number of GPIOs in a certain bank. In such case the ACPI handle
141+
* of a GPIO device is NULL and can not be used. Hence we have to check
142+
* the parent device to be sure that there is no match before bailing
143+
* out.
144+
*/
145+
if (gc->parent)
146+
return device_match_acpi_handle(gc->parent, data);
147+
148+
return false;
132149
}
133150

134151
/**
@@ -938,6 +955,10 @@ static struct gpio_desc *acpi_get_gpiod_from_data(struct fwnode_handle *fwnode,
938955
static bool acpi_can_fallback_to_crs(struct acpi_device *adev,
939956
const char *con_id)
940957
{
958+
/* If there is no ACPI device, there is no _CRS to fall back to */
959+
if (!adev)
960+
return false;
961+
941962
/* Never allow fallback if the device has properties */
942963
if (acpi_dev_has_props(adev) || adev->driver_gpios)
943964
return false;
@@ -978,10 +999,10 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int
978999
}
9791000

9801001
/* Then from plain _CRS GPIOs */
981-
if (!adev || !can_fallback)
982-
return ERR_PTR(-ENOENT);
1002+
if (can_fallback)
1003+
return acpi_get_gpiod_by_index(adev, NULL, idx, info);
9831004

984-
return acpi_get_gpiod_by_index(adev, NULL, idx, info);
1005+
return ERR_PTR(-ENOENT);
9851006
}
9861007

9871008
struct gpio_desc *acpi_find_gpio(struct fwnode_handle *fwnode,

0 commit comments

Comments
 (0)