Skip to content

Commit

Permalink
iio: accel: mma9553: check input value for activity period
Browse files Browse the repository at this point in the history
When setting the activity period, the value introduced by
the user in sysfs is not checked for validity.

Add a boundary check so that only allowed values are
reported as successfully written to device.

Signed-off-by: Irina Tirdea <[email protected]>
Reported-by: Hartmut Knaack <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
itirdea authored and jic23 committed Apr 26, 2015
1 parent ae2ec95 commit 1d93353
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions drivers/iio/accel/mma9553.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#define MMA9553_MASK_CONF_STEPCOALESCE GENMASK(7, 0)

#define MMA9553_REG_CONF_ACTTHD 0x0E
#define MMA9553_MAX_ACTTHD GENMASK(15, 0)

/* Pedometer status registers (R-only) */
#define MMA9553_REG_STATUS 0x00
Expand Down Expand Up @@ -869,6 +870,9 @@ static int mma9553_write_event_value(struct iio_dev *indio_dev,
case IIO_EV_INFO_PERIOD:
switch (chan->type) {
case IIO_ACTIVITY:
if (val < 0 || val > MMA9553_ACTIVITY_THD_TO_SEC(
MMA9553_MAX_ACTTHD))
return -EINVAL;
mutex_lock(&data->mutex);
ret = mma9553_set_config(data, MMA9553_REG_CONF_ACTTHD,
&data->conf.actthd,
Expand Down

0 comments on commit 1d93353

Please sign in to comment.