From: Li Zhijian Date: Tue, 19 Mar 2024 05:45:25 +0000 (+0800) Subject: HID: hid-sensor-custom: Convert sprintf() family to sysfs_emit() family X-Git-Tag: io_uring-6.10-20240523~98^2~10^2~2 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=460560fda31b8d22b7dac0f69965e3626536b5bb;p=linux-2.6-block.git HID: hid-sensor-custom: Convert sprintf() family to sysfs_emit() family 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() and scnprintf() will be converted as well if they have. Generally, this patch is generated by make coccicheck M= MODE=patch \ COCCI=scripts/coccinelle/api/device_attr_show.cocci No functional change intended CC: Jiri Kosina CC: Jonathan Cameron CC: Srinivas Pandruvada CC: Benjamin Tissoires CC: linux-input@vger.kernel.org CC: linux-iio@vger.kernel.org Reviewed-by: Jonathan Cameron Signed-off-by: Li Zhijian Signed-off-by: Jiri Kosina --- diff --git a/drivers/hid/hid-sensor-custom.c b/drivers/hid/hid-sensor-custom.c index d85398721659..ac214777d7d9 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,13 @@ 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,