Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: shared: verify con_id when adding proxy lookup

When matching the firmware node with the potential consumer, we
currently omit the con_id string. This can lead to false positives in
the unlikely case of the consumer having been assigned more than one
shared GPIO. Check the connector ID before proceeding.

Fixes: a060b8c511ab ("gpiolib: implement low-level, shared GPIO support")
Link: https://lore.kernel.org/r/20251222-gpio-shared-reset-gpio-proxy-v1-2-8d4bba7d8c14@oss.qualcomm.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

+11 -3
+6 -1
drivers/gpio/gpiolib-shared.c
··· 365 365 } 366 366 #endif /* CONFIG_RESET_GPIO */ 367 367 368 - int gpio_shared_add_proxy_lookup(struct device *consumer, unsigned long lflags) 368 + int gpio_shared_add_proxy_lookup(struct device *consumer, const char *con_id, 369 + unsigned long lflags) 369 370 { 370 371 const char *dev_id = dev_name(consumer); 371 372 struct gpio_shared_entry *entry; ··· 384 383 continue; 385 384 386 385 guard(mutex)(&ref->lock); 386 + 387 + if ((!con_id && ref->con_id) || (con_id && !ref->con_id) || 388 + (con_id && ref->con_id && strcmp(con_id, ref->con_id) != 0)) 389 + continue; 387 390 388 391 /* We've already done that on a previous request. */ 389 392 if (ref->lookup)
+3 -1
drivers/gpio/gpiolib-shared.h
··· 16 16 17 17 int gpio_device_setup_shared(struct gpio_device *gdev); 18 18 void gpio_device_teardown_shared(struct gpio_device *gdev); 19 - int gpio_shared_add_proxy_lookup(struct device *consumer, unsigned long lflags); 19 + int gpio_shared_add_proxy_lookup(struct device *consumer, const char *con_id, 20 + unsigned long lflags); 20 21 21 22 #else 22 23 ··· 29 28 static inline void gpio_device_teardown_shared(struct gpio_device *gdev) { } 30 29 31 30 static inline int gpio_shared_add_proxy_lookup(struct device *consumer, 31 + const char *con_id, 32 32 unsigned long lflags) 33 33 { 34 34 return 0;
+2 -1
drivers/gpio/gpiolib.c
··· 4717 4717 * lookup table for the proxy device as previously 4718 4718 * we only knew the consumer's fwnode. 4719 4719 */ 4720 - ret = gpio_shared_add_proxy_lookup(consumer, lookupflags); 4720 + ret = gpio_shared_add_proxy_lookup(consumer, con_id, 4721 + lookupflags); 4721 4722 if (ret) 4722 4723 return ERR_PTR(ret); 4723 4724