All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: Fix test on unsigned in lnw_irq_type()
@ 2009-10-12 14:12 Roel Kluin
  2009-10-12 22:11 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Roel Kluin @ 2009-10-12 14:12 UTC (permalink / raw)
  To: alek.du, Andrew Morton, LKML

The wrong test was used, gpio is unsigned.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
diff --git a/drivers/gpio/langwell_gpio.c b/drivers/gpio/langwell_gpio.c
index 5711ce5..0d0cbc0 100644
--- a/drivers/gpio/langwell_gpio.c
+++ b/drivers/gpio/langwell_gpio.c
@@ -123,8 +123,11 @@ static int lnw_irq_type(unsigned irq, unsigned type)
 	void __iomem *grer = (void __iomem *)(&lnw->reg_base->GRER[reg]);
 	void __iomem *gfer = (void __iomem *)(&lnw->reg_base->GFER[reg]);
 
-	if (gpio < 0 || gpio > lnw->chip.ngpio)
+	if (irq < lnw->irq_base || gpio > lnw->chip.ngpio ||
+			reg >= ARRAY_SIZE(lnw->reg_base->GRER)
+			reg >= ARRAY_SIZE(lnw->reg_base->GFER))
 		return -EINVAL;
+
 	spin_lock_irqsave(&lnw->lock, flags);
 	if (type & IRQ_TYPE_EDGE_RISING)
 		value = readl(grer) | BIT(gpio % 32);

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

* Re: [PATCH] gpio: Fix test on unsigned in lnw_irq_type()
  2009-10-12 14:12 [PATCH] gpio: Fix test on unsigned in lnw_irq_type() Roel Kluin
@ 2009-10-12 22:11 ` Andrew Morton
       [not found]   ` <EADF0A36011179459010BDF5142A457501CEB8C146@pdsmsx502.ccr.corp.intel.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2009-10-12 22:11 UTC (permalink / raw)
  To: Roel Kluin; +Cc: alek.du, LKML

On Mon, 12 Oct 2009 16:12:40 +0200
Roel Kluin <roel.kluin@gmail.com> wrote:

> The wrong test was used, gpio is unsigned.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
> ---
> diff --git a/drivers/gpio/langwell_gpio.c b/drivers/gpio/langwell_gpio.c
> index 5711ce5..0d0cbc0 100644
> --- a/drivers/gpio/langwell_gpio.c
> +++ b/drivers/gpio/langwell_gpio.c
> @@ -123,8 +123,11 @@ static int lnw_irq_type(unsigned irq, unsigned type)
>  	void __iomem *grer = (void __iomem *)(&lnw->reg_base->GRER[reg]);
>  	void __iomem *gfer = (void __iomem *)(&lnw->reg_base->GFER[reg]);
>  
> -	if (gpio < 0 || gpio > lnw->chip.ngpio)
> +	if (irq < lnw->irq_base || gpio > lnw->chip.ngpio ||
> +			reg >= ARRAY_SIZE(lnw->reg_base->GRER)
> +			reg >= ARRAY_SIZE(lnw->reg_base->GFER))
>  		return -EINVAL;
> +
>  	spin_lock_irqsave(&lnw->lock, flags);
>  	if (type & IRQ_TYPE_EDGE_RISING)
>  		value = readl(grer) | BIT(gpio % 32);

Makes the code unfortunately complex.  It'd be better to make `gpio' a
signed quantity, or even..

