Re: [PATCH] Input: atmel_mxt_ts - Use snprintf for sysfs attributeshow method

From: Daniel Kurtz
Date: Fri Sep 16 2011 - 01:11:08 EST


Hi Joonyoung,

Thanks for replying.

On Fri, Sep 16, 2011 at 8:52 AM, Joonyoung Shim <jy0922.shim@xxxxxxxxxxx> wrote:
> Hi,
>
> On 2011-09-16 ìì 4:40, Daniel Kurtz wrote:
>>
>> 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@xxxxxxxxxxxx>
>
> This patch is working but original problem is object size is increasing
> as atmel touchscreen chip updates and we should consider also the
> instances of object.

"This patch is working" = Acked-By ?

> How about splitting attributes to each object?

I agree. Can we do that in another patch (with instance printing)?

> Iiro, do you have any update plans about atmel touchscreen driver?

I have several more patches coming for this driver, mostly to speed up
startup time, cleanup the MT-B implementation, and optimize interrupt
handling.

Thanks,
Daniel

>> ---
>> Âdrivers/input/touchscreen/atmel_mxt_ts.c | Â 21 +++++++++++++++------
>> Â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 f5d6685..a596c27 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,
>> Â Â Â Âfor (i = 0; i< Âdata->info.object_num; i++) {
>> Â Â Â Â Â Â Â Âobject = data->object_table + i;
>>
>> - Â Â Â Â Â Â Â count += sprintf(buf + count,
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "Object Table Element %d(Type %d)\n",
>> + Â Â Â Â Â Â Â count += snprintf(buf + count, PAGE_SIZE - count,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "Object[%d] (Type %d)\n",
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âi + 1, object->type);
>> + Â Â Â Â Â Â Â if (count>= PAGE_SIZE)
>> + Â Â Â Â Â Â Â Â Â Â Â return PAGE_SIZE - 1;
>>
>> Â Â Â Â Â Â Â Â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;
>> Â Â Â Â Â Â Â Â}
>>
>> @@ -925,11 +930,15 @@ static ssize_t mxt_object_show(struct device *dev,
>> Â Â Â Â Â Â Â Â Â Â Â Âif (error)
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âreturn error;
>>
>> - Â Â Â Â Â Â Â Â Â Â Â count += sprintf(buf + count,
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â " ÂByte %d: 0x%x (%d)\n", j, val,
>> val);
>> + Â Â Â Â Â Â Â Â Â Â Â count += snprintf(buf + count, PAGE_SIZE - count,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "\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;
N‹§²æìr¸›yúèšØb²X¬¶ÇvØ^–)Þ{.nÇ+‰·¥Š{±‘êçzX§¶›¡Ü}©ž²ÆzÚ&j:+v‰¨¾«‘êçzZ+€Ê+zf£¢·hšˆ§~†­†Ûiÿûàz¹®w¥¢¸?™¨è­Ú&¢)ßf”ù^jÇy§m…á@A«a¶Úÿ 0¶ìh®å’i