diff mbox series

[v2,2/7] gpiolib: fix fast-path cancellation in gpiod_get_array()

Message ID 20261103-b4-gpiolib-free-v2-2-ea46767c9cf8@gmail.com
State New
Headers show
Series gpiolib: scope-based management and cleanup for GPIO descriptor arrays | expand

Commit Message

Dmitry Torokhov Nov. 4, 2026, 3:40 a.m. UTC
In gpiod_get_array(), when a pin on the same chip is not in hardware
order and the preceding pins form a contiguous block, the fast path is
cancelled by setting array_info to NULL. However, descs->info was
already populated with the array_info pointer during the first
iteration, leaving descs->info pointing to the aborted array_info.
Consequently, subsequent array operations still use the fast path with
remaining bits set in the masks and wrong hardware pin numbers.

Clear descs->info alongside array_info when cancelling the fast path so
callers do not erroneously use the aborted array_info.

Fixes: c4c958aa64f3 ("gpiolib: Fix array members of same chip processed separately")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/gpio/gpiolib.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Andy Shevchenko Nov. 4, 2026, 12:09 p.m. UTC | #1
On Tue, Nov 03, 2026 at 07:40:30PM -0800, Dmitry Torokhov wrote:
> In gpiod_get_array(), when a pin on the same chip is not in hardware
> order and the preceding pins form a contiguous block, the fast path is
> cancelled by setting array_info to NULL. However, descs->info was
> already populated with the array_info pointer during the first
> iteration, leaving descs->info pointing to the aborted array_info.
> Consequently, subsequent array operations still use the fast path with
> remaining bits set in the masks and wrong hardware pin numbers.
> 
> Clear descs->info alongside array_info when cancelling the fast path so
> callers do not erroneously use the aborted array_info.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index f33033dd9473..9a850f5c1917 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -5307,6 +5307,7 @@  struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
 			 * hardware number is different from its array index.
 			 */
 			if (bitmap_full(array_info->get_mask, i)) {
+				descs->info = NULL;
 				array_info = NULL;
 			} else {
 				__clear_bit(i, array_info->get_mask);