drivers/sensor: lis2dh: Fix LP Enable bit mask

Fix the value for Low Power Enable (LP_EN) bit mask.
(Issue described by Coverity CID #188734)

Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
Armando Visconti 2019-01-16 14:23:06 +01:00 committed by Maureen Helm
commit 16891af7a7
2 changed files with 3 additions and 2 deletions

View file

@ -202,12 +202,12 @@ static int lis2dh_acc_odr_set(struct device *dev, u16_t freq)
} }
/* some odr values cannot be set in certain power modes */ /* some odr values cannot be set in certain power modes */
if ((value & LIS2DH_LP_EN_BIT) == 0 && odr == LIS2DH_ODR_8) { if ((value & LIS2DH_LP_EN_BIT_MASK) == 0 && odr == LIS2DH_ODR_8) {
return -ENOTSUP; return -ENOTSUP;
} }
/* adjust odr index for LP enabled mode, see table above */ /* adjust odr index for LP enabled mode, see table above */
if ((value & LIS2DH_LP_EN_BIT) == 1 && (odr == LIS2DH_ODR_9 + 1)) { if ((value & LIS2DH_LP_EN_BIT_MASK) == 1 && (odr == LIS2DH_ODR_9 + 1)) {
odr--; odr--;
} }

View file

@ -50,6 +50,7 @@
LIS2DH_ACCEL_Z_EN_BIT) LIS2DH_ACCEL_Z_EN_BIT)
#define LIS2DH_ACCEL_XYZ_MASK BIT_MASK(3) #define LIS2DH_ACCEL_XYZ_MASK BIT_MASK(3)
#define LIS2DH_LP_EN_BIT_MASK BIT(3)
#if defined(CONFIG_LIS2DH_POWER_MODE_LOW) #if defined(CONFIG_LIS2DH_POWER_MODE_LOW)
#define LIS2DH_LP_EN_BIT BIT(3) #define LIS2DH_LP_EN_BIT BIT(3)
#elif defined(CONFIG_LIS2DH_POWER_MODE_NORMAL) #elif defined(CONFIG_LIS2DH_POWER_MODE_NORMAL)