linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matt Ranostay <mranostay@gmail.com>
To: linux-iio@vger.kernel.org
Cc: jic23@kernel.org, Matt Ranostay <mranostay@gmail.com>
Subject: [PATCH 3/3] iio: chemical: vz89x: prevent corrupted buffer from being read
Date: Mon, 22 Aug 2016 20:44:54 -0700	[thread overview]
Message-ID: <1471923894-12194-4-git-send-email-mranostay@gmail.com> (raw)
In-Reply-To: <1471923894-12194-1-git-send-email-mranostay@gmail.com>

Signed-off-by: Matt Ranostay <mranostay@gmail.com>
---
 drivers/iio/chemical/vz89x.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c
index 0347761ebdba..c2a311c59190 100644
--- a/drivers/iio/chemical/vz89x.c
+++ b/drivers/iio/chemical/vz89x.c
@@ -54,6 +54,7 @@ struct vz89x_data {
 	int (*xfer)(struct vz89x_data *data, u8 cmd);
 	int (*valid)(struct vz89x_data *data);
 
+	bool is_valid;
 	unsigned long last_update;
 	u8 cmd;
 	u8 write_size;
@@ -220,8 +221,10 @@ static int vz89x_get_measurement(struct vz89x_data *data)
 
 	/* sensor can only be polled once a second max per datasheet */
 	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, data->cmd);
 	if (ret < 0)
 		return ret;
@@ -230,7 +233,7 @@ static int vz89x_get_measurement(struct vz89x_data *data)
 	if (ret)
 		return -EAGAIN;
 
-	data->last_update = jiffies;
+	data->is_valid = true;
 
 	return 0;
 }
-- 
2.7.4

      parent reply	other threads:[~2016-08-23  3:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-23  3:44 [PATCH 0/3] iio: chemical: vz89x: add multiple chip functionality Matt Ranostay
2016-08-23  3:44 ` [PATCH 1/3] iio: chemical: vz89x: abstract chip configuration Matt Ranostay
2016-08-23  3:44 ` [PATCH 2/3] iio: chemical: vz89x: add support for VZ89TE part Matt Ranostay
2016-08-23  5:42   ` Peter Meerwald-Stadler
2016-08-23  7:58     ` Matt Ranostay
2016-08-23  8:10       ` Peter Meerwald-Stadler
2016-08-23  8:43         ` Matt Ranostay
2016-08-29 16:37           ` Jonathan Cameron
2016-08-23 20:35     ` Matt Ranostay
2016-08-23 23:52     ` Matt Ranostay
2016-08-24  4:23       ` Peter Meerwald-Stadler
2016-08-24  4:39         ` Matt Ranostay
2016-08-23  3:44 ` Matt Ranostay [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471923894-12194-4-git-send-email-mranostay@gmail.com \
    --to=mranostay@gmail.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).