Skip to content

Commit cb0451e

Browse files
author
Bartosz Golaszewski
committed
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: a060b8c ("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>
1 parent 9700b0f commit cb0451e

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

drivers/gpio/gpiolib-shared.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ static bool gpio_shared_dev_is_reset_gpio(struct device *consumer,
365365
}
366366
#endif /* CONFIG_RESET_GPIO */
367367

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)
369370
{
370371
const char *dev_id = dev_name(consumer);
371372
struct gpio_shared_entry *entry;
@@ -384,6 +385,10 @@ int gpio_shared_add_proxy_lookup(struct device *consumer, unsigned long lflags)
384385

385386
guard(mutex)(&ref->lock);
386387

388+
if ((!con_id && ref->con_id) || (con_id && !ref->con_id) ||
389+
(con_id && ref->con_id && strcmp(con_id, ref->con_id) != 0))
390+
continue;
391+
387392
/* We've already done that on a previous request. */
388393
if (ref->lookup)
389394
return 0;

drivers/gpio/gpiolib-shared.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ struct device;
1616

1717
int gpio_device_setup_shared(struct gpio_device *gdev);
1818
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);
2021

2122
#else
2223

@@ -28,6 +29,7 @@ static inline int gpio_device_setup_shared(struct gpio_device *gdev)
2829
static inline void gpio_device_teardown_shared(struct gpio_device *gdev) { }
2930

3031
static inline int gpio_shared_add_proxy_lookup(struct device *consumer,
32+
const char *con_id,
3133
unsigned long lflags)
3234
{
3335
return 0;

drivers/gpio/gpiolib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4717,7 +4717,8 @@ struct gpio_desc *gpiod_find_and_request(struct device *consumer,
47174717
* lookup table for the proxy device as previously
47184718
* we only knew the consumer's fwnode.
47194719
*/
4720-
ret = gpio_shared_add_proxy_lookup(consumer, lookupflags);
4720+
ret = gpio_shared_add_proxy_lookup(consumer, con_id,
4721+
lookupflags);
47214722
if (ret)
47224723
return ERR_PTR(ret);
47234724

0 commit comments

Comments
 (0)