From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751189Ab1IPAxZ (ORCPT ); Thu, 15 Sep 2011 20:53:25 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:11239 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750964Ab1IPAxX (ORCPT ); Thu, 15 Sep 2011 20:53:23 -0400 MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; charset=UTF-8; format=flowed X-AuditID: cbfee61b-b7b7fae000005864-9d-4e729e011e7c Date: Fri, 16 Sep 2011 09:52:36 +0900 From: Joonyoung Shim Subject: Re: [PATCH] Input: atmel_mxt_ts - Use snprintf for sysfs attribute show method In-reply-to: <1316115647-1244-1-git-send-email-djkurtz@chromium.org> To: Daniel Kurtz Cc: Dmitry Torokhov , Iiro Valkonen , Henrik Rydberg , Yufeng Shen , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Message-id: <4E729DD4.8010208@samsung.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 References: <1316115647-1244-1-git-send-email-djkurtz@chromium.org> X-OriginalArrivalTime: 16 Sep 2011 00:53:52.0782 (UTC) FILETIME=[1AABA2E0:01CC740B] X-Brightmail-Tracker: AAAAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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. How about splitting attributes to each object? Iiro, do you have any update plans about atmel touchscreen driver? > --- > 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;