linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: mxs-lradc: check ranges of ts properties
@ 2014-11-19 22:19 Stefan Wahren
  2014-11-19 22:42 ` Fabio Estevam
  2014-11-28 22:47 ` Hartmut Knaack
  0 siblings, 2 replies; 13+ messages in thread
From: Stefan Wahren @ 2014-11-19 22:19 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Fabio Estevam, Kristina Martšenko, linux-iio

The devicetree binding for mxs-lradc defines ranges for the
touchscreen properties. In order to avoid unexpected behavior like
division by zero, we better check these ranges during probe and
abort in error case.

Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
---
 drivers/staging/iio/adc/mxs-lradc.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/staging/iio/adc/mxs-lradc.c b/drivers/staging/iio/adc/mxs-lradc.c
index 6757f10..57c3cf6 100644
--- a/drivers/staging/iio/adc/mxs-lradc.c
+++ b/drivers/staging/iio/adc/mxs-lradc.c
@@ -1500,16 +1500,36 @@ static int mxs_lradc_probe_touchscreen(struct mxs_lradc *lradc,
 	if (ret == 0)
 		lradc->over_sample_cnt = adapt;

+	if (!lradc->over_sample_cnt || lradc->over_sample_cnt > 0x1f) {
+		dev_err(lradc->dev, "Invalid sample count (%u)\n",
+				    lradc->over_sample_cnt);
+		return -EINVAL;
+	}
+
 	lradc->over_sample_delay = 2;
 	ret = of_property_read_u32(lradc_node, "fsl,ave-delay", &adapt);
 	if (ret == 0)
 		lradc->over_sample_delay = adapt;

+	if (!lradc->over_sample_delay ||
+	    lradc->over_sample_delay > LRADC_DELAY_DELAY_MASK) {
+		dev_err(lradc->dev, "Invalid sample delay (%u)\n",
+				    lradc->over_sample_delay);
+		return -EINVAL;
+	}
+
 	lradc->settling_delay = 10;
 	ret = of_property_read_u32(lradc_node, "fsl,settling", &adapt);
 	if (ret == 0)
 		lradc->settling_delay = adapt;

+	if (!lradc->settling_delay ||
+	    lradc->settling_delay > LRADC_DELAY_DELAY_MASK) {
+		dev_err(lradc->dev, "Invalid settling delay (%u)\n",
+				    lradc->settling_delay);
+		return -EINVAL;
+	}
+
 	return 0;
 }

--
1.7.9.5


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-12-12 11:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-19 22:19 [PATCH] iio: mxs-lradc: check ranges of ts properties Stefan Wahren
2014-11-19 22:42 ` Fabio Estevam
2014-11-22 12:02   ` Jonathan Cameron
2014-11-28 23:28   ` Hartmut Knaack
2014-11-29 11:22     ` Stefan Wahren
2014-11-29 18:47       ` Hartmut Knaack
2014-11-30 12:10         ` Kristina Martšenko
2014-11-30 13:29           ` Stefan Wahren
2014-12-08 19:40             ` Stefan Wahren
2014-12-12 11:38               ` Jonathan Cameron
2014-11-28 22:47 ` Hartmut Knaack
2014-11-29 11:06   ` Stefan Wahren
2014-11-29 18:14     ` Hartmut Knaack

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).