summaryrefslogtreecommitdiffstats
path: root/drivers/iio/industrialio-event.c
diff options
context:
space:
mode:
authorJonathan Cameron <jic23@kernel.org>2014-01-03 23:24:00 +0100
committerJonathan Cameron <jic23@kernel.org>2014-03-16 19:00:35 +0100
commitef4b4856593fc3d9d169bededdaf7acf62f83a52 (patch)
tree475540e4f92024899b4ab3b4b2469b9884503ff5 /drivers/iio/industrialio-event.c
parentAdd support for Microchip Technology's MCP3426/7/8 ADC (diff)
downloadlinux-ef4b4856593fc3d9d169bededdaf7acf62f83a52.tar.xz
linux-ef4b4856593fc3d9d169bededdaf7acf62f83a52.zip
iio:core: Fix bug in length of event info_mask and catch unhandled bits set in masks.
The unhandled bits case was highlighted by smatch: CHECK drivers/iio/industrialio-core.c drivers/iio/industrialio-core.c:719 iio_device_add_info_mask_type() error: buffer overflow 'iio_chan_info_postfix' 17 <= 31 CC [M] drivers/iio/industrialio-core.o CHECK drivers/iio/industrialio-event.c drivers/iio/industrialio-event.c:327 iio_device_add_event() error: buffer overflow 'iio_ev_info_text' 3 <= 3 The incorrect limit for the for_each_set_bit loop was noticed whilst fixing this other case. Note that as we only have 3 possible entries a the moment and the value was set to 4, the bug would not have any effect currently. It will bite fairly soon though, so best fix it now. Signed-off-by: Jonathan Cameron <jic23@kernel.org> Cc: Lars-Peter Clausen <lars@metafoo.de> Cc: Dan Carpenter <dan.carpenter@oracle.com>
Diffstat (limited to 'drivers/iio/industrialio-event.c')
-rw-r--r--drivers/iio/industrialio-event.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
index ea6e06b9c7d4..dddfb0f90d34 100644
--- a/drivers/iio/industrialio-event.c
+++ b/drivers/iio/industrialio-event.c
@@ -321,7 +321,9 @@ static int iio_device_add_event(struct iio_dev *indio_dev,
char *postfix;
int ret;
- for_each_set_bit(i, mask, sizeof(*mask)) {
+ for_each_set_bit(i, mask, sizeof(*mask)*8) {
+ if (i >= ARRAY_SIZE(iio_ev_info_text))
+ return -EINVAL;
postfix = kasprintf(GFP_KERNEL, "%s_%s_%s",
iio_ev_type_text[type], iio_ev_dir_text[dir],
iio_ev_info_text[i]);