Skip to content

Commit

Permalink
block: Replace sprintf() with sysfs_emit()
Browse files Browse the repository at this point in the history
Per Documentation/filesystems/sysfs.rst, show() should only use
sysfs_emit() or sysfs_emit_at() when formatting the value to be
returned to user space.

No functional change intended.

Signed-off-by: zhangguopeng <[email protected]>
Suggested-by: Christoph Hellwig <[email protected]>
Reviewed-by: Christoph Hellwig <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
zhangguopeng authored and axboe committed Nov 7, 2024
1 parent 4122fef commit 8e71afb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
24 changes: 12 additions & 12 deletions block/blk-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct queue_sysfs_entry {
static ssize_t
queue_var_show(unsigned long var, char *page)
{
return sprintf(page, "%lu\n", var);
return sysfs_emit(page, "%lu\n", var);
}

static ssize_t
Expand Down Expand Up @@ -121,7 +121,7 @@ QUEUE_SYSFS_LIMIT_SHOW(atomic_write_unit_max)
#define QUEUE_SYSFS_LIMIT_SHOW_SECTORS_TO_BYTES(_field) \
static ssize_t queue_##_field##_show(struct gendisk *disk, char *page) \
{ \
return sprintf(page, "%llu\n", \
return sysfs_emit(page, "%llu\n", \
(unsigned long long)disk->queue->limits._field << \
SECTOR_SHIFT); \
}
Expand All @@ -144,7 +144,7 @@ QUEUE_SYSFS_LIMIT_SHOW_SECTORS_TO_KB(max_hw_sectors)
#define QUEUE_SYSFS_SHOW_CONST(_name, _val) \
static ssize_t queue_##_name##_show(struct gendisk *disk, char *page) \
{ \
return sprintf(page, "%d\n", _val); \
return sysfs_emit(page, "%d\n", _val); \
}

/* deprecated fields */
Expand Down Expand Up @@ -235,7 +235,7 @@ static ssize_t queue_feature_store(struct gendisk *disk, const char *page,
#define QUEUE_SYSFS_FEATURE(_name, _feature) \
static ssize_t queue_##_name##_show(struct gendisk *disk, char *page) \
{ \
return sprintf(page, "%u\n", \
return sysfs_emit(page, "%u\n", \
!!(disk->queue->limits.features & _feature)); \
} \
static ssize_t queue_##_name##_store(struct gendisk *disk, \
Expand All @@ -252,7 +252,7 @@ QUEUE_SYSFS_FEATURE(stable_writes, BLK_FEAT_STABLE_WRITES);
#define QUEUE_SYSFS_FEATURE_SHOW(_name, _feature) \
static ssize_t queue_##_name##_show(struct gendisk *disk, char *page) \
{ \
return sprintf(page, "%u\n", \
return sysfs_emit(page, "%u\n", \
!!(disk->queue->limits.features & _feature)); \
}

Expand All @@ -263,8 +263,8 @@ QUEUE_SYSFS_FEATURE_SHOW(dax, BLK_FEAT_DAX);
static ssize_t queue_zoned_show(struct gendisk *disk, char *page)
{
if (blk_queue_is_zoned(disk->queue))
return sprintf(page, "host-managed\n");
return sprintf(page, "none\n");
return sysfs_emit(page, "host-managed\n");
return sysfs_emit(page, "none\n");
}

static ssize_t queue_nr_zones_show(struct gendisk *disk, char *page)
Expand Down Expand Up @@ -377,7 +377,7 @@ static ssize_t queue_poll_store(struct gendisk *disk, const char *page,

static ssize_t queue_io_timeout_show(struct gendisk *disk, char *page)
{
return sprintf(page, "%u\n", jiffies_to_msecs(disk->queue->rq_timeout));
return sysfs_emit(page, "%u\n", jiffies_to_msecs(disk->queue->rq_timeout));
}

static ssize_t queue_io_timeout_store(struct gendisk *disk, const char *page,
Expand All @@ -398,8 +398,8 @@ static ssize_t queue_io_timeout_store(struct gendisk *disk, const char *page,
static ssize_t queue_wc_show(struct gendisk *disk, char *page)
{
if (blk_queue_write_cache(disk->queue))
return sprintf(page, "write back\n");
return sprintf(page, "write through\n");
return sysfs_emit(page, "write back\n");
return sysfs_emit(page, "write through\n");
}

static ssize_t queue_wc_store(struct gendisk *disk, const char *page,
Expand Down Expand Up @@ -530,9 +530,9 @@ static ssize_t queue_wb_lat_show(struct gendisk *disk, char *page)
return -EINVAL;

if (wbt_disabled(disk->queue))
return sprintf(page, "0\n");
return sysfs_emit(page, "0\n");

return sprintf(page, "%llu\n",
return sysfs_emit(page, "%llu\n",
div_u64(wbt_get_min_lat(disk->queue), 1000));
}

Expand Down
30 changes: 15 additions & 15 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ static ssize_t disk_badblocks_show(struct device *dev,
struct gendisk *disk = dev_to_disk(dev);

if (!disk->bb)
return sprintf(page, "\n");
return sysfs_emit(page, "\n");

return badblocks_show(disk->bb, page, 0);
}
Expand Down Expand Up @@ -931,15 +931,15 @@ static ssize_t disk_range_show(struct device *dev,
{
struct gendisk *disk = dev_to_disk(dev);

return sprintf(buf, "%d\n", disk->minors);
return sysfs_emit(buf, "%d\n", disk->minors);
}

static ssize_t disk_ext_range_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct gendisk *disk = dev_to_disk(dev);

return sprintf(buf, "%d\n",
return sysfs_emit(buf, "%d\n",
(disk->flags & GENHD_FL_NO_PART) ? 1 : DISK_MAX_PARTS);
}

Expand All @@ -948,7 +948,7 @@ static ssize_t disk_removable_show(struct device *dev,
{
struct gendisk *disk = dev_to_disk(dev);

return sprintf(buf, "%d\n",
return sysfs_emit(buf, "%d\n",
(disk->flags & GENHD_FL_REMOVABLE ? 1 : 0));
}

Expand All @@ -957,7 +957,7 @@ static ssize_t disk_hidden_show(struct device *dev,
{
struct gendisk *disk = dev_to_disk(dev);

return sprintf(buf, "%d\n",
return sysfs_emit(buf, "%d\n",
(disk->flags & GENHD_FL_HIDDEN ? 1 : 0));
}

Expand All @@ -966,13 +966,13 @@ static ssize_t disk_ro_show(struct device *dev,
{
struct gendisk *disk = dev_to_disk(dev);

return sprintf(buf, "%d\n", get_disk_ro(disk) ? 1 : 0);
return sysfs_emit(buf, "%d\n", get_disk_ro(disk) ? 1 : 0);
}

ssize_t part_size_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%llu\n", bdev_nr_sectors(dev_to_bdev(dev)));
return sysfs_emit(buf, "%llu\n", bdev_nr_sectors(dev_to_bdev(dev)));
}

ssize_t part_stat_show(struct device *dev,
Expand All @@ -989,7 +989,7 @@ ssize_t part_stat_show(struct device *dev,
part_stat_unlock();
}
part_stat_read_all(bdev, &stat);
return sprintf(buf,
return sysfs_emit(buf,
"%8lu %8lu %8llu %8u "
"%8lu %8lu %8llu %8u "
"%8u %8u %8u "
Expand Down Expand Up @@ -1031,14 +1031,14 @@ ssize_t part_inflight_show(struct device *dev, struct device_attribute *attr,
else
part_in_flight_rw(bdev, inflight);

return sprintf(buf, "%8u %8u\n", inflight[0], inflight[1]);
return sysfs_emit(buf, "%8u %8u\n", inflight[0], inflight[1]);
}

static ssize_t disk_capability_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
dev_warn_once(dev, "the capability attribute has been deprecated.\n");
return sprintf(buf, "0\n");
return sysfs_emit(buf, "0\n");
}

static ssize_t disk_alignment_offset_show(struct device *dev,
Expand All @@ -1047,7 +1047,7 @@ static ssize_t disk_alignment_offset_show(struct device *dev,
{
struct gendisk *disk = dev_to_disk(dev);

return sprintf(buf, "%d\n", bdev_alignment_offset(disk->part0));
return sysfs_emit(buf, "%d\n", bdev_alignment_offset(disk->part0));
}

static ssize_t disk_discard_alignment_show(struct device *dev,
Expand All @@ -1056,21 +1056,21 @@ static ssize_t disk_discard_alignment_show(struct device *dev,
{
struct gendisk *disk = dev_to_disk(dev);

return sprintf(buf, "%d\n", bdev_alignment_offset(disk->part0));
return sysfs_emit(buf, "%d\n", bdev_alignment_offset(disk->part0));
}

static ssize_t diskseq_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct gendisk *disk = dev_to_disk(dev);

return sprintf(buf, "%llu\n", disk->diskseq);
return sysfs_emit(buf, "%llu\n", disk->diskseq);
}

static ssize_t partscan_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%u\n", disk_has_partscan(dev_to_disk(dev)));
return sysfs_emit(buf, "%u\n", disk_has_partscan(dev_to_disk(dev)));
}

static DEVICE_ATTR(range, 0444, disk_range_show, NULL);
Expand All @@ -1092,7 +1092,7 @@ static DEVICE_ATTR(partscan, 0444, partscan_show, NULL);
ssize_t part_fail_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%d\n",
return sysfs_emit(buf, "%d\n",
bdev_test_flag(dev_to_bdev(dev), BD_MAKE_IT_FAIL));
}

Expand Down

0 comments on commit 8e71afb

Please sign in to comment.