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

gpio: mockup: add helpers for accessing the gpio ranges

In order to avoid repeating the calculations on every access - add
helpers for gpio base and ngpio components of the ranges array.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Bartosz Golaszewski and committed by
Linus Walleij
cd9835f1 e63a006f

+14 -4
+14 -4
drivers/gpio/gpio-mockup.c
··· 81 81 82 82 static struct dentry *gpio_mockup_dbg_dir; 83 83 84 + static int gpio_mockup_range_base(unsigned int index) 85 + { 86 + return gpio_mockup_ranges[index * 2]; 87 + } 88 + 89 + static int gpio_mockup_range_ngpio(unsigned int index) 90 + { 91 + return gpio_mockup_ranges[index * 2 + 1]; 92 + } 93 + 84 94 static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) 85 95 { 86 96 struct gpio_mockup_chip *chip = gpiochip_get_data(gc); ··· 361 351 * always be greater than 0. 362 352 */ 363 353 for (i = 0; i < num_chips; i++) { 364 - if (gpio_mockup_ranges[i * 2 + 1] < 0) 354 + if (gpio_mockup_range_ngpio(i) < 0) 365 355 return -EINVAL; 366 356 } 367 357 ··· 377 367 378 368 for (i = 0; i < num_chips; i++) { 379 369 pdata.index = index++; 380 - pdata.base = gpio_mockup_ranges[i * 2]; 370 + pdata.base = gpio_mockup_range_base(i); 381 371 pdata.ngpio = pdata.base < 0 382 - ? gpio_mockup_ranges[i * 2 + 1] 383 - : gpio_mockup_ranges[i * 2 + 1] - pdata.base; 372 + ? gpio_mockup_range_ngpio(i) 373 + : gpio_mockup_range_ngpio(i) - pdata.base; 384 374 pdata.named_lines = gpio_mockup_named_lines; 385 375 386 376 pdev = platform_device_register_resndata(NULL,