]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: pressure: mprls0025pa: stricter checks for the status byte
authorPetre Rodan <petre.rodan@subdimension.ro>
Wed, 14 Jan 2026 16:55:40 +0000 (18:55 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Fri, 16 Jan 2026 17:40:41 +0000 (17:40 +0000)
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>
drivers/iio/pressure/mprls0025pa.c

index a7041a503bde5e226c4401785be316c1af025467..31ec2bae84b154e829651a91709b9d4ffa519ec1 100644 (file)
@@ -198,9 +198,10 @@ static void mpr_reset(struct mpr_data *data)
  *
  * Context: The function can sleep and data->lock should be held when calling it
  * Return:
- * * 0         - OK, the pressure value could be read
- * * -ETIMEDOUT        - Timeout while waiting for the EOC interrupt or busy flag is
- *               still set after nloops attempts of reading
+ * * 0          - OK, the pressure value could be read
+ * * -EBUSY     - Sensor does not have a new conversion ready
+ * * -ETIMEDOUT - Timeout while waiting for the EOC interrupt
+ * * -EIO       - Invalid status byte received from sensor
  */
 static int mpr_read_pressure(struct mpr_data *data, s32 *press)
 {
@@ -253,10 +254,25 @@ static int mpr_read_pressure(struct mpr_data *data, s32 *press)
        if (ret < 0)
                return ret;
 
-       if (data->rx_buf[0] & MPR_ST_ERR_FLAG) {
+       /*
+        * Status byte flags
+        *  bit7 SANITY_CHK   - must always be 0
+        *  bit6 MPR_ST_POWER - 1 if device is powered
+        *  bit5 MPR_ST_BUSY  - 1 if device has no new conversion ready
+        *  bit4 SANITY_CHK   - must always be 0
+        *  bit3 SANITY_CHK   - must always be 0
+        *  bit2 MEMORY_ERR   - 1 if integrity test has failed
+        *  bit1 SANITY_CHK   - must always be 0
+        *  bit0 MATH_ERR     - 1 during internal math saturation error
+        */
+
+       if (data->rx_buf[0] == (MPR_ST_POWER | MPR_ST_BUSY))
+               return -EBUSY;
+
+       if (data->rx_buf[0] != MPR_ST_POWER) {
                dev_err(data->dev,
-                       "unexpected status byte %02x\n", data->rx_buf[0]);
-               return -ETIMEDOUT;
+                       "unexpected status byte 0x%02x\n", data->rx_buf[0]);
+               return -EIO;
        }
 
        *press = get_unaligned_be24(&data->rx_buf[1]);