Skip to content

Commit

Permalink
iio: maxim_thermocouple: detect invalid storage size in read()
Browse files Browse the repository at this point in the history
As found by gcc -Wmaybe-uninitialized, having a storage_bytes value other
than 2 or 4 will result in undefined behavior:

drivers/iio/temperature/maxim_thermocouple.c: In function 'maxim_thermocouple_read':
drivers/iio/temperature/maxim_thermocouple.c:141:5: error: 'ret' may be used uninitialized in this function [-Werror=maybe-uninitialized]

This probably cannot happen, but returning -EINVAL here is appropriate
and makes gcc happy and the code more robust.

Fixes: 231147e ("iio: maxim_thermocouple: Align 16 bit big endian value of raw reads")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
  • Loading branch information
Arnd Bergmann authored and Jonathan Cameron committed Oct 25, 2016
1 parent 3089ec2 commit 32cb7d2
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/iio/temperature/maxim_thermocouple.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ static int maxim_thermocouple_read(struct maxim_thermocouple_data *data,
case 4:
*val = be32_to_cpu(buf);
break;
default:
ret = -EINVAL;
}

/* check to be sure this is a valid reading */
Expand Down

0 comments on commit 32cb7d2

Please sign in to comment.