Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: pressure: mprls0025pa: stricter checks for the status byte

Make sure a valid conversion comes with a status byte that only has
the MPR_ST_POWER bit set.
Return -EBUSY if also MPR_ST_BUSY is set or -EIO otherwise.

Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Petre Rodan and committed by
Jonathan Cameron
84e15e1a 4edab7b0

+22 -6
+22 -6
drivers/iio/pressure/mprls0025pa.c
··· 198 198 * 199 199 * Context: The function can sleep and data->lock should be held when calling it 200 200 * Return: 201 - * * 0 - OK, the pressure value could be read 202 - * * -ETIMEDOUT - Timeout while waiting for the EOC interrupt or busy flag is 203 - * still set after nloops attempts of reading 201 + * * 0 - OK, the pressure value could be read 202 + * * -EBUSY - Sensor does not have a new conversion ready 203 + * * -ETIMEDOUT - Timeout while waiting for the EOC interrupt 204 + * * -EIO - Invalid status byte received from sensor 204 205 */ 205 206 static int mpr_read_pressure(struct mpr_data *data, s32 *press) 206 207 { ··· 254 253 if (ret < 0) 255 254 return ret; 256 255 257 - if (data->rx_buf[0] & MPR_ST_ERR_FLAG) { 256 + /* 257 + * Status byte flags 258 + * bit7 SANITY_CHK - must always be 0 259 + * bit6 MPR_ST_POWER - 1 if device is powered 260 + * bit5 MPR_ST_BUSY - 1 if device has no new conversion ready 261 + * bit4 SANITY_CHK - must always be 0 262 + * bit3 SANITY_CHK - must always be 0 263 + * bit2 MEMORY_ERR - 1 if integrity test has failed 264 + * bit1 SANITY_CHK - must always be 0 265 + * bit0 MATH_ERR - 1 during internal math saturation error 266 + */ 267 + 268 + if (data->rx_buf[0] == (MPR_ST_POWER | MPR_ST_BUSY)) 269 + return -EBUSY; 270 + 271 + if (data->rx_buf[0] != MPR_ST_POWER) { 258 272 dev_err(data->dev, 259 - "unexpected status byte %02x\n", data->rx_buf[0]); 260 - return -ETIMEDOUT; 273 + "unexpected status byte 0x%02x\n", data->rx_buf[0]); 274 + return -EIO; 261 275 } 262 276 263 277 *press = get_unaligned_be24(&data->rx_buf[1]);