回复: [PATCH] hid: replace snprintf in show functions with sysfs_emit

From: 王擎
Date: Fri Oct 15 2021 - 06:12:55 EST



>> show() must not use snprintf() when formatting the value to be
>> returned to user space.
>>
>> Fix the coccicheck warnings:
>> WARNING: use scnprintf or sprintf.
>>
>> Use sysfs_emit instead of scnprintf or sprintf makes more sense.
>
>Looks good to me, but I have a few remarks:
>
>- No need to talk about "must not use" in detailled commit message.
>  Mentioning introduction of the newish sysfs_emit() functions (in
>  commit 2efc459d06f1630001e3984854848a5647086232 a Year ago) and thus
>  switching over to those would be sufficient for code predating their
>  introduction.
>
>- I'm wondering why picolcd_fb_update_rate_show() in
>    drivers/hid/hid-picolcd_fb.c:446
>  is not updated as well in this same patch.
>  There scnprintf() calls should be replaced with sysfs_emit_at() calls
>  according to the intent of this patch!

scnprintf is fine, but snprintf is WRONG used.
scnprintf() return the number of bytes printed into the buffer.
snprintf() returns the length the resulting string.

>
>- Not sure if the patch should be split into a 5-patch series with one
>  patch per HID driver (each driver can be updated independently).
>

I will do this in V2.

Thanks,

Qing

>
>Acked-by: Bruno Prémont <bonbons@xxxxxxxxxxxxxxxxx>
>  (for picolcd code)