Skip to content

gpiolib: remove gpio_desc[] static array

Alexandre Courbot linux-arch linux-arm-kernel lkml 1 version Applied

Status from this message: Applied, thanks.

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest9 patches 32 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/9gpiolib: link all gpio_chips using a listdrivers/gpio/gpiolib.c include/asm-generic/gpio.h+46 -72 replies
2/9gpiolib: use gpio_chips list in gpiolib_sysfs_initdrivers/gpio/gpiolib.c+2 -52 replies
3/9gpiolib: use gpio_chips list in gpiochip_finddrivers/gpio/gpiolib.c+7 -102 replies
4/9gpiolib: use gpio_chips list in sysfs opsdrivers/gpio/gpiolib.c+10 -273 replies
5/9gpiolib: use gpio_chips list in gpiochip_find_basedrivers/gpio/gpiolib.c+16 -213 replies
6/9gpiolib: use descriptors internallydrivers/gpio/gpiolib.c+317 -17613 replies
7/9gpiolib: let gpio_chip reference its descriptorsdrivers/gpio/gpiolib.c include/asm-generic/gpio.h+26 -162 replies
8/9gpiolib: use gpio_chips list in gpio_to_descdrivers/gpio/gpiolib.c+15 -44 replies
9/9gpiolib: dynamically allocate descriptors arraydrivers/gpio/gpiolib.c+12 -41 reply

Reviews trailers per patch

7 of 9 patches have a Reviewed-by or Acked-by.

PatchLinus Walleij
1/9R-b
2/9R-b
3/9R-b
4/9R-b
5/9
6/9
7/9R-b
8/9R-b
9/9R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/9] gpiolib: remove gpio_desc[] static array

Since Linus kindly merged the gpiochip_reserve() removal patches, here comes the main course.

This series removes the ARCH_NR_GPIOS sized static array of GPIO descriptors that stood in gpiolib and replaces it with a more flexible mechanism that dynamically allocates GPIO descriptors as chips are added.

ARCH_NR_GPIOS is still here, but now only controls the upper limit of the GPIO integer space, i.e. which GPIO numbers are valid and where GPIO chips without a base GPIO are placed in the GPIO space. Technically it would be possible to get rid of it completely - but this might change GPIO numbers on some architectures and make people unhappy. At least it can now be arbitrarily high without consuming more memory.

As a result of this series, gpiolib has a slightly lower memory footprint (~-9KB on my Tegra2 board which has a GPIO space of 1024 but only uses 232 of them), is very slightly slower (because of the gpio to descriptor conversion which is linear instead of being constant), and (most importantly) is prepared to receive the new descriptor-based public GPIO interface.

The linear-time conversion between GPIO numbers and descriptors might make some teeth grind, but please consider the following. First, even though the conversion is O(n), this is a very small n (the number of GPIO chips), and I doubt the overhead would be even perceptible. Second, the gpio descriptor interface that will follow this series will not require this conversion since it works with descriptors directly. Finally, the GPIO framework allow platforms that are concerned about performance to implement gpio_get_value() and gpio_set_value() with a fast path shortcutting gpiolib for those GPIO numbers for which performance matters, and this is not affected at all by this series.

The patches are split as much as possible to make the switch as easy to follow as possible - they may actually be oversplit, if this is the case please let me know and I will resubmit the series.

This has been tested on a Tegra 2 Ventana board. I made sure that debugfs and sysfs were working as before, and that GPIOs had the expected value. Being a rather deep change, it should certainly undergo some more testing.

Alexandre Courbot (9):
gpiolib: link all gpio_chips using a list
gpiolib: use gpio_chips list in gpiolib_sysfs_init
gpiolib: use gpio_chips list in gpiochip_find
gpiolib: use gpio_chips list in sysfs ops
gpiolib: use gpio_chips list in gpiochip_find_base
gpiolib: use descriptors internally
gpiolib: let gpio_chip reference its descriptors
gpiolib: use gpio_chips list in gpio_to_desc
gpiolib: dynamically allocate descriptors array

 drivers/gpio/gpiolib.c     | 694 ++++++++++++++++++++++++++++-----------------
 include/asm-generic/gpio.h |   5 +
 2 files changed, 440 insertions(+), 259 deletions(-)
Signature · 1 line
1.8.1.1