[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240319063132.1588443-13-lizhijian@fujitsu.com>
Date: Tue, 19 Mar 2024 14:31:20 +0800
From: Li Zhijian <lizhijian@...itsu.com>
To: linux-kernel@...r.kernel.org
Cc: Li Zhijian <lizhijian@...itsu.com>,
Don Brace <don.brace@...rochip.com>,
"James E.J. Bottomley" <jejb@...ux.ibm.com>,
"Martin K. Petersen" <martin.petersen@...cle.com>,
storagedev@...rochip.com,
linux-scsi@...r.kernel.org
Subject: [PATCH v2 13/25] scsi: hpsa: Convert sprintf() family to sysfs_emit() family
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: Don Brace <don.brace@...rochip.com>
CC: "James E.J. Bottomley" <jejb@...ux.ibm.com>
CC: "Martin K. Petersen" <martin.petersen@...cle.com>
CC: storagedev@...rochip.com
CC: linux-scsi@...r.kernel.org
Signed-off-by: Li Zhijian <lizhijian@...itsu.com>
---
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@fujitsu.com/
---
drivers/scsi/hpsa.c | 83 +++++++++++++++++++++------------------------
1 file changed, 38 insertions(+), 45 deletions(-)
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index af18d20f3079..8d2c1f84c739 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -445,7 +445,7 @@ static ssize_t host_show_lockup_detected(struct device *dev,
h = shost_to_hba(shost);
ld = lockup_detected(h);
- return sprintf(buf, "ld=%d\n", ld);
+ return sysfs_emit(buf, "ld=%d\n", ld);
}
static ssize_t host_store_hp_ssd_smart_path_status(struct device *dev,
@@ -525,8 +525,8 @@ static ssize_t host_show_firmware_revision(struct device *dev,
if (!h->hba_inquiry_data)
return 0;
fwrev = &h->hba_inquiry_data[32];
- return snprintf(buf, 20, "%c%c%c%c\n",
- fwrev[0], fwrev[1], fwrev[2], fwrev[3]);
+ return sysfs_emit(buf, "%c%c%c%c\n",
+ fwrev[0], fwrev[1], fwrev[2], fwrev[3]);
}
static ssize_t host_show_commands_outstanding(struct device *dev,
@@ -535,8 +535,7 @@ static ssize_t host_show_commands_outstanding(struct device *dev,
struct Scsi_Host *shost = class_to_shost(dev);
struct ctlr_info *h = shost_to_hba(shost);
- return snprintf(buf, 20, "%d\n",
- atomic_read(&h->commands_outstanding));
+ return sysfs_emit(buf, "%d\n", atomic_read(&h->commands_outstanding));
}
static ssize_t host_show_transport_mode(struct device *dev,
@@ -546,9 +545,9 @@ static ssize_t host_show_transport_mode(struct device *dev,
struct Scsi_Host *shost = class_to_shost(dev);
h = shost_to_hba(shost);
- return snprintf(buf, 20, "%s\n",
- h->transMethod & CFGTBL_Trans_Performant ?
- "performant" : "simple");
+ return sysfs_emit(buf, "%s\n",
+ h->transMethod & CFGTBL_Trans_Performant ?
+ "performant" : "simple");
}
static ssize_t host_show_hp_ssd_smart_path_status(struct device *dev,
@@ -558,8 +557,8 @@ static ssize_t host_show_hp_ssd_smart_path_status(struct device *dev,
struct Scsi_Host *shost = class_to_shost(dev);
h = shost_to_hba(shost);
- return snprintf(buf, 30, "HP SSD Smart Path %s\n",
- (h->acciopath_status == 1) ? "enabled" : "disabled");
+ return sysfs_emit(buf, "HP SSD Smart Path %s\n",
+ (h->acciopath_status == 1) ? "enabled" : "disabled");
}
/* List of controllers which cannot be hard reset on kexec with reset_devices */
@@ -642,7 +641,7 @@ static ssize_t host_show_resettable(struct device *dev,
struct Scsi_Host *shost = class_to_shost(dev);
h = shost_to_hba(shost);
- return snprintf(buf, 20, "%d\n", ctlr_is_resettable(h->board_id));
+ return sysfs_emit(buf, "%d\n", ctlr_is_resettable(h->board_id));
}
static inline int is_logical_dev_addr_mode(unsigned char scsi3addr[])
@@ -690,7 +689,7 @@ static ssize_t raid_level_show(struct device *dev,
/* Is this even a logical drive? */
if (!is_logical_device(hdev)) {
spin_unlock_irqrestore(&h->lock, flags);
- l = snprintf(buf, PAGE_SIZE, "N/A\n");
+ l = sysfs_emit(buf, "N/A\n");
return l;
}
@@ -698,7 +697,7 @@ static ssize_t raid_level_show(struct device *dev,
spin_unlock_irqrestore(&h->lock, flags);
if (rlevel > RAID_UNKNOWN)
rlevel = RAID_UNKNOWN;
- l = snprintf(buf, PAGE_SIZE, "RAID %s\n", raid_label[rlevel]);
+ l = sysfs_emit(buf, "RAID %s\n", raid_label[rlevel]);
return l;
}
@@ -721,7 +720,7 @@ static ssize_t lunid_show(struct device *dev,
}
memcpy(lunid, hdev->scsi3addr, sizeof(lunid));
spin_unlock_irqrestore(&h->lock, flags);
- return snprintf(buf, 20, "0x%8phN\n", lunid);
+ return sysfs_emit(buf, "0x%8phN\n", lunid);
}
static ssize_t unique_id_show(struct device *dev,
@@ -743,13 +742,12 @@ static ssize_t unique_id_show(struct device *dev,
}
memcpy(sn, hdev->device_id, sizeof(sn));
spin_unlock_irqrestore(&h->lock, flags);
- return snprintf(buf, 16 * 2 + 2,
- "%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],
- sn[8], sn[9], sn[10], sn[11],
- sn[12], sn[13], sn[14], sn[15]);
+ 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],
+ sn[8], sn[9], sn[10], sn[11],
+ sn[12], sn[13], sn[14], sn[15]);
}
static ssize_t sas_address_show(struct device *dev,
@@ -772,7 +770,7 @@ static ssize_t sas_address_show(struct device *dev,
sas_address = hdev->sas_address;
spin_unlock_irqrestore(&h->lock, flags);
- return snprintf(buf, PAGE_SIZE, "0x%016llx\n", sas_address);
+ return sysfs_emit(buf, "0x%016llx\n", sas_address);
}
static ssize_t host_show_hp_ssd_smart_path_enabled(struct device *dev,
@@ -796,10 +794,10 @@ static ssize_t host_show_hp_ssd_smart_path_enabled(struct device *dev,
spin_unlock_irqrestore(&h->lock, flags);
if (hdev->devtype == TYPE_DISK || hdev->devtype == TYPE_ZBC)
- return snprintf(buf, 20, "%d\n", offload_enabled);
+ return sysfs_emit(buf, "%d\n", offload_enabled);
else
- return snprintf(buf, 40, "%s\n",
- "Not applicable for a controller");
+ return sysfs_emit(buf, "%s\n",
+ "Not applicable for a controller");
}
#define MAX_PATHS 8
@@ -837,17 +835,15 @@ static ssize_t path_info_show(struct device *dev,
else
continue;
- output_len += scnprintf(buf + output_len,
- PAGE_SIZE - output_len,
+ output_len += sysfs_emit_at(buf, output_len,
"[%d:%d:%d:%d] %20.20s ",
h->scsi_host->host_no,
hdev->bus, hdev->target, hdev->lun,
scsi_device_type(hdev->devtype));
if (hdev->devtype == TYPE_RAID || is_logical_device(hdev)) {
- output_len += scnprintf(buf + output_len,
- PAGE_SIZE - output_len,
- "%s\n", active);
+ output_len += sysfs_emit_at(buf, output_len,
+ "%s\n", active);
continue;
}
@@ -858,30 +854,27 @@ static ssize_t path_info_show(struct device *dev,
phys_connector[0] = '0';
if (phys_connector[1] < '0')
phys_connector[1] = '0';
- output_len += scnprintf(buf + output_len,
- PAGE_SIZE - output_len,
+ output_len += sysfs_emit_at(buf, output_len,
"PORT: %.2s ",
phys_connector);
if ((hdev->devtype == TYPE_DISK || hdev->devtype == TYPE_ZBC) &&
hdev->expose_device) {
if (box == 0 || box == 0xFF) {
- output_len += scnprintf(buf + output_len,
- PAGE_SIZE - output_len,
- "BAY: %hhu %s\n",
- bay, active);
+ output_len += sysfs_emit_at(buf, output_len,
+ "BAY: %hhu %s\n",
+ bay, active);
} else {
- output_len += scnprintf(buf + output_len,
- PAGE_SIZE - output_len,
+ output_len += sysfs_emit_at(buf, output_len,
"BOX: %hhu BAY: %hhu %s\n",
box, bay, active);
}
} else if (box != 0 && box != 0xFF) {
- output_len += scnprintf(buf + output_len,
- PAGE_SIZE - output_len, "BOX: %hhu %s\n",
- box, active);
+ output_len += sysfs_emit_at(buf, output_len,
+ "BOX: %hhu %s\n",
+ box, active);
} else
- output_len += scnprintf(buf + output_len,
- PAGE_SIZE - output_len, "%s\n", active);
+ output_len += sysfs_emit_at(buf, output_len,
+ "%s\n", active);
}
spin_unlock_irqrestore(&h->devlock, flags);
@@ -895,7 +888,7 @@ static ssize_t host_show_ctlr_num(struct device *dev,
struct Scsi_Host *shost = class_to_shost(dev);
h = shost_to_hba(shost);
- return snprintf(buf, 20, "%d\n", h->ctlr);
+ return sysfs_emit(buf, "%d\n", h->ctlr);
}
static ssize_t host_show_legacy_board(struct device *dev,
@@ -905,7 +898,7 @@ static ssize_t host_show_legacy_board(struct device *dev,
struct Scsi_Host *shost = class_to_shost(dev);
h = shost_to_hba(shost);
- return snprintf(buf, 20, "%d\n", h->legacy_board ? 1 : 0);
+ return sysfs_emit(buf, "%d\n", h->legacy_board ? 1 : 0);
}
static DEVICE_ATTR_RO(raid_level);
--
2.29.2
Powered by blists - more mailing lists