Commit 84b2e7c3 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Jonathan Cameron

iio: imu: st_lsm6dsx: always check enable_reg in st_lsm6dsx_event_setup

Check if enable_reg of event_settings data structure is defined before
writing on it

Fixes: b5969abf ("iio: imu: st_lsm6dsx: add motion events")
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Tested-by: default avatarSean Nyekjaer <sean@geanix.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 66b662a1
...@@ -1497,26 +1497,25 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev, ...@@ -1497,26 +1497,25 @@ static int st_lsm6dsx_write_raw(struct iio_dev *iio_dev,
static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state) static int st_lsm6dsx_event_setup(struct st_lsm6dsx_hw *hw, int state)
{ {
const struct st_lsm6dsx_reg *reg;
int err; int err;
u8 enable = 0;
if (!hw->settings->irq_config.irq1_func.addr) if (!hw->settings->irq_config.irq1_func.addr)
return -ENOTSUPP; return -ENOTSUPP;
enable = state ? hw->settings->event_settings.enable_reg.mask : 0; reg = &hw->settings->event_settings.enable_reg;
if (reg->addr) {
err = regmap_update_bits(hw->regmap, err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
hw->settings->event_settings.enable_reg.addr, ST_LSM6DSX_SHIFT_VAL(state, reg->mask));
hw->settings->event_settings.enable_reg.mask, if (err < 0)
enable); return err;
if (err < 0) }
return err;
enable = state ? hw->irq_routing->mask : 0;
/* Enable wakeup interrupt */ /* Enable wakeup interrupt */
return regmap_update_bits(hw->regmap, hw->irq_routing->addr, return regmap_update_bits(hw->regmap, hw->irq_routing->addr,
hw->irq_routing->mask, enable); hw->irq_routing->mask,
ST_LSM6DSX_SHIFT_VAL(state,
hw->irq_routing->mask));
} }
static int st_lsm6dsx_read_event(struct iio_dev *iio_dev, static int st_lsm6dsx_read_event(struct iio_dev *iio_dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment