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

gpiolib: use gpio_chips list in sysfs ops

This makes the code both simpler and faster compared to parsing the GPIO
number space.

Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

authored by

Alexandre Courbot and committed by
Grant Likely
cb1650d4 125eef96

+10 -27
+10 -27
drivers/gpio/gpiolib.c
··· 1890 1890 static void *gpiolib_seq_start(struct seq_file *s, loff_t *pos) 1891 1891 { 1892 1892 struct gpio_chip *chip = NULL; 1893 - unsigned int gpio; 1894 - void *ret = NULL; 1895 - loff_t index = 0; 1893 + loff_t index = *pos; 1896 1894 1897 1895 /* REVISIT this isn't locked against gpio_chip removal ... */ 1898 1896 1899 - for (gpio = 0; gpio_is_valid(gpio); gpio++) { 1900 - if (gpio_desc[gpio].chip == chip) 1901 - continue; 1902 - 1903 - chip = gpio_desc[gpio].chip; 1904 - if (!chip) 1905 - continue; 1906 - 1907 - if (index++ >= *pos) { 1908 - ret = chip; 1909 - break; 1910 - } 1911 - } 1912 - 1913 1897 s->private = ""; 1914 1898 1915 - return ret; 1899 + list_for_each_entry(chip, &gpio_chips, list) 1900 + if (index-- == 0) 1901 + return chip; 1902 + 1903 + return NULL; 1916 1904 } 1917 1905 1918 1906 static void *gpiolib_seq_next(struct seq_file *s, void *v, loff_t *pos) 1919 1907 { 1920 1908 struct gpio_chip *chip = v; 1921 - unsigned int gpio; 1922 1909 void *ret = NULL; 1923 1910 1924 - /* skip GPIOs provided by the current chip */ 1925 - for (gpio = chip->base + chip->ngpio; gpio_is_valid(gpio); gpio++) { 1926 - chip = gpio_desc[gpio].chip; 1927 - if (chip) { 1928 - ret = chip; 1929 - break; 1930 - } 1931 - } 1911 + if (list_is_last(&chip->list, &gpio_chips)) 1912 + ret = NULL; 1913 + else 1914 + ret = list_entry(chip->list.next, struct gpio_chip, list); 1932 1915 1933 1916 s->private = "\n"; 1934 1917 ++*pos;