Skip to content

Commit

Permalink
HID: hid-sensor-custom: Convert sprintf() family to sysfs_emit() family
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
zhijianli88 authored and Jiri Kosina committed Apr 3, 2024
1 parent 247481b commit 460560f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions drivers/hid/hid-sensor-custom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 460560f

Please sign in to comment.