Skip to content

Commit a802080

Browse files
author
Bartosz Golaszewski
committed
gpio: shared: don't allocate the lookup table until we really need it
We allocate memory for the GPIO lookup table at the top of gpio_shared_add_proxy_lookup() but we don't use it until the very end. Depending on the timing, we may return earlier. Move the allocation towards the end. Fixes: a060b8c ("gpiolib: implement low-level, shared GPIO support") Tested-by: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20260106-gpio-shared-fixes-v2-3-c7091d2f7581@oss.qualcomm.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
1 parent 476e44d commit a802080

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

drivers/gpio/gpiolib-shared.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,10 @@ int gpio_shared_add_proxy_lookup(struct device *consumer, const char *con_id,
443443
unsigned long lflags)
444444
{
445445
const char *dev_id = dev_name(consumer);
446+
struct gpiod_lookup_table *lookup;
446447
struct gpio_shared_entry *entry;
447448
struct gpio_shared_ref *ref;
448449

449-
struct gpiod_lookup_table *lookup __free(kfree) =
450-
kzalloc(struct_size(lookup, table, 2), GFP_KERNEL);
451-
if (!lookup)
452-
return -ENOMEM;
453-
454450
list_for_each_entry(entry, &gpio_shared_list, list) {
455451
list_for_each_entry(ref, &entry->refs, list) {
456452
guard(mutex)(&ref->lock);
@@ -482,14 +478,18 @@ int gpio_shared_add_proxy_lookup(struct device *consumer, const char *con_id,
482478
if (!key)
483479
return -ENOMEM;
484480

481+
lookup = kzalloc(struct_size(lookup, table, 2), GFP_KERNEL);
482+
if (!lookup)
483+
return -ENOMEM;
484+
485485
pr_debug("Adding machine lookup entry for a shared GPIO for consumer %s, with key '%s' and con_id '%s'\n",
486486
dev_id, key, ref->con_id ?: "none");
487487

488488
lookup->dev_id = dev_id;
489489
lookup->table[0] = GPIO_LOOKUP(no_free_ptr(key), 0,
490490
ref->con_id, lflags);
491491

492-
ref->lookup = no_free_ptr(lookup);
492+
ref->lookup = lookup;
493493
gpiod_add_lookup_table(ref->lookup);
494494

495495
return 0;

0 commit comments

Comments
 (0)