--- a/drivers/gpio/langwell_gpio.c~gpio-fix-test-on-unsigned-in-lnw_irq_type
+++ a/drivers/gpio/langwell_gpio.c
@@ -123,7 +123,7 @@ static int lnw_irq_type(unsigned irq, un
 	void __iomem *grer = (void __iomem *)(&lnw->reg_base->GRER[reg]);
 	void __iomem *gfer = (void __iomem *)(&lnw->reg_base->GFER[reg]);
 
-	if (gpio < 0 || gpio > lnw->chip.ngpio)
+	if ((s32)gpio < 0 || gpio > lnw->chip.ngpio)
 		return -EINVAL;
 	spin_lock_irqsave(&lnw->lock, flags);
 	if (type & IRQ_TYPE_EDGE_RISING)
_


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

* Re: [PATCH] gpio: Fix test on unsigned in lnw_irq_type()
       [not found]           ` <EADF0A36011179459010BDF5142A457501CEC48E76@pdsmsx502.ccr.corp.intel.com>
@ 2009-10-14 17:16             ` Roel Kluin
  2009-10-15  0:52               ` Du, Alek
  0 siblings, 1 reply; 4+ messages in thread
From: Roel Kluin @ 2009-10-14 17:16 UTC (permalink / raw)
  To: Du, Alek, Andrew Morton, LKML

The wrong test was used, gpio is unsigned. Also lnw->chip.ngpio is
set to 64, so if gpio equals that, then reg (= gpio / 32) becomes 2,
an index out of bounds for GRER and GFER that have 2 elements.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
>>>> From: Andrew Morton [mailto:akpm@linux-foundation.org]
>>>>> -    if (gpio < 0 || gpio > lnw->chip.ngpio)
>>>>> +    if (gpio > lnw->chip.ngpio)
>>>>>              return -EINVAL;
>>>>
>>>> Should that be >= ?

> Oh, my bad. Andrew is right, should be >=...

Ok, how about this then?

diff --git a/drivers/gpio/langwell_gpio.c b/drivers/gpio/langwell_gpio.c
index 5711ce5..72af3fc 100644
--- a/drivers/gpio/langwell_gpio.c
+++ b/drivers/gpio/langwell_gpio.c
@@ -123,7 +123,7 @@ static int lnw_irq_type(unsigned irq, unsigned type)
 	void __iomem *grer = (void __iomem *)(&lnw->reg_base->GRER[reg]);
 	void __iomem *gfer = (void __iomem *)(&lnw->reg_base->GFER[reg]);
 
-	if (gpio < 0 || gpio > lnw->chip.ngpio)
+	if (gpio >= lnw->chip.ngpio)
 		return -EINVAL;
 	spin_lock_irqsave(&lnw->lock, flags);
 	if (type & IRQ_TYPE_EDGE_RISING)

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

* RE: [PATCH] gpio: Fix test on unsigned in lnw_irq_type()
  2009-10-14 17:16             ` Roel Kluin
@ 2009-10-15  0:52               ` Du, Alek
  0 siblings, 0 replies; 4+ messages in thread
From: Du, Alek @ 2009-10-15  0:52 UTC (permalink / raw)
  To: Roel Kluin, Andrew Morton, LKML



>-----Original Message-----
>From: Roel Kluin [mailto:roel.kluin@gmail.com]
>Sent: Thursday, October 15, 2009 1:17 AM
>To: Du, Alek; Andrew Morton; LKML
>Subject: Re: [PATCH] gpio: Fix test on unsigned in lnw_irq_type()
>
>The wrong test was used, gpio is unsigned. Also lnw->chip.ngpio is
>set to 64, so if gpio equals that, then reg (= gpio / 32) becomes 2,
>an index out of bounds for GRER and GFER that have 2 elements.
>
>Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
>---
>>>>> From: Andrew Morton [mailto:akpm@linux-foundation.org]
>>>>>> -    if (gpio < 0 || gpio > lnw->chip.ngpio)
>>>>>> +    if (gpio > lnw->chip.ngpio)
>>>>>>              return -EINVAL;
>>>>>
>>>>> Should that be >= ?
>
>> Oh, my bad. Andrew is right, should be >=...
>
>Ok, how about this then?
>
>diff --git a/drivers/gpio/langwell_gpio.c b/drivers/gpio/langwell_gpio.c
>index 5711ce5..72af3fc 100644
>--- a/drivers/gpio/langwell_gpio.c
>+++ b/drivers/gpio/langwell_gpio.c
>@@ -123,7 +123,7 @@ static int lnw_irq_type(unsigned irq, unsigned type)
> 	void __iomem *grer = (void __iomem *)(&lnw->reg_base->GRER[reg]);
> 	void __iomem *gfer = (void __iomem *)(&lnw->reg_base->GFER[reg]);
>
>-	if (gpio < 0 || gpio > lnw->chip.ngpio)
>+	if (gpio >= lnw->chip.ngpio)
> 		return -EINVAL;
> 	spin_lock_irqsave(&lnw->lock, flags);
> 	if (type & IRQ_TYPE_EDGE_RISING)

Acked-by: Alek Du <alek.du@intel.com>




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

end of thread, other threads:[~2009-10-15  0:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-12 14:12 [PATCH] gpio: Fix test on unsigned in lnw_irq_type() Roel Kluin
2009-10-12 22:11 ` Andrew Morton
     [not found]   ` <EADF0A36011179459010BDF5142A457501CEB8C146@pdsmsx502.ccr.corp.intel.com>
     [not found]     ` <20091013105901.972f7dbe.akpm@linux-foundation.org>
     [not found]       ` <EADF0A36011179459010BDF5142A457501CEC48A68@pdsmsx502.ccr.corp.intel.com>
     [not found]         ` <25e057c00910140850j787e9fd6lcd6ac236a0f4851d@mail.gmail.com>
     [not found]           ` <EADF0A36011179459010BDF5142A457501CEC48E76@pdsmsx502.ccr.corp.intel.com>
2009-10-14 17:16             ` Roel Kluin
2009-10-15  0:52               ` Du, Alek

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.