Skip to content

Commit

Permalink
iio: adc: at91: signedness bug in at91_adc_get_trigger_value_by_name()
Browse files Browse the repository at this point in the history
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>
Tested-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Cc: Stable@vger.kernel.org
  • Loading branch information
Dan Carpenter authored and Jonathan Cameron committed Jun 14, 2014
1 parent 19bc498 commit 4f3bcd8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions drivers/iio/adc/at91_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,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++) {
Expand All @@ -340,15 +339,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)
Expand All @@ -358,14 +358,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);
Expand Down

0 comments on commit 4f3bcd8

Please sign in to comment.