Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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=<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
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Li Zhijian <lizhijian@fujitsu.com>
Signed-off-by: Jiri Kosina <jkosina@suse.com>

authored by

Li Zhijian and committed by
Jiri Kosina
460560fd 247481b8

+4 -5
+4 -5
drivers/hid/hid-sensor-custom.c
··· 155 155 { 156 156 struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev); 157 157 158 - return sprintf(buf, "%d\n", sensor_inst->enable); 158 + return sysfs_emit(buf, "%d\n", sensor_inst->enable); 159 159 } 160 160 161 161 static int set_power_report_state(struct hid_sensor_custom *sensor_inst, ··· 372 372 sizeof(struct hid_custom_usage_desc), 373 373 usage_id_cmp); 374 374 if (usage_desc) 375 - return snprintf(buf, PAGE_SIZE, "%s\n", 376 - usage_desc->desc); 375 + return sysfs_emit(buf, "%s\n", usage_desc->desc); 377 376 else 378 - return sprintf(buf, "not-specified\n"); 377 + return sysfs_emit(buf, "not-specified\n"); 379 378 } else 380 379 return -EINVAL; 381 380 382 - return sprintf(buf, "%d\n", value); 381 + return sysfs_emit(buf, "%d\n", value); 383 382 } 384 383 385 384 static ssize_t store_value(struct device *dev, struct device_attribute *attr,