diff mbox series

[06/13] iio: imu: st_lsm6dsx: always check enable_reg in st_lsm6dsx_event_setup

Message ID 837ea533a4094d6da572999e8f863687fa4cae1b.1570367532.git.lorenzo@kernel.org (mailing list archive)
State New, archived
Headers show
Series various st_lsm6dsx fixes and missing bits | expand

Commit Message

Lorenzo Bianconi Oct. 6, 2019, 1:22 p.m. UTC
Check if enable_reg of event_settings data structure is defined before
writing on it

Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 23 ++++++++++----------
 1 file changed, 11 insertions(+), 12 deletions(-)

Comments

Sean Nyekjaer Oct. 7, 2019, 7:55 a.m. UTC | #1
On 06/10/2019 15.22, Lorenzo Bianconi wrote:
> Check if enable_reg of event_settings data structure is defined before
> writing on it
> 
> Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Tested-by: Sean Nyekjaer <sean@geanix.com>
> ---
>   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 23 ++++++++++----------
>   1 file changed, 11 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index 5df382b9d8f9..7e9e1ef81742 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -1482,26 +1482,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)
>   {
> +	const struct st_lsm6dsx_reg *reg;
>   	int err;
> -	u8 enable = 0;
>   
>   	if (!hw->settings->irq_config.irq1_func.addr)
>   		return -ENOTSUPP;
>   
> -	enable = state ? hw->settings->event_settings.enable_reg.mask : 0;
> -
> -	err = regmap_update_bits(hw->regmap,
> -				 hw->settings->event_settings.enable_reg.addr,
> -				 hw->settings->event_settings.enable_reg.mask,
> -				 enable);
> -	if (err < 0)
> -		return err;
> -
> -	enable = state ? hw->irq_routing->mask : 0;
> +	reg = &hw->settings->event_settings.enable_reg;
> +	if (reg->addr) {
> +		err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> +					 ST_LSM6DSX_SHIFT_VAL(state, reg->mask));
> +		if (err < 0)
> +			return err;
> +	}
>   
>   	/* Enable wakeup interrupt */
>   	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,
>
Jonathan Cameron Oct. 12, 2019, 12:21 p.m. UTC | #2
On Mon, 7 Oct 2019 09:55:14 +0200
Sean Nyekjaer <sean@geanix.com> wrote:

> On 06/10/2019 15.22, Lorenzo Bianconi wrote:
> > Check if enable_reg of event_settings data structure is defined before
> > writing on it
> > 
> > Fixes: b5969abfa8b8 ("iio: imu: st_lsm6dsx: add motion events")
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>  
> Tested-by: Sean Nyekjaer <sean@geanix.com>
Applied
> > ---
> >   drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 23 ++++++++++----------
> >   1 file changed, 11 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > index 5df382b9d8f9..7e9e1ef81742 100644
> > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> > @@ -1482,26 +1482,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)
> >   {
> > +	const struct st_lsm6dsx_reg *reg;
> >   	int err;
> > -	u8 enable = 0;
> >   
> >   	if (!hw->settings->irq_config.irq1_func.addr)
> >   		return -ENOTSUPP;
> >   
> > -	enable = state ? hw->settings->event_settings.enable_reg.mask : 0;
> > -
> > -	err = regmap_update_bits(hw->regmap,
> > -				 hw->settings->event_settings.enable_reg.addr,
> > -				 hw->settings->event_settings.enable_reg.mask,
> > -				 enable);
> > -	if (err < 0)
> > -		return err;
> > -
> > -	enable = state ? hw->irq_routing->mask : 0;
> > +	reg = &hw->settings->event_settings.enable_reg;
> > +	if (reg->addr) {
> > +		err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
> > +					 ST_LSM6DSX_SHIFT_VAL(state, reg->mask));
> > +		if (err < 0)
> > +			return err;
> > +	}
> >   
> >   	/* Enable wakeup interrupt */
> >   	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,
> >
diff mbox series

Patch

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 5df382b9d8f9..7e9e1ef81742 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1482,26 +1482,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)
 {
+	const struct st_lsm6dsx_reg *reg;
 	int err;
-	u8 enable = 0;
 
 	if (!hw->settings->irq_config.irq1_func.addr)
 		return -ENOTSUPP;
 
-	enable = state ? hw->settings->event_settings.enable_reg.mask : 0;
-
-	err = regmap_update_bits(hw->regmap,
-				 hw->settings->event_settings.enable_reg.addr,
-				 hw->settings->event_settings.enable_reg.mask,
-				 enable);
-	if (err < 0)
-		return err;
-
-	enable = state ? hw->irq_routing->mask : 0;
+	reg = &hw->settings->event_settings.enable_reg;
+	if (reg->addr) {
+		err = regmap_update_bits(hw->regmap, reg->addr, reg->mask,
+					 ST_LSM6DSX_SHIFT_VAL(state, reg->mask));
+		if (err < 0)
+			return err;
+	}
 
 	/* Enable wakeup interrupt */
 	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,