Skip to content

Commit 30e0fd3

Browse files
hvilleneuvedooBartosz Golaszewski
authored andcommitted
gpiolib: fix performance regression when using gpio_chip_get_multiple()
commit 74abd08 ("gpiolib: sanitize the return value of gpio_chip::get_multiple()") altered the value returned by gc->get_multiple() in case it is positive (> 0), but failed to return for other cases (<= 0). This may result in the "if (gc->get)" block being executed and thus negates the performance gain that is normally obtained by using gc->get_multiple(). Fix by returning the result of gc->get_multiple() if it is <= 0. Also move the "ret" variable to the scope where it is used, which as an added bonus fixes an indentation error introduced by the aforementioned commit. Fixes: 74abd08 ("gpiolib: sanitize the return value of gpio_chip::get_multiple()") Cc: [email protected] Signed-off-by: Hugo Villeneuve <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent d0b3b7b commit 30e0fd3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/gpio/gpiolib.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3297,14 +3297,15 @@ static int gpiod_get_raw_value_commit(const struct gpio_desc *desc)
32973297
static int gpio_chip_get_multiple(struct gpio_chip *gc,
32983298
unsigned long *mask, unsigned long *bits)
32993299
{
3300-
int ret;
3301-
33023300
lockdep_assert_held(&gc->gpiodev->srcu);
33033301

33043302
if (gc->get_multiple) {
3303+
int ret;
3304+
33053305
ret = gc->get_multiple(gc, mask, bits);
33063306
if (ret > 0)
33073307
return -EBADE;
3308+
return ret;
33083309
}
33093310

33103311
if (gc->get) {

0 commit comments

Comments
 (0)