All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roel Kluin <roel.kluin@gmail.com>
To: "Du, Alek" <alek.du@intel.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] gpio: Fix test on unsigned in lnw_irq_type()
Date: Wed, 14 Oct 2009 19:16:38 +0200	[thread overview]
Message-ID: <4AD60776.5090404@gmail.com> (raw)
In-Reply-To: <EADF0A36011179459010BDF5142A457501CEC48E76@pdsmsx502.ccr.corp.intel.com>

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)

  parent reply	other threads:[~2009-10-14 17:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2009-10-15  0:52               ` Du, Alek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4AD60776.5090404@gmail.com \
    --to=roel.kluin@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=alek.du@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.