diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2014-11-06 04:13:00 -0500 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2014-06-14 10:31:20 -0400 |
commit | 4f3bcd878f1d3c730fe00f619b7260c6125d49eb (patch) | |
tree | a1cca2b92384c509819893f9931fd8b48d8c824c /drivers/iio/adc | |
parent | 19bc4981a213d0c5b0e1e8b08815c0b26f01ec54 (diff) |
iio: adc: at91: signedness bug in at91_adc_get_trigger_value_by_name()
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
Diffstat (limited to 'drivers/iio/adc')
-rw-r--r-- | drivers/iio/adc/at91_adc.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c index 89777ed9abd8..be0b2accf895 100644 --- a/drivers/iio/adc/at91_adc.c +++ b/drivers/iio/adc/at91_adc.c | |||
@@ -322,12 +322,11 @@ static int at91_adc_channel_init(struct iio_dev *idev) | |||
322 | return idev->num_channels; | 322 | return idev->num_channels; |
323 | } | 323 | } |
324 | 324 | ||
325 | static u8 at91_adc_get_trigger_value_by_name(struct iio_dev *idev, | 325 | static int at91_adc_get_trigger_value_by_name(struct iio_dev *idev, |
326 | struct at91_adc_trigger *triggers, | 326 | struct at91_adc_trigger *triggers, |
327 | const char *trigger_name) | 327 | const char *trigger_name) |
328 | { | 328 | { |
329 | struct at91_adc_state *st = iio_priv(idev); | 329 | struct at91_adc_state *st = iio_priv(idev); |
330 | u8 value = 0; | ||
331 | int i; | 330 | int i; |
332 | 331 | ||
333 | for (i = 0; i < st->trigger_number; i++) { | 332 | for (i = 0; i < st->trigger_number; i++) { |
@@ -340,15 +339,16 @@ static u8 at91_adc_get_trigger_value_by_name(struct iio_dev *idev, | |||
340 | return -ENOMEM; | 339 | return -ENOMEM; |
341 | 340 | ||
342 | if (strcmp(trigger_name, name) == 0) { | 341 | if (strcmp(trigger_name, name) == 0) { |
343 | value = triggers[i].value; | ||
344 | kfree(name); | 342 | kfree(name); |
345 | break; | 343 | if (triggers[i].value == 0) |
344 | return -EINVAL; | ||
345 | return triggers[i].value; | ||
346 | } | 346 | } |
347 | 347 | ||
348 | kfree(name); | 348 | kfree(name); |
349 | } | 349 | } |
350 | 350 | ||
351 | return value; | 351 | return -EINVAL; |
352 | } | 352 | } |
353 | 353 | ||
354 | static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) | 354 | static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) |
@@ -358,14 +358,14 @@ static int at91_adc_configure_trigger(struct iio_trigger *trig, bool state) | |||
358 | struct iio_buffer *buffer = idev->buffer; | 358 | struct iio_buffer *buffer = idev->buffer; |
359 | struct at91_adc_reg_desc *reg = st->registers; | 359 | struct at91_adc_reg_desc *reg = st->registers; |
360 | u32 status = at91_adc_readl(st, reg->trigger_register); | 360 | u32 status = at91_adc_readl(st, reg->trigger_register); |
361 | u8 value; | 361 | int value; |
362 | u8 bit; | 362 | u8 bit; |
363 | 363 | ||
364 | value = at91_adc_get_trigger_value_by_name(idev, | 364 | value = at91_adc_get_trigger_value_by_name(idev, |
365 | st->trigger_list, | 365 | st->trigger_list, |
366 | idev->trig->name); | 366 | idev->trig->name); |
367 | if (value == 0) | 367 | if (value < 0) |
368 | return -EINVAL; | 368 | return value; |
369 | 369 | ||
370 | if (state) { | 370 | if (state) { |
371 | st->buffer = kmalloc(idev->scan_bytes, GFP_KERNEL); | 371 | st->buffer = kmalloc(idev->scan_bytes, GFP_KERNEL); |