Skip to content

Commit 460560f

Browse files
zhijianli88Jiri Kosina
authored andcommitted
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 <[email protected]> CC: Jonathan Cameron <[email protected]> CC: Srinivas Pandruvada <[email protected]> CC: Benjamin Tissoires <[email protected]> CC: [email protected] CC: [email protected] Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Li Zhijian <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 247481b commit 460560f

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/hid/hid-sensor-custom.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static ssize_t enable_sensor_show(struct device *dev,
155155
{
156156
struct hid_sensor_custom *sensor_inst = dev_get_drvdata(dev);
157157

158-
return sprintf(buf, "%d\n", sensor_inst->enable);
158+
return sysfs_emit(buf, "%d\n", sensor_inst->enable);
159159
}
160160

161161
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,
372372
sizeof(struct hid_custom_usage_desc),
373373
usage_id_cmp);
374374
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);
377376
else
378-
return sprintf(buf, "not-specified\n");
377+
return sysfs_emit(buf, "not-specified\n");
379378
} else
380379
return -EINVAL;
381380

382-
return sprintf(buf, "%d\n", value);
381+
return sysfs_emit(buf, "%d\n", value);
383382
}
384383

385384
static ssize_t store_value(struct device *dev, struct device_attribute *attr,

0 commit comments

Comments
 (0)