aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Kurtz <djkurtz@chromium.org>2011-10-06 18:43:20 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2011-10-06 22:41:52 -0400
commit626af8611211c55595cd316103abd2419cd4d861 (patch)
tree51e0230b67bd204f66288329c572a3fdd2b772bb
parent04c59abd3c053f9a42437d5db3af4383cf68659c (diff)
Input: atmel_mxt_ts - use snprintf for sysfs attribute show method
Sysfs attribute show methods are always passed a buffer of length PAGE_SIZE. To keep from overwriting this buffer and causing havoc, use snprintf() to guarantee we never write more than the buffer can hold. In addition, at least for my touchscreen, the number and size of objects was far too big to fit in a single 4K page. Therefore, this patch also trims some redundant framing text to leave more room for actual data. Signed-off-by: Daniel Kurtz <djkurtz@chromium.org> Acked-by: Nick Dyer <nick.dyer@itdev.co.uk> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
-rw-r--r--drivers/input/touchscreen/atmel_mxt_ts.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index f5d66859f232..a596c2775d1a 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -910,12 +910,17 @@ static ssize_t mxt_object_show(struct device *dev,
910 for (i = 0; i < data->info.object_num; i++) { 910 for (i = 0; i < data->info.object_num; i++) {
911 object = data->object_table + i; 911 object = data->object_table + i;
912 912
913 count += sprintf(buf + count, 913 count += snprintf(buf + count, PAGE_SIZE - count,
914 "Object Table Element %d(Type %d)\n", 914 "Object[%d] (Type %d)\n",
915 i + 1, object->type); 915 i + 1, object->type);
916 if (count >= PAGE_SIZE)
917 return PAGE_SIZE - 1;
916 918
917 if (!mxt_object_readable(object->type)) { 919 if (!mxt_object_readable(object->type)) {
918 count += sprintf(buf + count, "\n"); 920 count += snprintf(buf + count, PAGE_SIZE - count,
921 "\n");
922 if (count >= PAGE_SIZE)
923 return PAGE_SIZE - 1;
919 continue; 924 continue;
920 } 925 }
921 926
@@ -925,11 +930,15 @@ static ssize_t mxt_object_show(struct device *dev,
925 if (error) 930 if (error)
926 return error; 931 return error;
927 932
928 count += sprintf(buf + count, 933 count += snprintf(buf + count, PAGE_SIZE - count,
929 " Byte %d: 0x%x (%d)\n", j, val, val); 934 "\t[%2d]: %02x (%d)\n", j, val, val);
935 if (count >= PAGE_SIZE)
936 return PAGE_SIZE - 1;
930 } 937 }
931 938
932 count += sprintf(buf + count, "\n"); 939 count += snprintf(buf + count, PAGE_SIZE - count, "\n");
940 if (count >= PAGE_SIZE)
941 return PAGE_SIZE - 1;
933 } 942 }
934 943
935 return count; 944 return count;