Skip to content

Commit 4e6104b

Browse files
ye xingchengroeck
authored andcommitted
hwmon: use sysfs_emit() to instead of scnprintf()
Replace the open-code with sysfs_emit() to simplify the code. Signed-off-by: ye xingchen <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 0cd3ba6 commit 4e6104b

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

drivers/hwmon/ds1621.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static ssize_t update_interval_show(struct device *dev,
269269
struct device_attribute *da, char *buf)
270270
{
271271
struct ds1621_data *data = dev_get_drvdata(dev);
272-
return scnprintf(buf, PAGE_SIZE, "%hu\n", data->update_interval);
272+
return sysfs_emit(buf, "%hu\n", data->update_interval);
273273
}
274274

275275
static ssize_t update_interval_store(struct device *dev,

drivers/hwmon/lm73.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static ssize_t temp_show(struct device *dev, struct device_attribute *da,
9292
/* use integer division instead of equivalent right shift to
9393
guarantee arithmetic shift and preserve the sign */
9494
temp = (((s16) err) * 250) / 32;
95-
return scnprintf(buf, PAGE_SIZE, "%d\n", temp);
95+
return sysfs_emit(buf, "%d\n", temp);
9696
}
9797

9898
static ssize_t convrate_store(struct device *dev, struct device_attribute *da,
@@ -137,7 +137,7 @@ static ssize_t convrate_show(struct device *dev, struct device_attribute *da,
137137
int res;
138138

139139
res = (data->ctrl & LM73_CTRL_RES_MASK) >> LM73_CTRL_RES_SHIFT;
140-
return scnprintf(buf, PAGE_SIZE, "%hu\n", lm73_convrates[res]);
140+
return sysfs_emit(buf, "%hu\n", lm73_convrates[res]);
141141
}
142142

143143
static ssize_t maxmin_alarm_show(struct device *dev,
@@ -154,7 +154,7 @@ static ssize_t maxmin_alarm_show(struct device *dev,
154154
data->ctrl = ctrl;
155155
mutex_unlock(&data->lock);
156156

157-
return scnprintf(buf, PAGE_SIZE, "%d\n", (ctrl >> attr->index) & 1);
157+
return sysfs_emit(buf, "%d\n", (ctrl >> attr->index) & 1);
158158

159159
abort:
160160
mutex_unlock(&data->lock);

drivers/hwmon/sht3x.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ static ssize_t temp1_limit_show(struct device *dev,
320320
u8 index = to_sensor_dev_attr(attr)->index;
321321
int temperature_limit = data->temperature_limits[index];
322322

323-
return scnprintf(buf, PAGE_SIZE, "%d\n", temperature_limit);
323+
return sysfs_emit(buf, "%d\n", temperature_limit);
324324
}
325325

326326
static ssize_t humidity1_limit_show(struct device *dev,
@@ -331,7 +331,7 @@ static ssize_t humidity1_limit_show(struct device *dev,
331331
u8 index = to_sensor_dev_attr(attr)->index;
332332
u32 humidity_limit = data->humidity_limits[index];
333333

334-
return scnprintf(buf, PAGE_SIZE, "%u\n", humidity_limit);
334+
return sysfs_emit(buf, "%u\n", humidity_limit);
335335
}
336336

337337
/*
@@ -483,7 +483,7 @@ static ssize_t temp1_alarm_show(struct device *dev,
483483
if (ret)
484484
return ret;
485485

486-
return scnprintf(buf, PAGE_SIZE, "%d\n", !!(buffer[0] & 0x04));
486+
return sysfs_emit(buf, "%d\n", !!(buffer[0] & 0x04));
487487
}
488488

489489
static ssize_t humidity1_alarm_show(struct device *dev,
@@ -498,7 +498,7 @@ static ssize_t humidity1_alarm_show(struct device *dev,
498498
if (ret)
499499
return ret;
500500

501-
return scnprintf(buf, PAGE_SIZE, "%d\n", !!(buffer[0] & 0x08));
501+
return sysfs_emit(buf, "%d\n", !!(buffer[0] & 0x08));
502502
}
503503

504504
static ssize_t heater_enable_show(struct device *dev,
@@ -513,7 +513,7 @@ static ssize_t heater_enable_show(struct device *dev,
513513
if (ret)
514514
return ret;
515515

516-
return scnprintf(buf, PAGE_SIZE, "%d\n", !!(buffer[0] & 0x20));
516+
return sysfs_emit(buf, "%d\n", !!(buffer[0] & 0x20));
517517
}
518518

519519
static ssize_t heater_enable_store(struct device *dev,
@@ -550,7 +550,7 @@ static ssize_t update_interval_show(struct device *dev,
550550
{
551551
struct sht3x_data *data = dev_get_drvdata(dev);
552552

553-
return scnprintf(buf, PAGE_SIZE, "%u\n",
553+
return sysfs_emit(buf, "%u\n",
554554
mode_to_update_interval[data->mode]);
555555
}
556556

0 commit comments

Comments
 (0)