diff mbox

Input: touchscreen: AD7879: prevent invalid finger data reports

Message ID 1287408804-19789-1-git-send-email-michael.hennerich@analog.com (mailing list archive)
State Superseded
Headers show

Commit Message

Hennerich, Michael Oct. 18, 2010, 1:33 p.m. UTC
None
diff mbox

Patch

diff --git a/drivers/input/touchscreen/ad7879.c b/drivers/input/touchscreen/ad7879.c
index ba6f0bd..3173589 100644
--- a/drivers/input/touchscreen/ad7879.c
+++ b/drivers/input/touchscreen/ad7879.c
@@ -129,6 +129,9 @@  struct ad7879 {
 	u16			cmd_crtl1;
 	u16			cmd_crtl2;
 	u16			cmd_crtl3;
+	int			x;
+	int			y;
+	int			Rt;	
 };
 
 static int ad7879_read(struct ad7879 *ts, u8 reg)
@@ -175,13 +178,29 @@  static int ad7879_report(struct ad7879 *ts)
 		Rt /= z1;
 		Rt = (Rt + 2047) >> 12;
 
-		if (!timer_pending(&ts->timer))
+		/*
+		 * Sample found inconsistent, pressure is beyond
+		 * the maximum. Don't report it to user space.
+		 */
+		if (Rt > ts->pressure_max)
+			return -EINVAL;
+
+		if (!timer_pending(&ts->timer)) {
+			ts->x = x;
+			ts->y = y;
+			ts->Rt = Rt;
 			input_report_key(input_dev, BTN_TOUCH, 1);
-
-		input_report_abs(input_dev, ABS_X, x);
-		input_report_abs(input_dev, ABS_Y, y);
-		input_report_abs(input_dev, ABS_PRESSURE, Rt);
-		input_sync(input_dev);
+		}
+		
+		input_report_abs(input_dev, ABS_X, ts->x);
+		input_report_abs(input_dev, ABS_Y, ts->y);
+		input_report_abs(input_dev, ABS_PRESSURE, ts->Rt);
+		input_sync(input_dev);		
+
+		ts->x = x;
+		ts->y = y;
+		ts->Rt = Rt;
+		
 		return 0;
 	}