Commit c904a0d8 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski
Browse files

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: a060b8c5 ("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: default avatarBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
parent e2c4175b
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -491,10 +491,13 @@ void gpio_device_teardown_shared(struct gpio_device *gdev)
			continue;

		list_for_each_entry(ref, &entry->refs, list) {
			if (ref->lookup) {
				gpiod_remove_lookup_table(ref->lookup);
				kfree(ref->lookup->table[0].key);
				kfree(ref->lookup);
				ref->lookup = NULL;
			}

			gpio_shared_remove_adev(&ref->adev);
		}
	}