Skip to content

Commit 0102fbf

Browse files
author
Bartosz Golaszewski
committed
gpiolib: don't check the retval of get_direction() when registering a chip
During chip registration we should neither check the return value of gc->get_direction() nor hold the SRCU lock when calling it. The former is because pin controllers may have pins set to alternate functions and return errors from their get_direction() callbacks. That's alright - we should default to the safe INPUT state and not bail-out. The latter is not needed because we haven't registered the chip yet so there's nothing to protect against dynamic removal. In fact: we currently hit a lockdep splat. Revert to calling the gc->get_direction() callback directly and *not* checking its value. Fixes: 9d846b1 ("gpiolib: check the return value of gpio_chip::get_direction()") Reported-by: Marek Szyprowski <m.szyprowski@samsung.com> Closes: https://lore.kernel.org/all/81f890fc-6688-42f0-9756-567efc8bb97a@samsung.com/ Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Tested-by: Marek Szyprowski <m.szyprowski@samsung.com> Link: https://lore.kernel.org/r/20250226-retval-fixes-v2-1-c8dc57182441@linaro.org Tested-by: Gene C <arch@sapience.com> Link: https://lore.kernel.org/r/20250311175631.83779-1-brgl@bgdev.pl Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
1 parent 80e54e8 commit 0102fbf

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

drivers/gpio/gpiolib.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,24 +1056,19 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
10561056

10571057
desc->gdev = gdev;
10581058

1059-
if (gc->get_direction && gpiochip_line_is_valid(gc, desc_index)) {
1060-
ret = gc->get_direction(gc, desc_index);
1061-
if (ret < 0)
1062-
/*
1063-
* FIXME: Bail-out here once all GPIO drivers
1064-
* are updated to not return errors in
1065-
* situations that can be considered normal
1066-
* operation.
1067-
*/
1068-
dev_warn(&gdev->dev,
1069-
"%s: get_direction failed: %d\n",
1070-
__func__, ret);
1071-
1072-
assign_bit(FLAG_IS_OUT, &desc->flags, !ret);
1073-
} else {
1059+
/*
1060+
* We would typically want to check the return value of
1061+
* get_direction() here but we must not check the return value
1062+
* and bail-out as pin controllers can have pins configured to
1063+
* alternate functions and return -EINVAL. Also: there's no
1064+
* need to take the SRCU lock here.
1065+
*/
1066+
if (gc->get_direction && gpiochip_line_is_valid(gc, desc_index))
1067+
assign_bit(FLAG_IS_OUT, &desc->flags,
1068+
!gc->get_direction(gc, desc_index));
1069+
else
10741070
assign_bit(FLAG_IS_OUT,
10751071
&desc->flags, !gc->direction_input);
1076-
}
10771072
}
10781073

10791074
ret = of_gpiochip_add(gc);

0 commit comments

Comments
 (0)