From 1f4d4af4d7a1c794a4f003f75fcfd38fafb5dff3 Mon Sep 17 00:00:00 2001 From: Guenter Roeck Date: Sun, 21 Mar 2021 20:49:10 -0700 Subject: hwmon: replace snprintf in show functions with sysfs_emit coccicheck complains about the use of snprintf() in sysfs show functions. drivers/hwmon/ina3221.c:701:8-16: WARNING: use scnprintf or sprintf This results in a large number of patch submissions. Fix it all in one go using the following coccinelle rules. Use sysfs_emit instead of scnprintf or sprintf since that makes more sense. @depends on patch@ identifier show, dev, attr, buf; @@ ssize_t show(struct device *dev, struct device_attribute *attr, char *buf) { <... return - snprintf(buf, \( PAGE_SIZE \| PAGE_SIZE - 1 \), + sysfs_emit(buf, ...); ...> } @depends on patch@ identifier show, dev, attr, buf, rc; @@ ssize_t show(struct device *dev, struct device_attribute *attr, char *buf) { <... rc = - snprintf(buf, \( PAGE_SIZE \| PAGE_SIZE - 1 \), + sysfs_emit(buf, ...); ...> } While at it, remove unnecessary braces and as well as unnecessary else after return statements to address checkpatch warnings in the resulting patch. Cc: Zihao Tang Cc: Jay Fang Signed-off-by: Guenter Roeck --- drivers/hwmon/ltc4215.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/hwmon/ltc4215.c') diff --git a/drivers/hwmon/ltc4215.c b/drivers/hwmon/ltc4215.c index 7cef3cb2962b..1d18c212054f 100644 --- a/drivers/hwmon/ltc4215.c +++ b/drivers/hwmon/ltc4215.c @@ -139,7 +139,7 @@ static ssize_t ltc4215_voltage_show(struct device *dev, struct sensor_device_attribute *attr = to_sensor_dev_attr(da); const int voltage = ltc4215_get_voltage(dev, attr->index); - return snprintf(buf, PAGE_SIZE, "%d\n", voltage); + return sysfs_emit(buf, "%d\n", voltage); } static ssize_t ltc4215_current_show(struct device *dev, @@ -147,7 +147,7 @@ static ssize_t ltc4215_current_show(struct device *dev, { const unsigned int curr = ltc4215_get_current(dev); - return snprintf(buf, PAGE_SIZE, "%u\n", curr); + return sysfs_emit(buf, "%u\n", curr); } static ssize_t ltc4215_power_show(struct device *dev, @@ -159,7 +159,7 @@ static ssize_t ltc4215_power_show(struct device *dev, /* current in mA * voltage in mV == power in uW */ const unsigned int power = abs(output_voltage * curr); - return snprintf(buf, PAGE_SIZE, "%u\n", power); + return sysfs_emit(buf, "%u\n", power); } static ssize_t ltc4215_alarm_show(struct device *dev, @@ -170,7 +170,7 @@ static ssize_t ltc4215_alarm_show(struct device *dev, const u8 reg = data->regs[LTC4215_STATUS]; const u32 mask = attr->index; - return snprintf(buf, PAGE_SIZE, "%u\n", !!(reg & mask)); + return sysfs_emit(buf, "%u\n", !!(reg & mask)); } /* -- cgit v1.2.3