On Fri, 15 Oct 2021 04:07:28 -0700 Qing Wang <wangqing@xxxxxxxx> wrote: > show() should not use snprintf() when formatting the value to be returned > to user space, snprintf() returns the length the resulting string and > scnprintf() returns the number of bytes printed into the buffer. > > Fix the coccicheck warnings: > WARNING: use scnprintf or sprintf. > > Use sysfs_emit() instead of scnprintf() makes more sense. > > Signed-off-by: Qing Wang <wangqing@xxxxxxxx> Hi, A few places where it makes sense to tidy up the line breaks. The benefit of the change in general is fairly minor given none of the cases here can cause problems, but I guess it is worthwhile as warning suppression and general tidiness improvement. Jonathan > --- > drivers/hid/hid-lenovo.c | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c > index 93b1f93..086a7ae 100644 > --- a/drivers/hid/hid-lenovo.c > +++ b/drivers/hid/hid-lenovo.c > @@ -400,7 +400,7 @@ static ssize_t attr_fn_lock_show(struct device *dev, > struct hid_device *hdev = to_hid_device(dev); > struct lenovo_drvdata *data = hid_get_drvdata(hdev); > > - return snprintf(buf, PAGE_SIZE, "%u\n", data->fn_lock); > + return sysfs_emit(buf, "%u\n", data->fn_lock); > } > > static ssize_t attr_fn_lock_store(struct device *dev, > @@ -442,7 +442,7 @@ static ssize_t attr_sensitivity_show_cptkbd(struct device *dev, > struct hid_device *hdev = to_hid_device(dev); > struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev); > > - return snprintf(buf, PAGE_SIZE, "%u\n", > + return sysfs_emit(buf, "%u\n", > cptkbd_data->sensitivity); As below, whilst here tidy this up to be one line. > } > > @@ -603,7 +603,7 @@ static ssize_t attr_press_to_select_show_tpkbd(struct device *dev, > struct hid_device *hdev = to_hid_device(dev); > struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); > > - return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->press_to_select); > + return sysfs_emit(buf, "%u\n", data_pointer->press_to_select); > } > > static ssize_t attr_press_to_select_store_tpkbd(struct device *dev, > @@ -633,7 +633,7 @@ static ssize_t attr_dragging_show_tpkbd(struct device *dev, > struct hid_device *hdev = to_hid_device(dev); > struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); > > - return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->dragging); > + return sysfs_emit(buf, "%u\n", data_pointer->dragging); > } > > static ssize_t attr_dragging_store_tpkbd(struct device *dev, > @@ -663,7 +663,7 @@ static ssize_t attr_release_to_select_show_tpkbd(struct device *dev, > struct hid_device *hdev = to_hid_device(dev); > struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); > > - return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->release_to_select); > + return sysfs_emit(buf, "%u\n", data_pointer->release_to_select); > } > > static ssize_t attr_release_to_select_store_tpkbd(struct device *dev, > @@ -693,7 +693,7 @@ static ssize_t attr_select_right_show_tpkbd(struct device *dev, > struct hid_device *hdev = to_hid_device(dev); > struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); > > - return snprintf(buf, PAGE_SIZE, "%u\n", data_pointer->select_right); > + return sysfs_emit(buf, "%u\n", data_pointer->select_right); > } > > static ssize_t attr_select_right_store_tpkbd(struct device *dev, > @@ -723,7 +723,7 @@ static ssize_t attr_sensitivity_show_tpkbd(struct device *dev, > struct hid_device *hdev = to_hid_device(dev); > struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); > > - return snprintf(buf, PAGE_SIZE, "%u\n", > + return sysfs_emit(buf, "%u\n", > data_pointer->sensitivity); Perhaps put this on one line? It fit before the change of course, but as you are touching the code, might as well tidy that up. > } > > @@ -752,7 +752,7 @@ static ssize_t attr_press_speed_show_tpkbd(struct device *dev, > struct hid_device *hdev = to_hid_device(dev); > struct lenovo_drvdata *data_pointer = hid_get_drvdata(hdev); > > - return snprintf(buf, PAGE_SIZE, "%u\n", > + return sysfs_emit(buf, "%u\n", > data_pointer->press_speed); Same here. Thanks, Jonathan > } >