[PATCH RFT/RFC 1/2] gpiolib: support "undefined" GPIO machine lookup

From: Bartosz Golaszewski

Date: Wed Nov 19 2025 - 10:21:53 EST


From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>

SPI devices can specify a cs-gpios property to enumerate their chip
selects. In device tree, a zero entry in this property can be used to
specify that a particular chip select is using the SPI controllers
native chip select, for example:

cs-gpios = <&gpio1 0 0>, <0>;

Here, the second chip select is native. Allow users to pass
ERR_PTR(-ENOENT) as the key field in struct gpiod_lookup, indicating a
native chip select.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
---
drivers/gpio/gpiolib.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 91e0c384f34ae5c0ed61ccd3a978685d4f72e867..dbb5f7fe7b661979f559fcd32ad6e1c463431a18 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -4557,6 +4557,9 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
if (p->con_id && (!con_id || strcmp(p->con_id, con_id)))
continue;

+ if (p->key == PTR_ERR(-ENOENT))
+ return ERR_PTR(-ENOENT);
+
if (p->chip_hwnum == U16_MAX) {
desc = gpio_name_to_desc(p->key);
if (desc) {

--
2.51.0