All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Input: atmel_mxt_ts: Fix random configuration load failure
@ 2015-02-09 18:31 Martin Fuzzey
  0 siblings, 0 replies; only message in thread
From: Martin Fuzzey @ 2015-02-09 18:31 UTC (permalink / raw)
  To: Henrik Rydberg, Nick Dyer, linux-input

Sometimes configuration fails to load with:

	Bad format: failed to parse object

This can occur because the firmware loader does not ensure that
the configuration data is null terminated.

The scanf() therefore reads arbitrary garbage at the end of file.
If one item of garbage happens to be parsable the error occurs.

By skipping control characters (line endings) before scanning
each line rather than relying on the white space skipping of sscanf
we correctly detect end of file.

Signed-off-by: Martin Fuzzey <mfuzzey@parkeon.com>
---
 drivers/input/touchscreen/atmel_mxt_ts.c |    7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 0666759..29f9b9d 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -1086,6 +1086,13 @@ static int mxt_prepare_cfg_mem(struct mxt_data *data,
 	u8 val;
 
 	while (data_pos < cfg->size) {
+		if (cfg->data[data_pos] < 0x20) {
+			/* firmware loading does not ensure null termination
+			 * which is required by scanf */
+			 data_pos++;
+			 continue;
+		}
+
 		/* Read type, instance, length */
 		ret = sscanf(cfg->data + data_pos, "%x %x %x%n",
 			     &type, &instance, &size, &offset);


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-02-09 19:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-09 18:31 [PATCH] Input: atmel_mxt_ts: Fix random configuration load failure Martin Fuzzey

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.