Skip to content

Commit c904a0d

Browse files
author
Bartosz Golaszewski
committed
gpio: shared: check if a reference is populated before cleaning its resources
It's possible that not all proxy entries will be set up when the device gets removed so check if they are before trying to dereference members which are still NULL. This can happen if some consumers never requested their shared GPIOs. Fixes: a060b8c ("gpiolib: implement low-level, shared GPIO support") Link: https://lore.kernel.org/r/20251206-gpio-shared-teardown-fixes-v1-2-35ac458cfce1@oss.qualcomm.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
1 parent e2c4175 commit c904a0d

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

drivers/gpio/gpiolib-shared.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,13 @@ void gpio_device_teardown_shared(struct gpio_device *gdev)
491491
continue;
492492

493493
list_for_each_entry(ref, &entry->refs, list) {
494-
gpiod_remove_lookup_table(ref->lookup);
495-
kfree(ref->lookup->table[0].key);
496-
kfree(ref->lookup);
497-
ref->lookup = NULL;
494+
if (ref->lookup) {
495+
gpiod_remove_lookup_table(ref->lookup);
496+
kfree(ref->lookup->table[0].key);
497+
kfree(ref->lookup);
498+
ref->lookup = NULL;
499+
}
500+
498501
gpio_shared_remove_adev(&ref->adev);
499502
}
500503
}

0 commit comments

Comments
 (0)