Linux Input/HID development
 help / color / mirror / Atom feed
From: "Zhijian Li (Fujitsu)" <lizhijian@fujitsu.com>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "Bruno Prémont" <bonbons@linux-vserver.org>,
	"Jiri Kosina" <jikos@kernel.org>,
	"Benjamin Tissoires" <benjamin.tissoires@redhat.com>,
	"linux-input@vger.kernel.org" <linux-input@vger.kernel.org>
Subject: Re: [PATCH v3 1/4] HID: hid-picolcd*: Convert sprintf/scnprintf to sysfs_emit/sysfs_emit_at
Date: Tue, 19 Mar 2024 01:21:20 +0000	[thread overview]
Message-ID: <efe64892-2f6f-4629-ae0b-d82c0fd4c7c4@fujitsu.com> (raw)
In-Reply-To: <588c9ba0-fcec-4700-a577-b604511f22a1@wanadoo.fr>



On 19/03/2024 02:17, Christophe JAILLET wrote:
> Le 18/03/2024 à 02:28, Li Zhijian a écrit :
>> Per filesystems/sysfs.rst, show() should only use sysfs_emit()
>> or sysfs_emit_at() when formatting the value to be returned to user space.
>>
>> coccinelle complains that there are still a couple of functions that use
>> snprintf(). Convert them to sysfs_emit().
>>
>> scnprintf() will be converted as weel if they have.
>>
>> Generally, this patch is generated by
>> make coccicheck M=<path/to/file> MODE=patch \
>> COCCI=scripts/coccinelle/api/device_attr_show.cocci
>>
>> No functional change intended
>>
>> CC: "Bruno Prémont" <bonbons@linux-vserver.org>
>> CC: Jiri Kosina <jikos@kernel.org>
>> CC: Benjamin Tissoires <benjamin.tissoires@redhat.com>
>> CC: linux-input@vger.kernel.org
>> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
>> ---
>> V3:
>>     Covert more file(drivers/hid/hid-picolcd_fb.c) as suggested by Bruno
>>
>> This is a part of the work "Fix coccicheck device_attr_show warnings"[1]
>> Split them per subsystem so that the maintainer can review it easily
>> [1] https://lore.kernel.org/lkml/20240116041129.3937800-1-lizhijian@fujitsu.com/
>> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
>> ---
>>   drivers/hid/hid-picolcd_core.c | 6 +++---
>>   drivers/hid/hid-picolcd_fb.c   | 4 ++--
>>   2 files changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
>> index bbda231a7ce3..fa46fb6eab3f 100644
>> --- a/drivers/hid/hid-picolcd_core.c
>> +++ b/drivers/hid/hid-picolcd_core.c
>> @@ -256,9 +256,9 @@ static ssize_t picolcd_operation_mode_show(struct device *dev,
>>       struct picolcd_data *data = dev_get_drvdata(dev);
>>       if (data->status & PICOLCD_BOOTLOADER)
>> -        return snprintf(buf, PAGE_SIZE, "[bootloader] lcd\n");
>> +        return sysfs_emit(buf, "[bootloader] lcd\n");
>>       else
>> -        return snprintf(buf, PAGE_SIZE, "bootloader [lcd]\n");
>> +        return sysfs_emit(buf, "bootloader [lcd]\n");
>>   }
>>   static ssize_t picolcd_operation_mode_store(struct device *dev,
>> @@ -301,7 +301,7 @@ static ssize_t picolcd_operation_mode_delay_show(struct device *dev,
>>   {
>>       struct picolcd_data *data = dev_get_drvdata(dev);
>> -    return snprintf(buf, PAGE_SIZE, "%hu\n", data->opmode_delay);
>> +    return sysfs_emit(buf, "%hu\n", data->opmode_delay);
>>   }
>>   static ssize_t picolcd_operation_mode_delay_store(struct device *dev,
>> diff --git a/drivers/hid/hid-picolcd_fb.c b/drivers/hid/hid-picolcd_fb.c
>> index d7dddd99d325..369c78d70e66 100644
>> --- a/drivers/hid/hid-picolcd_fb.c
>> +++ b/drivers/hid/hid-picolcd_fb.c
>> @@ -424,9 +424,9 @@ static ssize_t picolcd_fb_update_rate_show(struct device *dev,
> 
> Hi,
> 
> just above we have:
>      for (i = 1; i <= PICOLCDFB_UPDATE_RATE_LIMIT; i++)
> 
>>           if (ret >= PAGE_SIZE)
>>               break;
> 
> and PICOLCDFB_UPDATE_RATE_LIMIT is 10, so it is not possible to have ret >= PAGE_SIZE. Should it happen, sysfs_emit_at() handles it.
> So, this test can also be removed, IMHO.

Good catch, i will update it.


Thanks
Zhijian

> 
> CJ
> 
>>           else if (i == fb_update_rate)
>> -            ret += scnprintf(buf+ret, PAGE_SIZE-ret, "[%u] ", i);
>> +            ret += sysfs_emit_at(buf, ret, "[%u] ", i);
>>           else
>> -            ret += scnprintf(buf+ret, PAGE_SIZE-ret, "%u ", i);
>> +            ret += sysfs_emit_at(buf, ret, "%u ", i);
>>       if (ret > 0)
>>           buf[min(ret, (size_t)PAGE_SIZE)-1] = '\n';
>>       return ret;
> 

      reply	other threads:[~2024-03-19  1:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18  1:28 [PATCH v3 1/4] HID: hid-picolcd*: Convert sprintf/scnprintf to sysfs_emit/sysfs_emit_at Li Zhijian
2024-03-18  1:28 ` [PATCH v3 2/4] HID: hid-sensor-custom: Convert sprintf/snprintf to sysfs_emit Li Zhijian
2024-03-18  1:28 ` [PATCH v3 3/4] HID: roccat: " Li Zhijian
2024-03-18  1:28 ` [PATCH v3 4/4] HID: corsair,lenovo: " Li Zhijian
2024-03-18 18:17 ` [PATCH v3 1/4] HID: hid-picolcd*: Convert sprintf/scnprintf to sysfs_emit/sysfs_emit_at Christophe JAILLET
2024-03-19  1:21   ` Zhijian Li (Fujitsu) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=efe64892-2f6f-4629-ae0b-d82c0fd4c7c4@fujitsu.com \
    --to=lizhijian@fujitsu.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=bonbons@linux-vserver.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox