* [PATCH v2 2/4] HID: hid-sensor-custom: Convert sprintf/snprintf to sysfs_emit [not found] <20240314084753.1322110-1-lizhijian@fujitsu.com> @ 2024-03-14 8:47 ` Li Zhijian 2024-03-14 15:33 ` Jonathan Cameron 0 siblings, 1 reply; 3+ messages in thread From: Li Zhijian @ 2024-03-14 8:47 UTC (permalink / raw) To: linux-kernel Cc: Li Zhijian, Jiri Kosina, Jonathan Cameron, Srinivas Pandruvada, Benjamin Tissoires, linux-input, linux-iio 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(). sprintf() 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: Jiri Kosina <jikos@kernel.org> CC: Jonathan Cameron <jic23@kernel.org> CC: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> CC: Benjamin Tissoires <benjamin.tissoires@redhat.com> CC: linux-input@vger.kernel.org CC: linux-iio@vger.kernel.org Signed-off-by: Li Zhijian <lizhijian@fujitsu.com> --- 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/ --- drivers/hid/hid-sensor-custom.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c index d85398721659..ee1a118834f0 100644 --- a/drivers/hid/hid-sensor-custom.c +++ b/drivers/hid/hid-sensor-custom.c @@ -155,7 +155,7 @@ static ssize_t enable_sensor_show(struct device *dev, { struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev); - return sprintf(buf, "%d\n", sensor_inst->enable); + return sysfs_emit(buf, "%d\n", sensor_inst->enable); } static int set_power_report_state(struct hid_sensor_custom *sensor_inst, @@ -372,14 +372,14 @@ static ssize_t show_value(struct device *dev, struct device_attribute *attr, sizeof(struct hid_custom_usage_desc), usage_id_cmp); if (usage_desc) - return snprintf(buf, PAGE_SIZE, "%s\n", - usage_desc->desc); + return sysfs_emit(buf, "%s\n", + usage_desc->desc); else - return sprintf(buf, "not-specified\n"); + return sysfs_emit(buf, "not-specified\n"); } else return -EINVAL; - return sprintf(buf, "%d\n", value); + return sysfs_emit(buf, "%d\n", value); } static ssize_t store_value(struct device *dev, struct device_attribute *attr, -- 2.29.2 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 2/4] HID: hid-sensor-custom: Convert sprintf/snprintf to sysfs_emit 2024-03-14 8:47 ` [PATCH v2 2/4] HID: hid-sensor-custom: Convert sprintf/snprintf to sysfs_emit Li Zhijian @ 2024-03-14 15:33 ` Jonathan Cameron 2024-03-15 1:14 ` Zhijian Li (Fujitsu) 0 siblings, 1 reply; 3+ messages in thread From: Jonathan Cameron @ 2024-03-14 15:33 UTC (permalink / raw) To: Li Zhijian Cc: linux-kernel, Jiri Kosina, Srinivas Pandruvada, Benjamin Tissoires, linux-input, linux-iio On Thu, 14 Mar 2024 16:47:51 +0800 Li Zhijian <lizhijian@fujitsu.com> wrote: > 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(). > > sprintf() 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: Jiri Kosina <jikos@kernel.org> > CC: Jonathan Cameron <jic23@kernel.org> > CC: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> > CC: Benjamin Tissoires <benjamin.tissoires@redhat.com> > CC: linux-input@vger.kernel.org > CC: linux-iio@vger.kernel.org > Signed-off-by: Li Zhijian <lizhijian@fujitsu.com> Hi Li Zhijian, One trivial comment inline. Otherwise straight forward so Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > --- > 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/ > --- > drivers/hid/hid-sensor-custom.c | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c > index d85398721659..ee1a118834f0 100644 > --- a/drivers/hid/hid-sensor-custom.c > +++ b/drivers/hid/hid-sensor-custom.c > @@ -155,7 +155,7 @@ static ssize_t enable_sensor_show(struct device *dev, > { > struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev); > > - return sprintf(buf, "%d\n", sensor_inst->enable); > + return sysfs_emit(buf, "%d\n", sensor_inst->enable); > } > > static int set_power_report_state(struct hid_sensor_custom *sensor_inst, > @@ -372,14 +372,14 @@ static ssize_t show_value(struct device *dev, struct device_attribute *attr, > sizeof(struct hid_custom_usage_desc), > usage_id_cmp); > if (usage_desc) > - return snprintf(buf, PAGE_SIZE, "%s\n", > - usage_desc->desc); > + return sysfs_emit(buf, "%s\n", > + usage_desc->desc); rewrap the line as will be under 80 chars. > else > - return sprintf(buf, "not-specified\n"); > + return sysfs_emit(buf, "not-specified\n"); > } else > return -EINVAL; > > - return sprintf(buf, "%d\n", value); > + return sysfs_emit(buf, "%d\n", value); > } > > static ssize_t store_value(struct device *dev, struct device_attribute *attr, ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2 2/4] HID: hid-sensor-custom: Convert sprintf/snprintf to sysfs_emit 2024-03-14 15:33 ` Jonathan Cameron @ 2024-03-15 1:14 ` Zhijian Li (Fujitsu) 0 siblings, 0 replies; 3+ messages in thread From: Zhijian Li (Fujitsu) @ 2024-03-15 1:14 UTC (permalink / raw) To: Jonathan Cameron Cc: linux-kernel@vger.kernel.org, Jiri Kosina, Srinivas Pandruvada, Benjamin Tissoires, linux-input@vger.kernel.org, linux-iio@vger.kernel.org On 14/03/2024 23:33, Jonathan Cameron wrote: > On Thu, 14 Mar 2024 16:47:51 +0800 > Li Zhijian <lizhijian@fujitsu.com> wrote: > >> 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(). >> >> sprintf() 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: Jiri Kosina <jikos@kernel.org> >> CC: Jonathan Cameron <jic23@kernel.org> >> CC: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> >> CC: Benjamin Tissoires <benjamin.tissoires@redhat.com> >> CC: linux-input@vger.kernel.org >> CC: linux-iio@vger.kernel.org >> Signed-off-by: Li Zhijian <lizhijian@fujitsu.com> > Hi Li Zhijian, > > One trivial comment inline. > Otherwise straight forward so > Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> > >> --- >> 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/ >> --- >> drivers/hid/hid-sensor-custom.c | 10 +++++----- >> 1 file changed, 5 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c >> index d85398721659..ee1a118834f0 100644 >> --- a/drivers/hid/hid-sensor-custom.c >> +++ b/drivers/hid/hid-sensor-custom.c >> @@ -155,7 +155,7 @@ static ssize_t enable_sensor_show(struct device *dev, >> { >> struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev); >> >> - return sprintf(buf, "%d\n", sensor_inst->enable); >> + return sysfs_emit(buf, "%d\n", sensor_inst->enable); >> } >> >> static int set_power_report_state(struct hid_sensor_custom *sensor_inst, >> @@ -372,14 +372,14 @@ static ssize_t show_value(struct device *dev, struct device_attribute *attr, >> sizeof(struct hid_custom_usage_desc), >> usage_id_cmp); >> if (usage_desc) >> - return snprintf(buf, PAGE_SIZE, "%s\n", >> - usage_desc->desc); >> + return sysfs_emit(buf, "%s\n", >> + usage_desc->desc); > rewrap the line as will be under 80 chars. Good catch, i will update it. Thanks Zhijian > >> else >> - return sprintf(buf, "not-specified\n"); >> + return sysfs_emit(buf, "not-specified\n"); >> } else >> return -EINVAL; >> >> - return sprintf(buf, "%d\n", value); >> + return sysfs_emit(buf, "%d\n", value); >> } >> >> static ssize_t store_value(struct device *dev, struct device_attribute *attr, > ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-15 1:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20240314084753.1322110-1-lizhijian@fujitsu.com>
2024-03-14 8:47 ` [PATCH v2 2/4] HID: hid-sensor-custom: Convert sprintf/snprintf to sysfs_emit Li Zhijian
2024-03-14 15:33 ` Jonathan Cameron
2024-03-15 1:14 ` Zhijian Li (Fujitsu)
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox