linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@free-electrons.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Jonathan Cameron <jic23@kernel.org>,
	Grant Likely <grant.likely@linaro.org>,
	Rob Herring <robh+dt@kernel.org>, Josh Wu <josh.wu@atmel.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 v2] iio: adc: at91: signedness bug in at91_adc_get_trigger_value_by_name()
Date: Wed, 11 Jun 2014 16:41:41 +0200	[thread overview]
Message-ID: <20140611144141.GH3429@piout.net> (raw)
In-Reply-To: <20140611081317.GA29444@mwanda>

On 11/06/2014 at 11:13:17 +0300, Dan Carpenter wrote :
> at91_adc_get_trigger_value_by_name() was returning -ENOMEM truncated to
> a positive u8 and that doesn't work.  I've changed it to int and
> refactored it to preserve the error code.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

Also, tested on an at91sam9g45ek.

> ---
> I'm not able to compile this code.
> 
> v2:  Preserve the -ENOMEM
> 
> diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
> index 3b5bacd..2b6a9ce 100644
> --- a/drivers/iio/adc/at91_adc.c
> +++ b/drivers/iio/adc/at91_adc.c
> @@ -510,12 +510,11 @@ static int at91_adc_channel_init(struct iio_dev *idev)
>  	return idev->num_channels;
>  }
>  
> -static u8 at91_adc_get_trigger_value_by_name(struct iio_dev *idev,
> +static int at91_adc_get_trigger_value_by_name(struct iio_dev *idev,
>  					     struct at91_adc_trigger *triggers,
>  					     const char *trigger_name)
>  {
>  	struct at91_adc_state *st = iio_priv(idev);
> -	u8 value = 0;
>  	int i;
>  
>  	for (i = 0; i < st->trigger_number; i++) {
> @@ -528,15 +527,16 @@ static u8 at91_adc_get_trigger_value_by_name(struct iio_dev *idev,
>  			return -ENOMEM;
>  
>  		if (strcmp(trigger_name, name) == 0) {
> -			value = triggers[i].value;
>  			kfree(name);
> -			break;
> +			if (triggers[i].value == 0)
> +				return -EINVAL;
> +			return triggers[i].value;
>  		}
>  
>  		kfree(name);
>  	}
>  
> -	return value;
> +	return -EINVAL;
>  }
>  
>  static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state)
> @@ -546,14 +546,14 @@ static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state)
>  	struct iio_buffer *buffer = idev->buffer;
>  	struct at91_adc_reg_desc *reg = st->registers;
>  	u32 status = at91_adc_readl(st, reg->trigger_register);
> -	u8 value;
> +	int value;
>  	u8 bit;
>  
>  	value = at91_adc_get_trigger_value_by_name(idev,
>  						   st->trigger_list,
>  						   idev->trig->name);
> -	if (value == 0)
> -		return -EINVAL;
> +	if (value < 0)
> +		return value;
>  
>  	if (state) {
>  		st->buffer = kmalloc(idev->scan_bytes, GFP_KERNEL);

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

  reply	other threads:[~2014-06-11 14:41 UTC|newest]

Thread overview: 7+ 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  7:36 ` walter harms
2014-06-11  8:12   ` Dan Carpenter
2014-06-11  8:27     ` walter harms
2014-06-11  8:13   ` [patch v2] " Dan Carpenter
2014-06-11 14:41     ` Alexandre Belloni [this message]
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=20140611144141.GH3429@piout.net \
    --to=alexandre.belloni@free-electrons.com \
    --cc=dan.carpenter@oracle.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=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 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).