Commit 9d1894cd authored by Matt Ranostay's avatar Matt Ranostay Committed by Jonathan Cameron

iio: chemical: vz89x: prevent corrupted buffer from being read

Signed-off-by: default avatarMatt Ranostay <mranostay@gmail.com>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 0a735aa0
...@@ -55,6 +55,7 @@ struct vz89x_data { ...@@ -55,6 +55,7 @@ struct vz89x_data {
struct mutex lock; struct mutex lock;
int (*xfer)(struct vz89x_data *data, u8 cmd); int (*xfer)(struct vz89x_data *data, u8 cmd);
bool is_valid;
unsigned long last_update; unsigned long last_update;
u8 buffer[VZ89TE_REG_MEASUREMENT_RD_SIZE]; u8 buffer[VZ89TE_REG_MEASUREMENT_RD_SIZE];
}; };
...@@ -229,7 +230,10 @@ static int vz89x_get_measurement(struct vz89x_data *data) ...@@ -229,7 +230,10 @@ static int vz89x_get_measurement(struct vz89x_data *data)
/* sensor can only be polled once a second max per datasheet */ /* sensor can only be polled once a second max per datasheet */
if (!time_after(jiffies, data->last_update + HZ)) if (!time_after(jiffies, data->last_update + HZ))
return 0; return data->is_valid ? 0 : -EAGAIN;
data->is_valid = false;
data->last_update = jiffies;
ret = data->xfer(data, chip->cmd); ret = data->xfer(data, chip->cmd);
if (ret < 0) if (ret < 0)
...@@ -239,7 +243,7 @@ static int vz89x_get_measurement(struct vz89x_data *data) ...@@ -239,7 +243,7 @@ static int vz89x_get_measurement(struct vz89x_data *data)
if (ret) if (ret)
return -EAGAIN; return -EAGAIN;
data->last_update = jiffies; data->is_valid = true;
return 0; return 0;
} }
......
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