linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Colin Ian King <colin.king-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
To: Romain Perier
	<romain.perier-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] spi: armada-3700: fix unsigned compare than zero on irq
Date: Tue, 13 Dec 2016 11:01:52 +0000	[thread overview]
Message-ID: <47d82067-0a4c-32e9-fe78-16f2e6735aa6@canonical.com> (raw)
In-Reply-To: <c173347e-c93b-2652-0b10-14e85d5f96bd-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>

On 13/12/16 10:55, Romain Perier wrote:
> Hello,
> 
> Le 13/12/2016 à 11:28, Colin King a écrit :
>> From: Colin Ian King <colin.king-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
>>
>> spi->irq is an unsigned integer hence the check if status is less than
>> zero has no effect.  Fix this by replacing spi->irq with an int irq
>> so the less than zero compare will correctly detect errors.
>>
>> Issue found with static analysis with CoverityScan, CID1388567
>>
>> Signed-off-by: Colin Ian King <colin.king-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
>> ---
>>  drivers/spi/spi-armada-3700.c | 9 +++++----
>>  1 file changed, 5 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/spi/spi-armada-3700.c
>> b/drivers/spi/spi-armada-3700.c
>> index e89da0a..4e92178 100644
>> --- a/drivers/spi/spi-armada-3700.c
>> +++ b/drivers/spi/spi-armada-3700.c
>> @@ -800,7 +800,7 @@ static int a3700_spi_probe(struct platform_device
>> *pdev)
>>      struct spi_master *master;
>>      struct a3700_spi *spi;
>>      u32 num_cs = 0;
>> -    int ret = 0;
>> +    int irq, ret = 0;
>>
>>      master = spi_alloc_master(dev, sizeof(*spi));
>>      if (!master) {
>> @@ -846,12 +846,13 @@ static int a3700_spi_probe(struct
>> platform_device *pdev)
>>          goto error;
>>      }
>>
>> -    spi->irq = platform_get_irq(pdev, 0);
>> -    if (spi->irq < 0) {
>> -        dev_err(dev, "could not get irq: %d\n", spi->irq);
>> +    irq = platform_get_irq(pdev, 0);
>> +    if (irq < 0) {
>> +        dev_err(dev, "could not get irq: %d\n", irq);
>>          ret = -ENXIO;
>>          goto error;
>>      }
>> +    spi->irq = irq;
>>
>>      init_completion(&spi->done);
>>
>>
> 
> Why don't you change only the type of "irq" in struct a3700_spi ?
> 
> Thanks,
> Romain

..because I've observed that a lot of driver seems to use a unsigned int
for the irq in their driver specific structs and I also didn't want to
modify this to an int in case it some subtle signed/unsigned logic
somewhere else that I was not aware of. Just seemed like the least risky
fix to me.

Colin

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2016-12-13 11:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-13 10:28 [PATCH] spi: armada-3700: fix unsigned compare than zero on irq Colin King
     [not found] ` <20161213102812.9029-1-colin.king-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
2016-12-13 10:55   ` Romain Perier
     [not found]     ` <c173347e-c93b-2652-0b10-14e85d5f96bd-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>
2016-12-13 11:01       ` Colin Ian King [this message]
2016-12-13 11:02       ` Romain Perier
2016-12-14 18:03 ` Applied "spi: armada-3700: fix unsigned compare than zero on irq" to the spi tree Mark Brown

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=47d82067-0a4c-32e9-fe78-16f2e6735aa6@canonical.com \
    --to=colin.king-z7wlfzj8ewms+fvcfc7uqw@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=romain.perier-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.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 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).