Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 144b5ae3 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull GPIO fixes from Linus Walleij:
 "More GPIO fixes.  Most prominent the gpiod_to_irq() fix brought to my
  attention by Hans de Goede.  The hardening patch is a consequence of
  the reasoning around that bug.

   - It was discovered that too many parts of the kernel does not
     respect gpiod_to_irq() returning zero for an invalid IRQ.  While
     this gets fixed, we need to make it return negative errorcodes
     again.

   - Harden the library a bit when passed error pointers.  It is a bug
     to use these, but let's be helpful and warn the users.

   - Fix an uninitialized spinlock in the 104-idi-48 driver"

* tag 'gpio-v4.7-4' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio:
  gpio: make library immune to error pointers
  gpio: make sure gpiod_to_irq() returns negative on NULL desc
  gpio: 104-idi-48: Fix missing spin_lock_init for ack_lock
parents 67016f6c bfbbe44d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -247,6 +247,7 @@ static int idi_48_probe(struct device *dev, unsigned int id)
	idi48gpio->irq = irq[id];

	spin_lock_init(&idi48gpio->lock);
	spin_lock_init(&idi48gpio->ack_lock);

	dev_set_drvdata(dev, idi48gpio);

+18 −3
Original line number Diff line number Diff line
@@ -1373,8 +1373,12 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label)
#define VALIDATE_DESC(desc) do { \
	if (!desc) \
		return 0; \
	if (IS_ERR(desc)) {						\
		pr_warn("%s: invalid GPIO (errorpointer)\n", __func__); \
		return PTR_ERR(desc); \
	} \
	if (!desc->gdev) { \
		pr_warn("%s: invalid GPIO\n", __func__); \
		pr_warn("%s: invalid GPIO (no device)\n", __func__); \
		return -EINVAL; \
	} \
	if ( !desc->gdev->chip ) { \
@@ -1386,8 +1390,12 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label)
#define VALIDATE_DESC_VOID(desc) do { \
	if (!desc) \
		return; \
	if (IS_ERR(desc)) {						\
		pr_warn("%s: invalid GPIO (errorpointer)\n", __func__); \
		return; \
	} \
	if (!desc->gdev) { \
		pr_warn("%s: invalid GPIO\n", __func__); \
		pr_warn("%s: invalid GPIO (no device)\n", __func__); \
		return; \
	} \
	if (!desc->gdev->chip) { \
@@ -2056,7 +2064,14 @@ int gpiod_to_irq(const struct gpio_desc *desc)
	struct gpio_chip *chip;
	int offset;

	VALIDATE_DESC(desc);
	/*
	 * Cannot VALIDATE_DESC() here as gpiod_to_irq() consumer semantics
	 * requires this function to not return zero on an invalid descriptor
	 * but rather a negative error number.
	 */
	if (!desc || IS_ERR(desc) || !desc->gdev || !desc->gdev->chip)
		return -EINVAL;

	chip = desc->gdev->chip;
	offset = gpio_chip_hwgpio(desc);
	if (chip->to_irq) {