All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: walter harms <wharms@bfs.de>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Grant Likely <grant.likely@linaro.org>,
	Rob Herring <robh+dt@kernel.org>, Josh Wu <josh.wu@atmel.com>,
	Alexandre Belloni <alexandre.belloni@free-electrons.com>,
	Nicolas Ferre <nicolas.ferre@atmel.com>,
	Maxime Ripard <maxime.ripard@free-electrons.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Thomas Meyer <thomas@m3y3r.de>,
	Wei Yongjun <yongjun_wei@trendmicro.com.cn>,
	Sachin Kamat <sachin.kamat@linaro.org>,
	linux-iio@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] iio: adc: at91: signedness bug in at91_adc_get_trigger_value_by_name()
Date: Wed, 11 Jun 2014 08:12:21 +0000	[thread overview]
Message-ID: <20140611081220.GP5500@mwanda> (raw)
In-Reply-To: <53980711.5030604@bfs.de>

On Wed, Jun 11, 2014 at 09:36:49AM +0200, walter harms wrote:
> 
> 
> Am 11.06.2014 08:53, schrieb Dan Carpenter:
> > The function returns a u8 so the -ENOMEM is truncated to a positive
> > value.  The caller tests for zero returns and treats them as an error
> > so I have changed the -ENOMEM to 0.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
> > index 3b5bacd..5ebe33d 100644
> > --- a/drivers/iio/adc/at91_adc.c
> > +++ b/drivers/iio/adc/at91_adc.c
> > @@ -525,7 +525,7 @@ static u8 at91_adc_get_trigger_value_by_name(struct iio_dev *idev,
> >  				idev->id,
> >  				triggers[i].name);
> >  		if (!name)
> > -			return -ENOMEM;
> > +			return 0;
> >  
> >  		if (strcmp(trigger_name, name) = 0) {
> >  			value = triggers[i].value;
> 
> 
> hi Dan,
> LXR says there is only 1 caller (and he is checking for ENOMON)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
No, it's not?  It's checking for zero.

> perhaps it is better to change  the return value to int.

In theory, it's always better to preserve the error code but in real
life, this memory allocation is going to succeed.  I'm not able to
compile this code, and that change is quite a bit more involved, but
I'll send it anyway.

regards,
dan carpenter


WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: walter harms <wharms@bfs.de>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Grant Likely <grant.likely@linaro.org>,
	Rob Herring <robh+dt@kernel.org>, Josh Wu <josh.wu@atmel.com>,
	Alexandre Belloni <alexandre.belloni@free-electrons.com>,
	Nicolas Ferre <nicolas.ferre@atmel.com>,
	Maxime Ripard <maxime.ripard@free-electrons.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Thomas Meyer <thomas@m3y3r.de>,
	Wei Yongjun <yongjun_wei@trendmicro.com.cn>,
	Sachin Kamat <sachin.kamat@linaro.org>,
	linux-iio@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [patch] iio: adc: at91: signedness bug in at91_adc_get_trigger_value_by_name()
Date: Wed, 11 Jun 2014 11:12:21 +0300	[thread overview]
Message-ID: <20140611081220.GP5500@mwanda> (raw)
In-Reply-To: <53980711.5030604@bfs.de>

On Wed, Jun 11, 2014 at 09:36:49AM +0200, walter harms wrote:
> 
> 
> Am 11.06.2014 08:53, schrieb Dan Carpenter:
> > The function returns a u8 so the -ENOMEM is truncated to a positive
> > value.  The caller tests for zero returns and treats them as an error
> > so I have changed the -ENOMEM to 0.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > 
> > diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
> > index 3b5bacd..5ebe33d 100644
> > --- a/drivers/iio/adc/at91_adc.c
> > +++ b/drivers/iio/adc/at91_adc.c
> > @@ -525,7 +525,7 @@ static u8 at91_adc_get_trigger_value_by_name(struct iio_dev *idev,
> >  				idev->id,
> >  				triggers[i].name);
> >  		if (!name)
> > -			return -ENOMEM;
> > +			return 0;
> >  
> >  		if (strcmp(trigger_name, name) == 0) {
> >  			value = triggers[i].value;
> 
> 
> hi Dan,
> LXR says there is only 1 caller (and he is checking for ENOMON)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
No, it's not?  It's checking for zero.

> perhaps it is better to change  the return value to int.

In theory, it's always better to preserve the error code but in real
life, this memory allocation is going to succeed.  I'm not able to
compile this code, and that change is quite a bit more involved, but
I'll send it anyway.

regards,
dan carpenter


  reply	other threads:[~2014-06-11  8:12 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-11  6:53 [patch] iio: adc: at91: signedness bug in at91_adc_get_trigger_value_by_name() Dan Carpenter
2014-06-11  6:53 ` Dan Carpenter
2014-06-11  7:36 ` walter harms
2014-06-11  7:36   ` walter harms
2014-06-11  8:12   ` Dan Carpenter [this message]
2014-06-11  8:12     ` Dan Carpenter
2014-06-11  8:27     ` walter harms
2014-06-11  8:27       ` walter harms
2014-06-11  8:13   ` [patch v2] " Dan Carpenter
2014-06-11  8:13     ` Dan Carpenter
2014-06-11 14:41     ` Alexandre Belloni
2014-06-11 14:41       ` Alexandre Belloni
2014-06-14 14:38       ` Jonathan Cameron
2014-06-14 14:38         ` Jonathan Cameron

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=20140611081220.GP5500@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=grant.likely@linaro.org \
    --cc=jic23@kernel.org \
    --cc=josh.wu@atmel.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=maxime.ripard@free-electrons.com \
    --cc=nicolas.ferre@atmel.com \
    --cc=robh+dt@kernel.org \
    --cc=sachin.kamat@linaro.org \
    --cc=thomas@m3y3r.de \
    --cc=wharms@bfs.de \
    --cc=yongjun_wei@trendmicro.com.cn \
    /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.