linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pinctrl: apple: Always return valid type in apple_gpio_irq_type
@ 2021-11-01 15:06 Sven Peter
  2021-11-01 15:18 ` Joey Gouly
  2021-11-09 11:05 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Sven Peter @ 2021-11-01 15:06 UTC (permalink / raw)
  To: Hector Martin, Sven Peter, Linus Walleij, Joey Gouly
  Cc: Alyssa Rosenzweig, Marc Zyngier, linux-arm-kernel, linux-gpio,
	linux-kernel

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: a0f160ffcb83 ("pinctrl: add pinctrl/GPIO driver for Apple SoCs")
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
 drivers/pinctrl/pinctrl-apple-gpio.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c
index 0cc346bfc4c3..a7861079a650 100644
--- a/drivers/pinctrl/pinctrl-apple-gpio.c
+++ b/drivers/pinctrl/pinctrl-apple-gpio.c
@@ -258,7 +258,7 @@ static void apple_gpio_irq_ack(struct irq_data *data)
 	       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) {
 	case IRQ_TYPE_EDGE_RISING:
@@ -272,7 +272,7 @@ static int apple_gpio_irq_type(unsigned int type)
 	case IRQ_TYPE_LEVEL_LOW:
 		return REG_GPIOx_IN_IRQ_LO;
 	default:
-		return -EINVAL;
+		return REG_GPIOx_IN_IRQ_OFF;
 	}
 }
 
@@ -288,7 +288,7 @@ static void apple_gpio_irq_unmask(struct irq_data *data)
 {
 	struct apple_gpio_pinctrl *pctl =
 		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,
 			   FIELD_PREP(REG_GPIOx_MODE, irqtype));
@@ -313,10 +313,10 @@ static int apple_gpio_irq_set_type(struct irq_data *data,
 {
 	struct apple_gpio_pinctrl *pctl =
 		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)
-		return irqtype;
+	if (irqtype == REG_GPIOx_IN_IRQ_OFF)
+		return -EINVAL;
 
 	apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE,
 			   FIELD_PREP(REG_GPIOx_MODE, irqtype));
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: apple: Always return valid type in apple_gpio_irq_type
  2021-11-01 15:06 [PATCH] pinctrl: apple: Always return valid type in apple_gpio_irq_type Sven Peter
@ 2021-11-01 15:18 ` Joey Gouly
  2021-11-09 11:05 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Joey Gouly @ 2021-11-01 15:18 UTC (permalink / raw)
  To: Sven Peter
  Cc: Hector Martin, Linus Walleij, Alyssa Rosenzweig, Marc Zyngier,
	linux-arm-kernel, linux-gpio, linux-kernel, nd

Hi Sven,

On Mon, Nov 01, 2021 at 04:06:40PM +0100, Sven Peter wrote:
> 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: a0f160ffcb83 ("pinctrl: add pinctrl/GPIO driver for Apple SoCs")
> Signed-off-by: Sven Peter <sven@svenpeter.dev>
> ---
>  drivers/pinctrl/pinctrl-apple-gpio.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c
> index 0cc346bfc4c3..a7861079a650 100644
> --- a/drivers/pinctrl/pinctrl-apple-gpio.c
> +++ b/drivers/pinctrl/pinctrl-apple-gpio.c
> @@ -258,7 +258,7 @@ static void apple_gpio_irq_ack(struct irq_data *data)
>  	       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) {
>  	case IRQ_TYPE_EDGE_RISING:
> @@ -272,7 +272,7 @@ static int apple_gpio_irq_type(unsigned int type)
>  	case IRQ_TYPE_LEVEL_LOW:
>  		return REG_GPIOx_IN_IRQ_LO;
>  	default:
> -		return -EINVAL;
> +		return REG_GPIOx_IN_IRQ_OFF;
>  	}
>  }
>  
> @@ -288,7 +288,7 @@ static void apple_gpio_irq_unmask(struct irq_data *data)
>  {
>  	struct apple_gpio_pinctrl *pctl =
>  		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,
>  			   FIELD_PREP(REG_GPIOx_MODE, irqtype));
> @@ -313,10 +313,10 @@ static int apple_gpio_irq_set_type(struct irq_data *data,
>  {
>  	struct apple_gpio_pinctrl *pctl =
>  		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)
> -		return irqtype;
> +	if (irqtype == REG_GPIOx_IN_IRQ_OFF)
> +		return -EINVAL;
>  
>  	apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE,
>  			   FIELD_PREP(REG_GPIOx_MODE, irqtype));
> -- 
> 2.25.1
> 

This was previously reported, but was miscategorised it as a compiler bug, so thanks for fixing this!

Reviewed-by: Joey Gouly <joey.gouly@arm.com>

Thanks,
Joey

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: apple: Always return valid type in apple_gpio_irq_type
  2021-11-01 15:06 [PATCH] pinctrl: apple: Always return valid type in apple_gpio_irq_type Sven Peter
  2021-11-01 15:18 ` Joey Gouly
@ 2021-11-09 11:05 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2021-11-09 11:05 UTC (permalink / raw)
  To: Sven Peter
  Cc: Hector Martin, Joey Gouly, Alyssa Rosenzweig, Marc Zyngier,
	linux-arm-kernel, linux-gpio, linux-kernel

On Mon, Nov 1, 2021 at 4:07 PM Sven Peter <sven@svenpeter.dev> wrote:

> 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.

Patch applied for fixes, thanks for fixing this!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-09 11:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-01 15:06 [PATCH] pinctrl: apple: Always return valid type in apple_gpio_irq_type Sven Peter
2021-11-01 15:18 ` Joey Gouly
2021-11-09 11:05 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).