Skip to content

Commit 28f5ab1

Browse files
committed
Merge tag 'gpio-v5.3-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO fixes from Linus Walleij: "Three GPIO fixes, all touching the core, so quite important: - Fix the request of active low GPIO line events. - Don't issue WARN() stuff on NULL descriptors if the GPIOLIB is disabled. - Preserve the descriptor flags when setting the initial direction on lines" * tag 'gpio-v5.3-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: gpiolib: Preserve desc->flags when setting state gpio: don't WARN() on NULL descs if gpiolib is disabled gpiolib: fix incorrect IRQ requesting of an active-low lineevent
2 parents 5c62075 + d95da99 commit 28f5ab1

File tree

2 files changed

+47
-40
lines changed

2 files changed

+47
-40
lines changed

drivers/gpio/gpiolib.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -956,9 +956,11 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
956956
}
957957

958958
if (eflags & GPIOEVENT_REQUEST_RISING_EDGE)
959-
irqflags |= IRQF_TRIGGER_RISING;
959+
irqflags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ?
960+
IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
960961
if (eflags & GPIOEVENT_REQUEST_FALLING_EDGE)
961-
irqflags |= IRQF_TRIGGER_FALLING;
962+
irqflags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ?
963+
IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING;
962964
irqflags |= IRQF_ONESHOT;
963965

964966
INIT_KFIFO(le->events);
@@ -1392,12 +1394,17 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
13921394
for (i = 0; i < chip->ngpio; i++) {
13931395
struct gpio_desc *desc = &gdev->descs[i];
13941396

1395-
if (chip->get_direction && gpiochip_line_is_valid(chip, i))
1396-
desc->flags = !chip->get_direction(chip, i) ?
1397-
(1 << FLAG_IS_OUT) : 0;
1398-
else
1399-
desc->flags = !chip->direction_input ?
1400-
(1 << FLAG_IS_OUT) : 0;
1397+
if (chip->get_direction && gpiochip_line_is_valid(chip, i)) {
1398+
if (!chip->get_direction(chip, i))
1399+
set_bit(FLAG_IS_OUT, &desc->flags);
1400+
else
1401+
clear_bit(FLAG_IS_OUT, &desc->flags);
1402+
} else {
1403+
if (!chip->direction_input)
1404+
set_bit(FLAG_IS_OUT, &desc->flags);
1405+
else
1406+
clear_bit(FLAG_IS_OUT, &desc->flags);
1407+
}
14011408
}
14021409

14031410
acpi_gpiochip_add(chip);

include/linux/gpio/consumer.h

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ static inline void gpiod_put(struct gpio_desc *desc)
247247
might_sleep();
248248

249249
/* GPIO can never have been requested */
250-
WARN_ON(1);
250+
WARN_ON(desc);
251251
}
252252

253253
static inline void devm_gpiod_unhinge(struct device *dev,
@@ -256,15 +256,15 @@ static inline void devm_gpiod_unhinge(struct device *dev,
256256
might_sleep();
257257

258258
/* GPIO can never have been requested */
259-
WARN_ON(1);
259+
WARN_ON(desc);
260260
}
261261

262262
static inline void gpiod_put_array(struct gpio_descs *descs)
263263
{
264264
might_sleep();
265265

266266
/* GPIO can never have been requested */
267-
WARN_ON(1);
267+
WARN_ON(descs);
268268
}
269269

270270
static inline struct gpio_desc *__must_check
@@ -317,7 +317,7 @@ static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
317317
might_sleep();
318318

319319
/* GPIO can never have been requested */
320-
WARN_ON(1);
320+
WARN_ON(desc);
321321
}
322322

323323
static inline void devm_gpiod_put_array(struct device *dev,
@@ -326,40 +326,40 @@ static inline void devm_gpiod_put_array(struct device *dev,
326326
might_sleep();
327327

328328
/* GPIO can never have been requested */
329-
WARN_ON(1);
329+
WARN_ON(descs);
330330
}
331331

332332

333333
static inline int gpiod_get_direction(const struct gpio_desc *desc)
334334
{
335335
/* GPIO can never have been requested */
336-
WARN_ON(1);
336+
WARN_ON(desc);
337337
return -ENOSYS;
338338
}
339339
static inline int gpiod_direction_input(struct gpio_desc *desc)
340340
{
341341
/* GPIO can never have been requested */
342-
WARN_ON(1);
342+
WARN_ON(desc);
343343
return -ENOSYS;
344344
}
345345
static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
346346
{
347347
/* GPIO can never have been requested */
348-
WARN_ON(1);
348+
WARN_ON(desc);
349349
return -ENOSYS;
350350
}
351351
static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
352352
{
353353
/* GPIO can never have been requested */
354-
WARN_ON(1);
354+
WARN_ON(desc);
355355
return -ENOSYS;
356356
}
357357

358358

359359
static inline int gpiod_get_value(const struct gpio_desc *desc)
360360
{
361361
/* GPIO can never have been requested */
362-
WARN_ON(1);
362+
WARN_ON(desc);
363363
return 0;
364364
}
365365
static inline int gpiod_get_array_value(unsigned int array_size,
@@ -368,27 +368,27 @@ static inline int gpiod_get_array_value(unsigned int array_size,
368368
unsigned long *value_bitmap)
369369
{
370370
/* GPIO can never have been requested */
371-
WARN_ON(1);
371+
WARN_ON(desc_array);
372372
return 0;
373373
}
374374
static inline void gpiod_set_value(struct gpio_desc *desc, int value)
375375
{
376376
/* GPIO can never have been requested */
377-
WARN_ON(1);
377+
WARN_ON(desc);
378378
}
379379
static inline int gpiod_set_array_value(unsigned int array_size,
380380
struct gpio_desc **desc_array,
381381
struct gpio_array *array_info,
382382
unsigned long *value_bitmap)
383383
{
384384
/* GPIO can never have been requested */
385-
WARN_ON(1);
385+
WARN_ON(desc_array);
386386
return 0;
387387
}
388388
static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
389389
{
390390
/* GPIO can never have been requested */
391-
WARN_ON(1);
391+
WARN_ON(desc);
392392
return 0;
393393
}
394394
static inline int gpiod_get_raw_array_value(unsigned int array_size,
@@ -397,28 +397,28 @@ static inline int gpiod_get_raw_array_value(unsigned int array_size,
397397
unsigned long *value_bitmap)
398398
{
399399
/* GPIO can never have been requested */
400-
WARN_ON(1);
400+
WARN_ON(desc_array);
401401
return 0;
402402
}
403403
static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
404404
{
405405
/* GPIO can never have been requested */
406-
WARN_ON(1);
406+
WARN_ON(desc);
407407
}
408408
static inline int gpiod_set_raw_array_value(unsigned int array_size,
409409
struct gpio_desc **desc_array,
410410
struct gpio_array *array_info,
411411
unsigned long *value_bitmap)
412412
{
413413
/* GPIO can never have been requested */
414-
WARN_ON(1);
414+
WARN_ON(desc_array);
415415
return 0;
416416
}
417417

418418
static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
419419
{
420420
/* GPIO can never have been requested */
421-
WARN_ON(1);
421+
WARN_ON(desc);
422422
return 0;
423423
}
424424
static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
@@ -427,27 +427,27 @@ static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
427427
unsigned long *value_bitmap)
428428
{
429429
/* GPIO can never have been requested */
430-
WARN_ON(1);
430+
WARN_ON(desc_array);
431431
return 0;
432432
}
433433
static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
434434
{
435435
/* GPIO can never have been requested */
436-
WARN_ON(1);
436+
WARN_ON(desc);
437437
}
438438
static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
439439
struct gpio_desc **desc_array,
440440
struct gpio_array *array_info,
441441
unsigned long *value_bitmap)
442442
{
443443
/* GPIO can never have been requested */
444-
WARN_ON(1);
444+
WARN_ON(desc_array);
445445
return 0;
446446
}
447447
static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
448448
{
449449
/* GPIO can never have been requested */
450-
WARN_ON(1);
450+
WARN_ON(desc);
451451
return 0;
452452
}
453453
static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
@@ -456,64 +456,64 @@ static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
456456
unsigned long *value_bitmap)
457457
{
458458
/* GPIO can never have been requested */
459-
WARN_ON(1);
459+
WARN_ON(desc_array);
460460
return 0;
461461
}
462462
static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
463463
int value)
464464
{
465465
/* GPIO can never have been requested */
466-
WARN_ON(1);
466+
WARN_ON(desc);
467467
}
468468
static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
469469
struct gpio_desc **desc_array,
470470
struct gpio_array *array_info,
471471
unsigned long *value_bitmap)
472472
{
473473
/* GPIO can never have been requested */
474-
WARN_ON(1);
474+
WARN_ON(desc_array);
475475
return 0;
476476
}
477477

478478
static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
479479
{
480480
/* GPIO can never have been requested */
481-
WARN_ON(1);
481+
WARN_ON(desc);
482482
return -ENOSYS;
483483
}
484484

485485
static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
486486
{
487487
/* GPIO can never have been requested */
488-
WARN_ON(1);
488+
WARN_ON(desc);
489489
return -ENOSYS;
490490
}
491491

492492
static inline int gpiod_is_active_low(const struct gpio_desc *desc)
493493
{
494494
/* GPIO can never have been requested */
495-
WARN_ON(1);
495+
WARN_ON(desc);
496496
return 0;
497497
}
498498
static inline int gpiod_cansleep(const struct gpio_desc *desc)
499499
{
500500
/* GPIO can never have been requested */
501-
WARN_ON(1);
501+
WARN_ON(desc);
502502
return 0;
503503
}
504504

505505
static inline int gpiod_to_irq(const struct gpio_desc *desc)
506506
{
507507
/* GPIO can never have been requested */
508-
WARN_ON(1);
508+
WARN_ON(desc);
509509
return -EINVAL;
510510
}
511511

512512
static inline int gpiod_set_consumer_name(struct gpio_desc *desc,
513513
const char *name)
514514
{
515515
/* GPIO can never have been requested */
516-
WARN_ON(1);
516+
WARN_ON(desc);
517517
return -EINVAL;
518518
}
519519

@@ -525,7 +525,7 @@ static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
525525
static inline int desc_to_gpio(const struct gpio_desc *desc)
526526
{
527527
/* GPIO can never have been requested */
528-
WARN_ON(1);
528+
WARN_ON(desc);
529529
return -EINVAL;
530530
}
531531

0 commit comments

Comments
 (0)