Skip to content

Commit 0b9df43

Browse files
committed
Merge tag 'gpio-fixes-for-v5.17-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux
Pull gpio fixes from Bartosz Golaszewski: - use sleeping variants of GPIO accessors where needed in gpio-aggregator - never return kernel's internal error codes to user-space in gpiolib core - use the correct register for reading output values in gpio-sifive - fix line hogging in gpio-sim * tag 'gpio-fixes-for-v5.17-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: gpio: sim: fix hogs with custom chip labels gpio: sifive: use the correct register to read output values gpiolib: Never return internal error codes to user space gpio: aggregator: Fix calling into sleeping GPIO controllers
2 parents 284fce0 + c162ca0 commit 0b9df43

File tree

6 files changed

+47
-17
lines changed

6 files changed

+47
-17
lines changed

drivers/gpio/gpio-aggregator.c

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

281-
return gpiod_get_value(fwd->descs[offset]);
281+
return chip->can_sleep ? gpiod_get_value_cansleep(fwd->descs[offset])
282+
: gpiod_get_value(fwd->descs[offset]);
282283
}
283284

284285
static int gpio_fwd_get_multiple(struct gpiochip_fwd *fwd, unsigned long *mask,
@@ -293,7 +294,10 @@ static int gpio_fwd_get_multiple(struct gpiochip_fwd *fwd, unsigned long *mask,
293294
for_each_set_bit(i, mask, fwd->chip.ngpio)
294295
descs[j++] = fwd->descs[i];
295296

296-
error = gpiod_get_array_value(j, descs, NULL, values);
297+
if (fwd->chip.can_sleep)
298+
error = gpiod_get_array_value_cansleep(j, descs, NULL, values);
299+
else
300+
error = gpiod_get_array_value(j, descs, NULL, values);
297301
if (error)
298302
return error;
299303

@@ -328,7 +332,10 @@ static void gpio_fwd_set(struct gpio_chip *chip, unsigned int offset, int value)
328332
{
329333
struct gpiochip_fwd *fwd = gpiochip_get_data(chip);
330334

331-
gpiod_set_value(fwd->descs[offset], value);
335+
if (chip->can_sleep)
336+
gpiod_set_value_cansleep(fwd->descs[offset], value);
337+
else
338+
gpiod_set_value(fwd->descs[offset], value);
332339
}
333340

334341
static void gpio_fwd_set_multiple(struct gpiochip_fwd *fwd, unsigned long *mask,
@@ -343,7 +350,10 @@ static void gpio_fwd_set_multiple(struct gpiochip_fwd *fwd, unsigned long *mask,
343350
descs[j++] = fwd->descs[i];
344351
}
345352

346-
gpiod_set_array_value(j, descs, NULL, values);
353+
if (fwd->chip.can_sleep)
354+
gpiod_set_array_value_cansleep(j, descs, NULL, values);
355+
else
356+
gpiod_set_array_value(j, descs, NULL, values);
347357
}
348358

349359
static void gpio_fwd_set_multiple_locked(struct gpio_chip *chip,

drivers/gpio/gpio-sifive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static int sifive_gpio_probe(struct platform_device *pdev)
223223
NULL,
224224
chip->base + SIFIVE_GPIO_OUTPUT_EN,
225225
chip->base + SIFIVE_GPIO_INPUT_EN,
226-
0);
226+
BGPIOF_READ_OUTPUT_REG_SET);
227227
if (ret) {
228228
dev_err(dev, "unable to init generic GPIO\n");
229229
return ret;

drivers/gpio/gpio-sim.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,11 @@ static struct gpio_sim_bank *to_gpio_sim_bank(struct config_item *item)
570570
return container_of(group, struct gpio_sim_bank, group);
571571
}
572572

573+
static bool gpio_sim_bank_has_label(struct gpio_sim_bank *bank)
574+
{
575+
return bank->label && *bank->label;
576+
}
577+
573578
static struct gpio_sim_device *
574579
gpio_sim_bank_get_device(struct gpio_sim_bank *bank)
575580
{
@@ -770,9 +775,15 @@ static int gpio_sim_add_hogs(struct gpio_sim_device *dev)
770775
* point the device doesn't exist yet and so dev_name()
771776
* is not available.
772777
*/
773-
hog->chip_label = kasprintf(GFP_KERNEL,
774-
"gpio-sim.%u-%s", dev->id,
775-
fwnode_get_name(bank->swnode));
778+
if (gpio_sim_bank_has_label(bank))
779+
hog->chip_label = kstrdup(bank->label,
780+
GFP_KERNEL);
781+
else
782+
hog->chip_label = kasprintf(GFP_KERNEL,
783+
"gpio-sim.%u-%s",
784+
dev->id,
785+
fwnode_get_name(
786+
bank->swnode));
776787
if (!hog->chip_label) {
777788
gpio_sim_remove_hogs(dev);
778789
return -ENOMEM;
@@ -816,7 +827,7 @@ gpio_sim_make_bank_swnode(struct gpio_sim_bank *bank,
816827

817828
properties[prop_idx++] = PROPERTY_ENTRY_U32("ngpios", bank->num_lines);
818829

819-
if (bank->label && (strlen(bank->label) > 0))
830+
if (gpio_sim_bank_has_label(bank))
820831
properties[prop_idx++] = PROPERTY_ENTRY_STRING("gpio-sim,label",
821832
bank->label);
822833

drivers/gpio/gpiolib-cdev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
330330
goto out_free_lh;
331331
}
332332

333-
ret = gpiod_request(desc, lh->label);
333+
ret = gpiod_request_user(desc, lh->label);
334334
if (ret)
335335
goto out_free_lh;
336336
lh->descs[i] = desc;
@@ -1378,7 +1378,7 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip)
13781378
goto out_free_linereq;
13791379
}
13801380

1381-
ret = gpiod_request(desc, lr->label);
1381+
ret = gpiod_request_user(desc, lr->label);
13821382
if (ret)
13831383
goto out_free_linereq;
13841384

@@ -1764,7 +1764,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
17641764
}
17651765
}
17661766

1767-
ret = gpiod_request(desc, le->label);
1767+
ret = gpiod_request_user(desc, le->label);
17681768
if (ret)
17691769
goto out_free_le;
17701770
le->desc = desc;

drivers/gpio/gpiolib-sysfs.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,9 @@ static ssize_t export_store(struct class *class,
475475
* they may be undone on its behalf too.
476476
*/
477477

478-
status = gpiod_request(desc, "sysfs");
479-
if (status) {
480-
if (status == -EPROBE_DEFER)
481-
status = -ENODEV;
478+
status = gpiod_request_user(desc, "sysfs");
479+
if (status)
482480
goto done;
483-
}
484481

485482
status = gpiod_set_transitory(desc, false);
486483
if (!status) {

drivers/gpio/gpiolib.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ struct gpio_desc {
135135

136136
int gpiod_request(struct gpio_desc *desc, const char *label);
137137
void gpiod_free(struct gpio_desc *desc);
138+
139+
static inline int gpiod_request_user(struct gpio_desc *desc, const char *label)
140+
{
141+
int ret;
142+
143+
ret = gpiod_request(desc, label);
144+
if (ret == -EPROBE_DEFER)
145+
ret = -ENODEV;
146+
147+
return ret;
148+
}
149+
138150
int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
139151
unsigned long lflags, enum gpiod_flags dflags);
140152
int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce);

0 commit comments

Comments
 (0)