[PATCH 17/42] drivers/scsi/aacraid: Convert snprintf to sysfs_emit

From: Li Zhijian
Date: Tue Jan 16 2024 - 00:00:11 EST


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().

> ./drivers/scsi/aacraid/linit.c:1299:8-16: WARNING: please use sysfs_emit
> ./drivers/scsi/aacraid/linit.c:1325:8-16: WARNING: please use sysfs_emit
> ./drivers/scsi/aacraid/linit.c:1332:8-16: WARNING: please use sysfs_emit
> ./drivers/scsi/aacraid/linit.c:561:9-17: WARNING: please use sysfs_emit
> ./drivers/scsi/aacraid/linit.c:588:8-16: WARNING: please use sysfs_emit

No functional change intended

CC: Adaptec OEM Raid Solutions <aacraid@xxxxxxxxxxxxx>
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>
---
drivers/scsi/aacraid/linit.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index 68f4dbcfff49..f534f5d985f1 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -558,11 +558,10 @@ static ssize_t aac_show_raid_level(struct device *dev, struct device_attribute *
struct scsi_device *sdev = to_scsi_device(dev);
struct aac_dev *aac = (struct aac_dev *)(sdev->host->hostdata);
if (sdev_channel(sdev) != CONTAINER_CHANNEL)
- return snprintf(buf, PAGE_SIZE, sdev->no_uld_attach
- ? "Hidden\n" :
+ return sysfs_emit(buf, sdev->no_uld_attacha ? "Hidden\n" :
((aac->jbod && (sdev->type == TYPE_DISK)) ? "JBOD\n" : ""));
- return snprintf(buf, PAGE_SIZE, "%s\n",
- get_container_type(aac->fsa_dev[sdev_id(sdev)].type));
+ return sysfs_emit(buf, "%s\n",
+ get_container_type(aac->fsa_dev[sdev_id(sdev)].type));
}

static struct device_attribute aac_raid_level_attr = {
@@ -585,7 +584,7 @@ static ssize_t aac_show_unique_id(struct device *dev,
if (sdev_channel(sdev) == CONTAINER_CHANNEL)
memcpy(sn, aac->fsa_dev[sdev_id(sdev)].identifier, sizeof(sn));

- return snprintf(buf, 16 * 2 + 2,
+ return sysfs_emit(buf,
"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
sn[0], sn[1], sn[2], sn[3],
sn[4], sn[5], sn[6], sn[7],
@@ -1296,7 +1295,7 @@ static ssize_t aac_show_driver_version(struct device *device,
struct device_attribute *attr,
char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%s\n", aac_driver_version);
+ return sysfs_emit(buf, "%s\n", aac_driver_version);
}

static ssize_t aac_show_serial_number(struct device *device,
@@ -1322,15 +1321,13 @@ static ssize_t aac_show_serial_number(struct device *device,
static ssize_t aac_show_max_channel(struct device *device,
struct device_attribute *attr, char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%d\n",
- class_to_shost(device)->max_channel);
+ return sysfs_emit(buf, "%d\n", class_to_shost(device)->max_channel);
}

static ssize_t aac_show_max_id(struct device *device,
struct device_attribute *attr, char *buf)
{
- return snprintf(buf, PAGE_SIZE, "%d\n",
- class_to_shost(device)->max_id);
+ return sysfs_emit(buf, "%d\n", class_to_shost(device)->max_id);
}

static ssize_t aac_store_reset_adapter(struct device *device,
--
2.29.2