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

Configure Feed

Select the types of activity you want to include in your feed.

gpio: aggregator: refactor the code to add GPIO desc in the forwarder

Create a dedicated function to add a GPIO desc in the forwarder. Instead of
saving a GPIO descs array pointer, now the GPIO descs are passed one by one
to the forwarder which registers them in its own array. So after the call
of gpiochip_fwd_create(), the passed array can be free.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Thomas Richard <thomas.richard@bootlin.com>
Link: https://lore.kernel.org/r/20250811-aaeon-up-board-pinctrl-support-v9-3-29f0cbbdfb30@bootlin.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

authored by

Thomas Richard and committed by
Bartosz Golaszewski
c44ce91b 871c7cd5

+40 -19
+40 -19
drivers/gpio/gpio-aggregator.c
··· 485 485 if (!fwd) 486 486 return ERR_PTR(-ENOMEM); 487 487 488 + fwd->descs = devm_kcalloc(dev, ngpios, sizeof(*fwd->descs), GFP_KERNEL); 489 + if (!fwd->descs) 490 + return ERR_PTR(-ENOMEM); 491 + 488 492 chip = &fwd->chip; 489 493 490 494 chip->label = dev_name(dev); ··· 508 504 return fwd; 509 505 } 510 506 507 + static int gpiochip_fwd_desc_add(struct gpiochip_fwd *fwd, 508 + struct gpio_desc *desc, 509 + unsigned int offset) 510 + { 511 + struct gpio_chip *parent = gpiod_to_chip(desc); 512 + struct gpio_chip *chip = &fwd->chip; 513 + 514 + if (offset > chip->ngpio) 515 + return -EINVAL; 516 + 517 + /* 518 + * If any of the GPIO lines are sleeping, then the entire forwarder 519 + * will be sleeping. 520 + * If any of the chips support .set_config(), then the forwarder will 521 + * support setting configs. 522 + */ 523 + if (gpiod_cansleep(desc)) 524 + chip->can_sleep = true; 525 + 526 + if (parent && parent->set_config) 527 + chip->set_config = gpio_fwd_set_config; 528 + 529 + fwd->descs[offset] = desc; 530 + 531 + dev_dbg(chip->parent, "%u => gpio %d irq %d\n", offset, 532 + desc_to_gpio(desc), gpiod_to_irq(desc)); 533 + 534 + return 0; 535 + } 536 + 511 537 /** 512 538 * gpiochip_fwd_create() - Create a new GPIO forwarder 513 539 * @dev: Parent device pointer 514 540 * @ngpios: Number of GPIOs in the forwarder. 515 541 * @descs: Array containing the GPIO descriptors to forward to. 516 - * This array must contain @ngpios entries, and must not be deallocated 517 - * before the forwarder has been destroyed again. 542 + * This array must contain @ngpios entries, and can be deallocated 543 + * as the forwarder has its own array. 518 544 * @features: Bitwise ORed features as defined with FWD_FEATURE_*. 519 545 * 520 546 * This function creates a new gpiochip, which forwards all GPIO operations to ··· 569 535 570 536 chip = &fwd->chip; 571 537 572 - /* 573 - * If any of the GPIO lines are sleeping, then the entire forwarder 574 - * will be sleeping. 575 - * If any of the chips support .set_config(), then the forwarder will 576 - * support setting configs. 577 - */ 578 538 for (i = 0; i < ngpios; i++) { 579 - struct gpio_chip *parent = gpiod_to_chip(descs[i]); 580 - 581 - dev_dbg(dev, "%u => gpio %d irq %d\n", i, 582 - desc_to_gpio(descs[i]), gpiod_to_irq(descs[i])); 583 - 584 - if (gpiod_cansleep(descs[i])) 585 - chip->can_sleep = true; 586 - if (parent && parent->set_config) 587 - chip->set_config = gpio_fwd_set_config; 539 + error = gpiochip_fwd_desc_add(fwd, descs[i], i); 540 + if (error) 541 + return ERR_PTR(error); 588 542 } 589 - 590 - fwd->descs = descs; 591 543 592 544 if (chip->can_sleep) 593 545 mutex_init(&fwd->mlock); ··· 1368 1348 return PTR_ERR(fwd); 1369 1349 1370 1350 platform_set_drvdata(pdev, fwd); 1351 + devm_kfree(dev, descs); 1371 1352 return 0; 1372 1353 } 1373 1354