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>
This commit is contained in:
Daniel Kurtz 2011-10-06 15:43:20 -07:00 коммит произвёл Dmitry Torokhov
Родитель 04c59abd3c
Коммит 626af86112
1 изменённых файлов: 15 добавлений и 6 удалений

Просмотреть файл

@ -910,12 +910,17 @@ static ssize_t mxt_object_show(struct device *dev,
for (i = 0; i < data->info.object_num; i++) { for (i = 0; i < data->info.object_num; i++) {
object = data->object_table + i; object = data->object_table + i;
count += sprintf(buf + count, count += snprintf(buf + count, PAGE_SIZE - count,
"Object Table Element %d(Type %d)\n", "Object[%d] (Type %d)\n",
i + 1, object->type); i + 1, object->type);
if (count >= PAGE_SIZE)
return PAGE_SIZE - 1;
if (!mxt_object_readable(object->type)) { if (!mxt_object_readable(object->type)) {
count += sprintf(buf + count, "\n"); count += snprintf(buf + count, PAGE_SIZE - count,
"\n");
if (count >= PAGE_SIZE)
return PAGE_SIZE - 1;
continue; continue;
} }
@ -925,11 +930,15 @@ static ssize_t mxt_object_show(struct device *dev,
if (error) if (error)
return error; return error;
count += sprintf(buf + count, count += snprintf(buf + count, PAGE_SIZE - count,
" Byte %d: 0x%x (%d)\n", j, val, val); "\t[%2d]: %02x (%d)\n", j, val, val);
if (count >= PAGE_SIZE)
return PAGE_SIZE - 1;
} }
count += sprintf(buf + count, "\n"); count += snprintf(buf + count, PAGE_SIZE - count, "\n");
if (count >= PAGE_SIZE)
return PAGE_SIZE - 1;
} }
return count; return count;