Skip to content

Commit 4ea0c97

Browse files
andy-shevBartosz Golaszewski
authored andcommitted
gpiolib: Check array_info for NULL only once in gpiod_get_array()
gpiod_get_array() has a long if-else-if branching where each of them tests for the same variable to be not NULL. Instead, check for NULL before even going to that flow. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
1 parent 7973642 commit 4ea0c97

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

drivers/gpio/gpiolib.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4288,7 +4288,7 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
42884288
if (!descs)
42894289
return ERR_PTR(-ENOMEM);
42904290

4291-
for (descs->ndescs = 0; descs->ndescs < count; ) {
4291+
for (descs->ndescs = 0; descs->ndescs < count; descs->ndescs++) {
42924292
desc = gpiod_get_index(dev, con_id, descs->ndescs, flags);
42934293
if (IS_ERR(desc)) {
42944294
gpiod_put_array(descs);
@@ -4333,17 +4333,21 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
43334333
count - descs->ndescs);
43344334
descs->info = array_info;
43354335
}
4336+
4337+
/* If there is no cache for fast bitmap processing path, continue */
4338+
if (!array_info)
4339+
continue;
4340+
43364341
/* Unmark array members which don't belong to the 'fast' chip */
4337-
if (array_info && array_info->chip != gc) {
4342+
if (array_info->chip != gc) {
43384343
__clear_bit(descs->ndescs, array_info->get_mask);
43394344
__clear_bit(descs->ndescs, array_info->set_mask);
43404345
}
43414346
/*
43424347
* Detect array members which belong to the 'fast' chip
43434348
* but their pins are not in hardware order.
43444349
*/
4345-
else if (array_info &&
4346-
gpio_chip_hwgpio(desc) != descs->ndescs) {
4350+
else if (gpio_chip_hwgpio(desc) != descs->ndescs) {
43474351
/*
43484352
* Don't use fast path if all array members processed so
43494353
* far belong to the same chip as this one but its pin
@@ -4357,7 +4361,7 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
43574361
__clear_bit(descs->ndescs,
43584362
array_info->set_mask);
43594363
}
4360-
} else if (array_info) {
4364+
} else {
43614365
/* Exclude open drain or open source from fast output */
43624366
if (gpiochip_line_is_open_drain(gc, descs->ndescs) ||
43634367
gpiochip_line_is_open_source(gc, descs->ndescs))
@@ -4368,8 +4372,6 @@ struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
43684372
__set_bit(descs->ndescs,
43694373
array_info->invert_mask);
43704374
}
4371-
4372-
descs->ndescs++;
43734375
}
43744376
if (array_info)
43754377
dev_dbg(dev,

0 commit comments

Comments
 (0)