Skip to content

Commit 70ea005

Browse files
geertugregkh
authored andcommitted
gpio: aggregator: Fix calling into sleeping GPIO controllers
[ Upstream commit 2cba054 ] If the parent GPIO controller is a sleeping controller (e.g. a GPIO controller connected to I2C), getting or setting a GPIO triggers a might_sleep() warning. This happens because the GPIO Aggregator takes the can_sleep flag into account only for its internal locking, not for calling into the parent GPIO controller. Fix this by using the gpiod_[gs]et*_cansleep() APIs when calling into a sleeping GPIO controller. Reported-by: Mikko Salomäki <ms@datarespons.se> Fixes: 828546e ("gpio: Add GPIO Aggregator") Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 0042178 commit 70ea005

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

‎drivers/gpio/gpio-aggregator.c‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ static int gpio_fwd_get(struct gpio_chip *chip, unsigned int offset)
330330
{
331331
struct gpiochip_fwd *fwd = gpiochip_get_data(chip);
332332

333-
return gpiod_get_value(fwd->descs[offset]);
333+
return chip->can_sleep ? gpiod_get_value_cansleep(fwd->descs[offset])
334+
: gpiod_get_value(fwd->descs[offset]);
334335
}
335336

336337
static int gpio_fwd_get_multiple(struct gpiochip_fwd *fwd, unsigned long *mask,
@@ -349,7 +350,10 @@ static int gpio_fwd_get_multiple(struct gpiochip_fwd *fwd, unsigned long *mask,
349350
for_each_set_bit(i, mask, fwd->chip.ngpio)
350351
descs[j++] = fwd->descs[i];
351352

352-
error = gpiod_get_array_value(j, descs, NULL, values);
353+
if (fwd->chip.can_sleep)
354+
error = gpiod_get_array_value_cansleep(j, descs, NULL, values);
355+
else
356+
error = gpiod_get_array_value(j, descs, NULL, values);
353357
if (error)
354358
return error;
355359

@@ -384,7 +388,10 @@ static void gpio_fwd_set(struct gpio_chip *chip, unsigned int offset, int value)
384388
{
385389
struct gpiochip_fwd *fwd = gpiochip_get_data(chip);
386390

387-
gpiod_set_value(fwd->descs[offset], value);
391+
if (chip->can_sleep)
392+
gpiod_set_value_cansleep(fwd->descs[offset], value);
393+
else
394+
gpiod_set_value(fwd->descs[offset], value);
388395
}
389396

390397
static void gpio_fwd_set_multiple(struct gpiochip_fwd *fwd, unsigned long *mask,
@@ -403,7 +410,10 @@ static void gpio_fwd_set_multiple(struct gpiochip_fwd *fwd, unsigned long *mask,
403410
descs[j++] = fwd->descs[i];
404411
}
405412

406-
gpiod_set_array_value(j, descs, NULL, values);
413+
if (fwd->chip.can_sleep)
414+
gpiod_set_array_value_cansleep(j, descs, NULL, values);
415+
else
416+
gpiod_set_array_value(j, descs, NULL, values);
407417
}
408418

409419
static void gpio_fwd_set_multiple_locked(struct gpio_chip *chip,

0 commit comments

Comments
 (0)