scsi: use DEVICE_ATTR_*() macros to simplify code
v2 cover scsi: use DEVICE_ATTR_*() macros to simplify code
v1 --> v2:
Combine these individual patches into a series.
Zhen Lei (4):
scsi: qedi: use DEVICE_ATTR_RO macro
scsi: qedf: use DEVICE_ATTR_RO macro
scsi: megaraid_mbox: use DEVICE_ATTR_ADMIN_RO macro
scsi: mvsas: use DEVICE_ATTR_RO/RW macro
drivers/scsi/megaraid/megaraid_mbox.c | 18 ++++++++---------- drivers/scsi/mvsas/mv_init.c | 26 +++++++++----------------- drivers/scsi/qedf/qedf_attr.c | 14 ++++++-------- drivers/scsi/qedi/qedi_sysfs.c | 14 +++++++------- 4 files changed, 30 insertions(+), 42 deletions(-)
Signature · 1 line
2.26.0.106.g9fadedd
PATCH v2 1/4 scsi: qedi: use DEVICE_ATTR_RO macro
Use DEVICE_ATTR_RO macro helper instead of plain DEVICE_ATTR, which makes the code a bit shorter and easier to read.
--- drivers/scsi/qedi/qedi_sysfs.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/scsi/qedi/qedi_sysfs.c +7 -7
@@ -16,9 +16,9 @@ static inline struct qedi_ctx *qedi_dev_to_hba(struct device *dev)return iscsi_host_priv (shost); } -static ssize_t qedi_show_port_state (struct device *dev, -struct device_attribute *attr, -char *buf) +static ssize_t port_state_show (struct device *dev, +struct device_attribute *attr, +char *buf) {struct qedi_ctx *qedi =qedi_dev_to_hba (dev);
@@ -28,8 +28,8 @@ static ssize_t qedi_show_port_state(struct device *dev,return sprintf (buf,"Linkdown\n" ); } -static ssize_t qedi_show_speed (struct device *dev, -struct device_attribute *attr,char *buf) +static ssize_t speed_show (struct device *dev, +struct device_attribute *attr,char *buf) {struct qedi_ctx *qedi =qedi_dev_to_hba (dev);struct qed_link_output if_link;
@@ -39,8 +39,8 @@ static ssize_t qedi_show_speed(struct device *dev,return sprintf (buf,"%d Gbit\n" , if_link.speed /1000 ); } -static DEVICE_ATTR(port_state, 0444, qedi_show_port_state, NULL); -static DEVICE_ATTR(speed, 0444, qedi_show_speed, NULL); +static DEVICE_ATTR_RO (port_state); +static DEVICE_ATTR_RO (speed);struct device_attribute *qedi_shost_attrs[] = { &dev_attr_port_state,
Signature · 1 line
2.26.0.106.g9fadedd
RE: [PATCH v2 1/4] scsi: qedi: use DEVICE_ATTR_RO macro
Quoted 55 lines
-----Original Message-----
From: Zhen Lei <[email protected]>
Sent: Wednesday, June 16, 2021 9:14 AM
To: Nilesh Javali <[email protected]>; Manish Rangankar <[email protected]>; Saurav Kashyap <[email protected]>; Javed Hasan <[email protected]>; Kashyap Desai <[email protected]>; Sumit Saxena <[email protected]>; Shivasharan S <[email protected]>; GR-QLogic-Storage-Upstream <[email protected]>; megaraidlinux . pdl <[email protected]>; James E . J . Bottomley <[email protected]>; Martin K . Petersen <[email protected]>; linux-scsi <[email protected]>
Cc: Zhen Lei <[email protected]>
Subject: [PATCH v2 1/4] scsi: qedi: useDEVICE_ATTR_ROmacroUse
DEVICE_ATTR_ROmacro helper instead of plainDEVICE_ATTR, which makes the code a bit shorter and easier to read.Signed-off-by Zhen Lei <[email protected]>--- drivers/scsi/qedi/qedi_sysfs.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)drivers/scsi/qedi/qedi_sysfs.c index renamed from drivers/scsi/qedi/qedi_sysfs.c +0
-0
04ee68e6499c912..be174d30eb7c275100644drivers/scsi/qedi/qedi_sysfs.c +5
-5@@ -16,9 +16,9 @@ static inline struct qedi_ctx *qedi_dev_to_hba(struct device *dev)return iscsi_host_priv (shost); } -static ssize_t qedi_show_port_state (struct device *dev, -struct device_attribute *attr, -char *buf) +static ssize_t port_state_show (struct device *dev, +struct device_attribute *attr, +char *buf) {struct qedi_ctx *qedi =qedi_dev_to_hba (dev);@@ -28,8 +28,8 @@ static ssize_t qedi_show_port_state(struct device *dev,return sprintf (buf,"Linkdown\n" ); } -static ssize_t qedi_show_speed (struct device *dev, -struct device_attribute *attr,char *buf) +static ssize_t speed_show (struct device *dev, +struct device_attribute *attr,char *buf) {struct qedi_ctx *qedi =qedi_dev_to_hba (dev);struct qed_link_output if_link;
drivers/scsi/qedi/qedi_sysfs.c static ssize_t qedi_show_speed(struct device *dev, · line 46
Quoted 10 lines
drivers/scsi/qedi/qedi_sysfs.c +2
-2@@ -39,8 +39,8 @@ static ssize_t qedi_show_speed(struct device *dev,return sprintf (buf,"%d Gbit\n" , if_link.speed /1000 ); } -static DEVICE_ATTR(port_state, 0444, qedi_show_port_state, NULL); -staticDEVICE_ATTR (speed,0444 , qedi_show_speed,NULL ); +static DEVICE_ATTR_RO (port_state); +static DEVICE_ATTR_RO (speed);struct device_attribute *qedi_shost_attrs[] = { &dev_attr_port_state, --
Thanks,
PATCH v2 2/4 scsi: qedf: use DEVICE_ATTR_RO macro
In reply to Zhen LeiUse DEVICE_ATTR_RO macro helper instead of plain DEVICE_ATTR, which makes the code a bit shorter and easier to read.
--- drivers/scsi/qedf/qedf_attr.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/scsi/qedf/qedf_attr.c +6 -8
@@ -24,9 +24,8 @@ static struct qedf_ctx *qedf_get_base_qedf(struct qedf_ctx *qedf)return lport_priv (base_lport); } -static ssize_t -qedf_fcoe_mac_show (struct device *dev, -struct device_attribute *attr,char *buf) +static ssize_t fcoe_mac_show (struct device *dev, +struct device_attribute *attr,char *buf) {struct fc_lport *lport =shost_priv (class_to_shost (dev));u32 port_id;
@@ -42,9 +41,8 @@ qedf_fcoe_mac_show(struct device *dev,return scnprintf (buf,PAGE_SIZE ,"%pM\n" , fcoe_mac); } -static ssize_t -qedf_fka_period_show (struct device *dev, -struct device_attribute *attr,char *buf) +static ssize_t fka_period_show (struct device *dev, +struct device_attribute *attr,char *buf) {struct fc_lport *lport =shost_priv (class_to_shost (dev));struct qedf_ctx *qedf =lport_priv (lport);
@@ -59,8 +57,8 @@ qedf_fka_period_show(struct device *dev,return scnprintf (buf,PAGE_SIZE ,"%d\n" , fka_period); } -static DEVICE_ATTR(fcoe_mac, S_IRUGO, qedf_fcoe_mac_show, NULL); -static DEVICE_ATTR(fka_period, S_IRUGO, qedf_fka_period_show, NULL); +static DEVICE_ATTR_RO (fcoe_mac); +static DEVICE_ATTR_RO (fka_period);struct device_attribute *qedf_host_attrs[] = { &dev_attr_fcoe_mac,
Signature · 1 line
2.26.0.106.g9fadedd
PATCH v2 3/4 scsi: megaraid_mbox: use DEVICE_ATTR_ADMIN_RO macro
In reply to Zhen LeiUse DEVICE_ATTR_ADMIN_RO macro helper instead of plain DEVICE_ATTR, which makes the code a bit shorter and easier to read.
--- drivers/scsi/megaraid/megaraid_mbox.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
drivers/scsi/megaraid/megaraid_mbox.c +8 -10
@@ -121,8 +121,8 @@ static irqreturn_t megaraid_isr(int, void *);static void megaraid_mbox_dpc (unsigned long ); -static ssize_t megaraid_sysfs_show_app_hndl (struct device *,struct device_attribute *attr,char *); -static ssize_t megaraid_sysfs_show_ldnum (struct device *,struct device_attribute *attr,char *); +static ssize_t megaraid_mbox_app_hndl_show (struct device *,struct device_attribute *attr,char *); +static ssize_t megaraid_mbox_ld_show (struct device *,struct device_attribute *attr,char *);static int megaraid_cmm_register (adapter_t *);static int megaraid_cmm_unregister (adapter_t *);
@@ -302,8 +302,7 @@ static struct pci_driver megaraid_pci_driver = {// definitions for the device attributes for exporting logical drive number // for a scsi address (Host, Channel, Id, Lun) -static DEVICE_ATTR(megaraid_mbox_app_hndl, S_IRUSR, megaraid_sysfs_show_app_hndl, - NULL); +static DEVICE_ATTR_ADMIN_RO (megaraid_mbox_app_hndl);// Host template initializer for megaraid mbox sysfs device attributes static struct device_attribute *megaraid_shost_attrs[] = {
@@ -312,7 +311,7 @@ static struct device_attribute *megaraid_shost_attrs[] = { }; -static DEVICE_ATTR(megaraid_mbox_ld, S_IRUSR, megaraid_sysfs_show_ldnum, NULL); +static DEVICE_ATTR_ADMIN_RO (megaraid_mbox_ld);// Host template initializer for megaraid mbox sysfs device attributes static struct device_attribute *megaraid_sdev_attrs[] = {
@@ -3961,7 +3960,7 @@ megaraid_sysfs_get_ldmap(adapter_t *adapter)/** -* megaraid_sysfs_show_app_hndl - display application handle for this adapter +* megaraid_mbox_app_hndl_show - display application handle for this adapter * @dev : class device object representation for the host * @attr : device attribute (unused) * @buf : buffer to send data to
@@ -3971,8 +3970,7 @@ megaraid_sysfs_get_ldmap(adapter_t *adapter)* handle, since we do not interface with applications directly. */ static ssize_t -megaraid_sysfs_show_app_hndl (struct device *dev,struct device_attribute *attr, -char *buf) +megaraid_mbox_app_hndl_show (struct device *dev,struct device_attribute *attr,char *buf) {struct Scsi_Host *shost =class_to_shost (dev);adapter_t *adapter = (adapter_t *)SCSIHOST2ADAP (shost);
@@ -3985,7 +3983,7 @@ megaraid_sysfs_show_app_hndl(struct device *dev, struct device_attribute *attr,/** -* megaraid_sysfs_show_ldnum - display the logical drive number for this device +* megaraid_mbox_ld_show - display the logical drive number for this device * @dev : device object representation for the scsi device * @attr : device attribute to show * @buf : buffer to send data to
@@ -4000,7 +3998,7 @@ megaraid_sysfs_show_app_hndl(struct device *dev, struct device_attribute *attr,* <int> <int> <int> <int> */ static ssize_t -megaraid_sysfs_show_ldnum (struct device *dev,struct device_attribute *attr,char *buf) +megaraid_mbox_ld_show (struct device *dev,struct device_attribute *attr,char *buf) {struct scsi_device *sdev =to_scsi_device (dev);adapter_t *adapter = (adapter_t *)SCSIHOST2ADAP (sdev->host);
Signature · 1 line
2.26.0.106.g9fadedd
PATCH v2 4/4 scsi: mvsas: use DEVICE_ATTR_RO/RW macro
In reply to Zhen LeiUse DEVICE_ATTR_RO/RW macro helper instead of plain DEVICE_ATTR, which makes the code a bit shorter and easier to read.
--- drivers/scsi/mvsas/mv_init.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-)
drivers/scsi/mvsas/mv_init.c +9 -17
@@ -692,22 +692,17 @@ static struct pci_driver mvs_pci_driver = { .remove = mvs_pci_remove, }; -static ssize_t -mvs_show_driver_version (struct device *cdev, -struct device_attribute *attr,char *buffer) +static ssize_t driver_version_show (struct device *cdev, +struct device_attribute *attr,char *buffer) {return snprintf (buffer,PAGE_SIZE ,"%s\n" ,DRV_VERSION ); } -static DEVICE_ATTR(driver_version, - S_IRUGO, - mvs_show_driver_version, - NULL); +static DEVICE_ATTR_RO (driver_version); -static ssize_t -mvs_store_interrupt_coalescing (struct device *cdev, -struct device_attribute *attr, -const char *buffer,size_t size) +static ssize_t interrupt_coalescing_store (struct device *cdev, +struct device_attribute *attr, +const char *buffer,size_t size) {unsigned int val =0 ;struct mvs_info *mvi =NULL ;
@@ -745,16 +740,13 @@ mvs_store_interrupt_coalescing(struct device *cdev,return strlen (buffer); } -static ssize_t mvs_show_interrupt_coalescing (struct device *cdev, -struct device_attribute *attr,char *buffer) +static ssize_t interrupt_coalescing_show (struct device *cdev, +struct device_attribute *attr,char *buffer) {return snprintf (buffer,PAGE_SIZE ,"%d\n" , interrupt_coalescing); } -static DEVICE_ATTR(interrupt_coalescing, - S_IRUGO|S_IWUSR, - mvs_show_interrupt_coalescing, - mvs_store_interrupt_coalescing); +static DEVICE_ATTR_RW (interrupt_coalescing);static int __init mvs_init (void ) {
Signature · 1 line
2.26.0.106.g9fadedd
Martin K. Petersen
AppliedZhen,
Quoted 5 lines
Zhen Lei (4):
scsi: qedi: useDEVICE_ATTR_ROmacro
scsi: qedf: useDEVICE_ATTR_ROmacro
scsi:megaraid_mbox: useDEVICE_ATTR_ADMIN_ROmacro
scsi: mvsas: use DEVICE_ATTR_RO/RW macro
Applied to 5.14/scsi-staging, thanks!
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering