[PATCH v2 19/25] scsi: st: Convert sprintf() family to sysfs_emit() family

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: "Kai Mäkisara" <Kai.Makisara@xxxxxxxxxxx>
CC: "James E.J. Bottomley" <jejb@xxxxxxxxxxxxx>
CC: "Martin K. Petersen" <martin.petersen@xxxxxxxxxx>
CC: linux-scsi@xxxxxxxxxxxxxxx
Signed-off-by: Li Zhijian <lizhijian@xxxxxxxxxxx>
---
This is a part of the work "Fix coccicheck device_attr_show warnings"[1]
Split them per subsystem so that the maintainer can review it easily
[1] https://lore.kernel.org/lkml/20240116041129.3937800-1-lizhijian@xxxxxxxxxxx/
---
 drivers/scsi/st.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 338aa8c42968..998e5bb7a6a0 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -4571,7 +4571,7 @@ defined_show(struct device *dev, struct device_attribute *attr, char *buf)
 	struct st_modedef *STm = dev_get_drvdata(dev);
 	ssize_t l = 0;
 
-	l = snprintf(buf, PAGE_SIZE, "%d\n", STm->defined);
+	l = sysfs_emit(buf, "%d\n", STm->defined);
 	return l;
 }
 static DEVICE_ATTR_RO(defined);
@@ -4583,7 +4583,7 @@ default_blksize_show(struct device *dev, struct device_attribute *attr,
 	struct st_modedef *STm = dev_get_drvdata(dev);
 	ssize_t l = 0;
 
-	l = snprintf(buf, PAGE_SIZE, "%d\n", STm->default_blksize);
+	l = sysfs_emit(buf, "%d\n", STm->default_blksize);
 	return l;
 }
 static DEVICE_ATTR_RO(default_blksize);
@@ -4597,7 +4597,7 @@ default_density_show(struct device *dev, struct device_attribute *attr,
 	char *fmt;
 
 	fmt = STm->default_density >= 0 ? "0x%02x\n" : "%d\n";
-	l = snprintf(buf, PAGE_SIZE, fmt, STm->default_density);
+	l = sysfs_emit(buf, fmt, STm->default_density);
 	return l;
 }
 static DEVICE_ATTR_RO(default_density);
@@ -4609,7 +4609,7 @@ default_compression_show(struct device *dev, struct device_attribute *attr,
 	struct st_modedef *STm = dev_get_drvdata(dev);
 	ssize_t l = 0;
 
-	l = snprintf(buf, PAGE_SIZE, "%d\n", STm->default_compression - 1);
+	l = sysfs_emit(buf, "%d\n", STm->default_compression - 1);
 	return l;
 }
 static DEVICE_ATTR_RO(default_compression);
@@ -4638,7 +4638,7 @@ options_show(struct device *dev, struct device_attribute *attr, char *buf)
 	options |= STp->immediate_filemark ? MT_ST_NOWAIT_EOF : 0;
 	options |= STp->sili ? MT_ST_SILI : 0;
 
-	l = snprintf(buf, PAGE_SIZE, "0x%08x\n", options);
+	l = sysfs_emit(buf, "0x%08x\n", options);
 	return l;
 }
 static DEVICE_ATTR_RO(options);
@@ -4656,7 +4656,7 @@ static ssize_t read_cnt_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->read_cnt));
 }
 static DEVICE_ATTR_RO(read_cnt);
@@ -4674,7 +4674,7 @@ static ssize_t read_byte_cnt_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->read_byte_cnt));
 }
 static DEVICE_ATTR_RO(read_byte_cnt);
@@ -4690,7 +4690,7 @@ static ssize_t read_ns_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->tot_read_time));
 }
 static DEVICE_ATTR_RO(read_ns);
@@ -4707,7 +4707,7 @@ static ssize_t write_cnt_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->write_cnt));
 }
 static DEVICE_ATTR_RO(write_cnt);
@@ -4724,7 +4724,7 @@ static ssize_t write_byte_cnt_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->write_byte_cnt));
 }
 static DEVICE_ATTR_RO(write_byte_cnt);
@@ -4741,7 +4741,7 @@ static ssize_t write_ns_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->tot_write_time));
 }
 static DEVICE_ATTR_RO(write_ns);
@@ -4759,7 +4759,7 @@ static ssize_t in_flight_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->in_flight));
 }
 static DEVICE_ATTR_RO(in_flight);
@@ -4779,7 +4779,7 @@ static ssize_t io_ns_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->tot_io_time));
 }
 static DEVICE_ATTR_RO(io_ns);
@@ -4798,7 +4798,7 @@ static ssize_t other_cnt_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->other_cnt));
 }
 static DEVICE_ATTR_RO(other_cnt);
@@ -4816,7 +4816,7 @@ static ssize_t resid_cnt_show(struct device *dev,
 {
 	struct st_modedef *STm = dev_get_drvdata(dev);
 
-	return sprintf(buf, "%lld",
+	return sysfs_emit(buf, "%lld",
 		       (long long)atomic64_read(&STm->tape->stats->resid_cnt));
 }
 static DEVICE_ATTR_RO(resid_cnt);
-- 
2.29.2





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux