Skip to contentSkip to conversation

pinctrl: core: Warn about NULL gpio_chip in pinctrl_ready_for_gpio_range()

PATCH New Tony Lindgren 2 participants 2 messages Sep 3, 2015 – Sep 8, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: core: Warn about NULL gpio_chip in pinctrl_ready_for_gpio_range()

If the gpio driver is confused about the numbers for gpio-ranges, pinctrl_ready_for_gpio_range() may get called with invalid GPIO causing a NULL pointer exception. Let's instead provide a warning that allows fixing the problem and return with error.

---
 drivers/pinctrl/core.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/pinctrl/core.c +3 -0
@@ -349,6 +349,9 @@ static bool pinctrl_ready_for_gpio_range(unsigned gpio)
 	struct pinctrl_gpio_range *range = NULL;
 	struct gpio_chip *chip = gpio_to_chip(gpio);
 
+	if (WARN(!chip, "no gpio_chip for gpio%i?", gpio))
+		return false;
+
 	mutex_lock(&pinctrldev_list_mutex);
 
 	/* Loop over the pin controllers */
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/1 pinctrl: core: Warn about NULL gpio_chip in pinctrl_ready_for_gpio_range()

Quoted 6 lines · Tony Lindgren

If the gpio driver is confused about the numbers for gpio-ranges, pinctrl_ready_for_gpio_range() may get called with invalid GPIO causing a NULL pointer exception. Let's instead provide a warning that allows fixing the problem and return with error.

Patch applied for fixes.

Yours,
Linus Walleij