Commit 9b3b94e9 authored by Sven Peter's avatar Sven Peter Committed by Linus Walleij

pinctrl: apple: Always return valid type in apple_gpio_irq_type

apple_gpio_irq_type can possibly return -EINVAL which triggers the
following compile error with gcc 9 because the type no longer fits
into the mask.

  drivers/pinctrl/pinctrl-apple-gpio.c: In function 'apple_gpio_irq_set_type':
  ././include/linux/compiler_types.h:335:38: error: call to '__compiletime_assert_289' declared with attribute error: FIELD_PREP: value too large for the field
    335 |  _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
        |                                      ^
  [...]
  drivers/pinctrl/pinctrl-apple-gpio.c:294:7: note: in expansion of macro 'FIELD_PREP'
    294 |       FIELD_PREP(REG_GPIOx_MODE, irqtype));
        |       ^~~~~~~~~~

Fix this by making the return value always valid and instead checking
for REG_GPIOx_IN_IRQ_OFF in apple_gpio_irq_set_type and return -EINVAL
from there.

Fixes: a0f160ff ("pinctrl: add pinctrl/GPIO driver for Apple SoCs")
Signed-off-by: default avatarSven Peter <sven@svenpeter.dev>
Reviewed-by: default avatarJoey Gouly <joey.gouly@arm.com>
Link: https://lore.kernel.org/r/20211101150640.46553-1-sven@svenpeter.devSigned-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent a5b9703f
...@@ -258,7 +258,7 @@ static void apple_gpio_irq_ack(struct irq_data *data) ...@@ -258,7 +258,7 @@ static void apple_gpio_irq_ack(struct irq_data *data)
pctl->base + REG_IRQ(irqgrp, data->hwirq)); pctl->base + REG_IRQ(irqgrp, data->hwirq));
} }
static int apple_gpio_irq_type(unsigned int type) static unsigned int apple_gpio_irq_type(unsigned int type)
{ {
switch (type & IRQ_TYPE_SENSE_MASK) { switch (type & IRQ_TYPE_SENSE_MASK) {
case IRQ_TYPE_EDGE_RISING: case IRQ_TYPE_EDGE_RISING:
...@@ -272,7 +272,7 @@ static int apple_gpio_irq_type(unsigned int type) ...@@ -272,7 +272,7 @@ static int apple_gpio_irq_type(unsigned int type)
case IRQ_TYPE_LEVEL_LOW: case IRQ_TYPE_LEVEL_LOW:
return REG_GPIOx_IN_IRQ_LO; return REG_GPIOx_IN_IRQ_LO;
default: default:
return -EINVAL; return REG_GPIOx_IN_IRQ_OFF;
} }
} }
...@@ -288,7 +288,7 @@ static void apple_gpio_irq_unmask(struct irq_data *data) ...@@ -288,7 +288,7 @@ static void apple_gpio_irq_unmask(struct irq_data *data)
{ {
struct apple_gpio_pinctrl *pctl = struct apple_gpio_pinctrl *pctl =
gpiochip_get_data(irq_data_get_irq_chip_data(data)); gpiochip_get_data(irq_data_get_irq_chip_data(data));
int irqtype = apple_gpio_irq_type(irqd_get_trigger_type(data)); unsigned int irqtype = apple_gpio_irq_type(irqd_get_trigger_type(data));
apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE, apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE,
FIELD_PREP(REG_GPIOx_MODE, irqtype)); FIELD_PREP(REG_GPIOx_MODE, irqtype));
...@@ -313,10 +313,10 @@ static int apple_gpio_irq_set_type(struct irq_data *data, ...@@ -313,10 +313,10 @@ static int apple_gpio_irq_set_type(struct irq_data *data,
{ {
struct apple_gpio_pinctrl *pctl = struct apple_gpio_pinctrl *pctl =
gpiochip_get_data(irq_data_get_irq_chip_data(data)); gpiochip_get_data(irq_data_get_irq_chip_data(data));
int irqtype = apple_gpio_irq_type(type); unsigned int irqtype = apple_gpio_irq_type(type);
if (irqtype < 0) if (irqtype == REG_GPIOx_IN_IRQ_OFF)
return irqtype; return -EINVAL;
apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE, apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE,
FIELD_PREP(REG_GPIOx_MODE, irqtype)); FIELD_PREP(REG_GPIOx_MODE, irqtype));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment