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/max16065.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'drivers/hwmon/max16065.c') diff --git a/drivers/hwmon/max16065.c b/drivers/hwmon/max16065.c index 0de2da3e5c46..ae3a6a7bdaa2 100644 --- a/drivers/hwmon/max16065.c +++ b/drivers/hwmon/max16065.c @@ -187,7 +187,7 @@ static ssize_t max16065_alarm_show(struct device *dev, i2c_smbus_write_byte_data(data->client, MAX16065_FAULT(attr2->nr), val); - return snprintf(buf, PAGE_SIZE, "%d\n", !!val); + return sysfs_emit(buf, "%d\n", !!val); } static ssize_t max16065_input_show(struct device *dev, @@ -200,8 +200,8 @@ static ssize_t max16065_input_show(struct device *dev, if (unlikely(adc < 0)) return adc; - return snprintf(buf, PAGE_SIZE, "%d\n", - ADC_TO_MV(adc, data->range[attr->index])); + return sysfs_emit(buf, "%d\n", + ADC_TO_MV(adc, data->range[attr->index])); } static ssize_t max16065_current_show(struct device *dev, @@ -212,8 +212,8 @@ static ssize_t max16065_current_show(struct device *dev, if (unlikely(data->curr_sense < 0)) return data->curr_sense; - return snprintf(buf, PAGE_SIZE, "%d\n", - ADC_TO_CURR(data->curr_sense, data->curr_gain)); + return sysfs_emit(buf, "%d\n", + ADC_TO_CURR(data->curr_sense, data->curr_gain)); } static ssize_t max16065_limit_store(struct device *dev, @@ -249,8 +249,8 @@ static ssize_t max16065_limit_show(struct device *dev, struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da); struct max16065_data *data = dev_get_drvdata(dev); - return snprintf(buf, PAGE_SIZE, "%d\n", - data->limit[attr2->nr][attr2->index]); + return sysfs_emit(buf, "%d\n", + data->limit[attr2->nr][attr2->index]); } /* Construct a sensor_device_attribute structure for each register */ -- cgit 1.4.1