[PATCH v2 08/25] scsi: mpt3sas: Convert sprintf() family to sysfs_emit() family
From: Li Zhijian
Date: Tue Mar 19 2024 - 02:34:56 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().
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: Sathya Prakash <sathya.prakash@xxxxxxxxxxxx>
CC: Sreekanth Reddy <sreekanth.reddy@xxxxxxxxxxxx>
CC: Suganath Prabu Subramani <suganath-prabu.subramani@xxxxxxxxxxxx>
CC: "James E.J. Bottomley" <jejb@xxxxxxxxxxxxx>
CC: "Martin K. Petersen" <martin.petersen@xxxxxxxxxx>
CC: linux-scsi@xxxxxxxxxxxxxxx
CC: MPT-FusionLinux.pdl@xxxxxxxxxxxx
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/mpt3sas/mpt3sas_ctl.c | 85 +++++++++++++++---------------
1 file changed, 43 insertions(+), 42 deletions(-)
diff --git a/drivers/scsi/mpt3sas/mpt3sas_ctl.c b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
index 1c9fd26195b8..4ac3b13f7025 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_ctl.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_ctl.c
@@ -2876,11 +2876,11 @@ version_fw_show(struct device *cdev, struct device_attribute *attr,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
- (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
- (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
- (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
- ioc->facts.FWVersion.Word & 0x000000FF);
+ return sysfs_emit(buf, "%02d.%02d.%02d.%02d\n",
+ (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
+ (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
+ (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
+ ioc->facts.FWVersion.Word & 0x000000FF);
}
static DEVICE_ATTR_RO(version_fw);
@@ -2901,11 +2901,11 @@ version_bios_show(struct device *cdev, struct device_attribute *attr,
u32 version = le32_to_cpu(ioc->bios_pg3.BiosVersion);
- return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
- (version & 0xFF000000) >> 24,
- (version & 0x00FF0000) >> 16,
- (version & 0x0000FF00) >> 8,
- version & 0x000000FF);
+ return sysfs_emit(buf, "%02d.%02d.%02d.%02d\n",
+ (version & 0xFF000000) >> 24,
+ (version & 0x00FF0000) >> 16,
+ (version & 0x0000FF00) >> 8,
+ version & 0x000000FF);
}
static DEVICE_ATTR_RO(version_bios);
@@ -2924,8 +2924,9 @@ version_mpi_show(struct device *cdev, struct device_attribute *attr,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, PAGE_SIZE, "%03x.%02x\n",
- ioc->facts.MsgVersion, ioc->facts.HeaderVersion >> 8);
+ return sysfs_emit(buf, "%03x.%02x\n",
+ ioc->facts.MsgVersion,
+ ioc->facts.HeaderVersion >> 8);
}
static DEVICE_ATTR_RO(version_mpi);
@@ -2944,7 +2945,7 @@ version_product_show(struct device *cdev, struct device_attribute *attr,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, 16, "%s\n", ioc->manu_pg0.ChipName);
+ return sysfs_emit(buf, "%s\n", ioc->manu_pg0.ChipName);
}
static DEVICE_ATTR_RO(version_product);
@@ -2963,8 +2964,8 @@ version_nvdata_persistent_show(struct device *cdev,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, PAGE_SIZE, "%08xh\n",
- le32_to_cpu(ioc->iounit_pg0.NvdataVersionPersistent.Word));
+ return sysfs_emit(buf, "%08xh\n",
+ le32_to_cpu(ioc->iounit_pg0.NvdataVersionPersistent.Word));
}
static DEVICE_ATTR_RO(version_nvdata_persistent);
@@ -2983,8 +2984,8 @@ version_nvdata_default_show(struct device *cdev, struct device_attribute
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, PAGE_SIZE, "%08xh\n",
- le32_to_cpu(ioc->iounit_pg0.NvdataVersionDefault.Word));
+ return sysfs_emit(buf, "%08xh\n",
+ le32_to_cpu(ioc->iounit_pg0.NvdataVersionDefault.Word));
}
static DEVICE_ATTR_RO(version_nvdata_default);
@@ -3003,7 +3004,7 @@ board_name_show(struct device *cdev, struct device_attribute *attr,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardName);
+ return sysfs_emit(buf, "%s\n", ioc->manu_pg0.BoardName);
}
static DEVICE_ATTR_RO(board_name);
@@ -3022,7 +3023,7 @@ board_assembly_show(struct device *cdev, struct device_attribute *attr,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardAssembly);
+ return sysfs_emit(buf, "%s\n", ioc->manu_pg0.BoardAssembly);
}
static DEVICE_ATTR_RO(board_assembly);
@@ -3041,7 +3042,7 @@ board_tracer_show(struct device *cdev, struct device_attribute *attr,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, 16, "%s\n", ioc->manu_pg0.BoardTracerNumber);
+ return sysfs_emit(buf, "%s\n", ioc->manu_pg0.BoardTracerNumber);
}
static DEVICE_ATTR_RO(board_tracer);
@@ -3063,7 +3064,7 @@ io_delay_show(struct device *cdev, struct device_attribute *attr,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);
+ return sysfs_emit(buf, "%02d\n", ioc->io_missing_delay);
}
static DEVICE_ATTR_RO(io_delay);
@@ -3085,7 +3086,7 @@ device_delay_show(struct device *cdev, struct device_attribute *attr,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);
+ return sysfs_emit(buf, "%02d\n", ioc->device_missing_delay);
}
static DEVICE_ATTR_RO(device_delay);
@@ -3106,7 +3107,7 @@ fw_queue_depth_show(struct device *cdev, struct device_attribute *attr,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->facts.RequestCredit);
+ return sysfs_emit(buf, "%02d\n", ioc->facts.RequestCredit);
}
static DEVICE_ATTR_RO(fw_queue_depth);
@@ -3128,8 +3129,8 @@ host_sas_address_show(struct device *cdev, struct device_attribute *attr,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
- (unsigned long long)ioc->sas_hba.sas_address);
+ return sysfs_emit(buf, "0x%016llx\n",
+ (unsigned long long)ioc->sas_hba.sas_address);
}
static DEVICE_ATTR_RO(host_sas_address);
@@ -3148,7 +3149,7 @@ logging_level_show(struct device *cdev, struct device_attribute *attr,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->logging_level);
+ return sysfs_emit(buf, "%08xh\n", ioc->logging_level);
}
static ssize_t
logging_level_store(struct device *cdev, struct device_attribute *attr,
@@ -3184,7 +3185,7 @@ fwfault_debug_show(struct device *cdev, struct device_attribute *attr,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, PAGE_SIZE, "%d\n", ioc->fwfault_debug);
+ return sysfs_emit(buf, "%d\n", ioc->fwfault_debug);
}
static ssize_t
fwfault_debug_store(struct device *cdev, struct device_attribute *attr,
@@ -3221,7 +3222,7 @@ ioc_reset_count_show(struct device *cdev, struct device_attribute *attr,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, PAGE_SIZE, "%d\n", ioc->ioc_reset_count);
+ return sysfs_emit(buf, "%d\n", ioc->ioc_reset_count);
}
static DEVICE_ATTR_RO(ioc_reset_count);
@@ -3249,7 +3250,7 @@ reply_queue_count_show(struct device *cdev,
else
reply_queue_count = 1;
- return snprintf(buf, PAGE_SIZE, "%d\n", reply_queue_count);
+ return sysfs_emit(buf, "%d\n", reply_queue_count);
}
static DEVICE_ATTR_RO(reply_queue_count);
@@ -3314,7 +3315,7 @@ BRM_status_show(struct device *cdev, struct device_attribute *attr,
/* BRM status is in bit zero of GPIOVal[24] */
backup_rail_monitor_status = le16_to_cpu(io_unit_pg3.GPIOVal[24]);
- rc = snprintf(buf, PAGE_SIZE, "%d\n", (backup_rail_monitor_status & 1));
+ rc = sysfs_emit(buf, "%d\n", (backup_rail_monitor_status & 1));
out:
mutex_unlock(&ioc->pci_access_mutex);
@@ -3371,7 +3372,7 @@ host_trace_buffer_size_show(struct device *cdev,
size = le32_to_cpu(request_data->Size);
ioc->ring_buffer_sz = size;
- return snprintf(buf, PAGE_SIZE, "%d\n", size);
+ return sysfs_emit(buf, "%d\n", size);
}
static DEVICE_ATTR_RO(host_trace_buffer_size);
@@ -3458,12 +3459,12 @@ host_trace_buffer_enable_show(struct device *cdev,
if ((!ioc->diag_buffer[MPI2_DIAG_BUF_TYPE_TRACE]) ||
((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_REGISTERED) == 0))
- return snprintf(buf, PAGE_SIZE, "off\n");
+ return sysfs_emit(buf, "off\n");
else if ((ioc->diag_buffer_status[MPI2_DIAG_BUF_TYPE_TRACE] &
MPT3_DIAG_BUFFER_IS_RELEASED))
- return snprintf(buf, PAGE_SIZE, "release\n");
+ return sysfs_emit(buf, "release\n");
else
- return snprintf(buf, PAGE_SIZE, "post\n");
+ return sysfs_emit(buf, "post\n");
}
static ssize_t
@@ -3879,7 +3880,7 @@ drv_support_bitmap_show(struct device *cdev,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, PAGE_SIZE, "0x%08x\n", ioc->drv_support_bitmap);
+ return sysfs_emit(buf, "0x%08x\n", ioc->drv_support_bitmap);
}
static DEVICE_ATTR_RO(drv_support_bitmap);
@@ -3899,7 +3900,7 @@ enable_sdev_max_qd_show(struct device *cdev,
struct Scsi_Host *shost = class_to_shost(cdev);
struct MPT3SAS_ADAPTER *ioc = shost_priv(shost);
- return snprintf(buf, PAGE_SIZE, "%d\n", ioc->enable_sdev_max_qd);
+ return sysfs_emit(buf, "%d\n", ioc->enable_sdev_max_qd);
}
/**
@@ -4047,8 +4048,8 @@ sas_address_show(struct device *dev, struct device_attribute *attr,
struct scsi_device *sdev = to_scsi_device(dev);
struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
- return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
- (unsigned long long)sas_device_priv_data->sas_target->sas_address);
+ return sysfs_emit(buf, "0x%016llx\n", (unsigned long long)
+ sas_device_priv_data->sas_target->sas_address);
}
static DEVICE_ATTR_RO(sas_address);
@@ -4069,8 +4070,8 @@ sas_device_handle_show(struct device *dev, struct device_attribute *attr,
struct scsi_device *sdev = to_scsi_device(dev);
struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
- return snprintf(buf, PAGE_SIZE, "0x%04x\n",
- sas_device_priv_data->sas_target->handle);
+ return sysfs_emit(buf, "0x%04x\n",
+ sas_device_priv_data->sas_target->handle);
}
static DEVICE_ATTR_RO(sas_device_handle);
@@ -4107,8 +4108,8 @@ sas_ncq_prio_enable_show(struct device *dev,
struct scsi_device *sdev = to_scsi_device(dev);
struct MPT3SAS_DEVICE *sas_device_priv_data = sdev->hostdata;
- return snprintf(buf, PAGE_SIZE, "%d\n",
- sas_device_priv_data->ncq_prio_enable);
+ return sysfs_emit(buf, "%d\n",
+ sas_device_priv_data->ncq_prio_enable);
}
static ssize_t
--
2.29.2