[PATCH] scsi:st.c replace snprintf() with sysfs_emit()

Rujra Bhatt
2025-07-24T00:58:35Z

replace snprintf() with sysfs_emit() or sysfs_emit_at() in st.c file to
follow kernel's guidelines from Documentation/filesystems/sysfs.rst
This improves safety, consistency and easier to maintain and update it
in the future.

Signed-off-by: Rujra Bhatt <braker.noob.kernel@gmail.com>
---
drivers/scsi/st.c | 42 +++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 74a6830b7ed8..38badba472d7 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -4564,25 +4564,25 @@ module_exit(exit_st);
/* The sysfs driver interface. Read-only at the moment */
static ssize_t try_direct_io_show(struct device_driver *ddp, char *buf)
{
- return scnprintf(buf, PAGE_SIZE, "%d\n", try_direct_io);
+ return sysfs_emit_at(buf, PAGE_SIZE, "%d\n", try_direct_io);
}
static DRIVER_ATTR_RO(try_direct_io);

static ssize_t fixed_buffer_size_show(struct device_driver *ddp, char *buf)
{
- return scnprintf(buf, PAGE_SIZE, "%d\n", st_fixed_buffer_size);
+ return sysfs_emit_at(buf, PAGE_SIZE, "%d\n", st_fixed_buffer_size);
}
static DRIVER_ATTR_RO(fixed_buffer_size);

static ssize_t max_sg_segs_show(struct device_driver *ddp, char *buf)
{
- return scnprintf(buf, PAGE_SIZE, "%d\n", st_max_sg_segs);
+ return sysfs_emit_at(buf, PAGE_SIZE, "%d\n", st_max_sg_segs);
}
static DRIVER_ATTR_RO(max_sg_segs);

static ssize_t version_show(struct device_driver *ddd, char *buf)
{
- return scnprintf(buf, PAGE_SIZE, "[%s]\n", verstr);
+ return sysfs_emit_at(buf, PAGE_SIZE, "[%s]\n", verstr);
}
static DRIVER_ATTR_RO(version);

@@ -4608,7 +4608,7 @@ static ssize_t debug_flag_store(struct device_driver *ddp,

static ssize_t debug_flag_show(struct device_driver *ddp, char *buf)
{
- return scnprintf(buf, PAGE_SIZE, "%d\n", debugging);
+ return sysfs_emit_at(buf, PAGE_SIZE, "%d\n", debugging);
}
static DRIVER_ATTR_RW(debug_flag);
#endif
@@ -4632,7 +4632,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_at(buf, PAGE_SIZE, "%d\n", STm->defined);
return l;
}
static DEVICE_ATTR_RO(defined);
@@ -4644,7 +4644,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_at(buf, PAGE_SIZE, "%d\n", STm->default_blksize);
return l;
}
static DEVICE_ATTR_RO(default_blksize);
@@ -4658,7 +4658,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_at(buf, PAGE_SIZE, fmt, STm->default_density);
return l;
}
static DEVICE_ATTR_RO(default_density);
@@ -4670,7 +4670,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_at(buf, PAGE_SIZE, "%d\n", STm->default_compression - 1);
return l;
}
static DEVICE_ATTR_RO(default_compression);
@@ -4699,7 +4699,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_at(buf, PAGE_SIZE, "0x%08x\n", options);
return l;
}
static DEVICE_ATTR_RO(options);
@@ -4718,7 +4718,7 @@ static ssize_t
position_lost_in_reset_show(struct device *dev,
struct st_modedef *STm = dev_get_drvdata(dev);
struct scsi_tape *STp = STm->tape;

- return sprintf(buf, "%d", STp->pos_unknown);
+ return sysfs_emit(buf, "%d", STp->pos_unknown);
}
static DEVICE_ATTR_RO(position_lost_in_reset);

@@ -4735,7 +4735,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);
@@ -4753,7 +4753,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);
@@ -4769,7 +4769,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);
@@ -4786,7 +4786,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);
@@ -4803,7 +4803,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);
@@ -4820,7 +4820,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);
@@ -4838,7 +4838,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);
@@ -4858,7 +4858,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);
@@ -4877,7 +4877,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);
@@ -4895,7 +4895,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.43.0