scsi: hisi_sas: Convert to DEFINE_SHOW_ATTRIBUTE
Subsystems (2)
PATCH 1/1 scsi: hisi_sas: Convert to DEFINE_SHOW_ATTRIBUTE
From: Yongqiang Liu <[email protected]>
Use DEFINE_SHOW_ATTRIBUTE macro to simplify the code.
--- drivers/scsi/hisi_sas/hisi_sas_main.c | 137 ++------------------------ 1 file changed, 10 insertions(+), 127 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_main.c +10 -127
@@ -2870,19 +2870,7 @@ static int hisi_sas_debugfs_global_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_global_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_global_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_global_fops = { - .open = hisi_sas_debugfs_global_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_global);static int hisi_sas_debugfs_axi_show (struct seq_file *s,void *p) {
@@ -2897,19 +2885,7 @@ static int hisi_sas_debugfs_axi_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_axi_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_axi_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_axi_fops = { - .open = hisi_sas_debugfs_axi_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_axi);static int hisi_sas_debugfs_ras_show (struct seq_file *s,void *p) {
@@ -2924,19 +2900,7 @@ static int hisi_sas_debugfs_ras_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_ras_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_ras_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_ras_fops = { - .open = hisi_sas_debugfs_ras_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_ras);static int hisi_sas_debugfs_port_show (struct seq_file *s,void *p) {
@@ -2951,18 +2915,7 @@ static int hisi_sas_debugfs_port_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_port_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_port_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_port_fops = { - .open = hisi_sas_debugfs_port_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_port);static void hisi_sas_show_row_64 (struct seq_file *s,int index,int sz,__le64 *ptr)
@@ -3019,18 +2972,7 @@ static int hisi_sas_debugfs_cq_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_cq_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_cq_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_cq_fops = { - .open = hisi_sas_debugfs_cq_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_cq);static void hisi_sas_dq_show_slot (struct seq_file *s,int slot,void *dq_ptr) {
@@ -3052,18 +2994,7 @@ static int hisi_sas_debugfs_dq_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_dq_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_dq_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_dq_fops = { - .open = hisi_sas_debugfs_dq_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_dq);static int hisi_sas_debugfs_iost_show (struct seq_file *s,void *p) {
@@ -3080,18 +3011,7 @@ static int hisi_sas_debugfs_iost_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_iost_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_iost_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_iost_fops = { - .open = hisi_sas_debugfs_iost_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_iost);static int hisi_sas_debugfs_iost_cache_show (struct seq_file *s,void *p) {
@@ -3117,20 +3037,7 @@ static int hisi_sas_debugfs_iost_cache_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_iost_cache_open (struct inode *inode, -struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_iost_cache_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_iost_cache_fops = { - .open = hisi_sas_debugfs_iost_cache_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_iost_cache);static int hisi_sas_debugfs_itct_show (struct seq_file *s,void *p) {
@@ -3147,18 +3054,7 @@ static int hisi_sas_debugfs_itct_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_itct_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_itct_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_itct_fops = { - .open = hisi_sas_debugfs_itct_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_itct);static int hisi_sas_debugfs_itct_cache_show (struct seq_file *s,void *p) {
@@ -3184,20 +3080,7 @@ static int hisi_sas_debugfs_itct_cache_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_itct_cache_open (struct inode *inode, -struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_itct_cache_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_itct_cache_fops = { - .open = hisi_sas_debugfs_itct_cache_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_itct_cache);static void hisi_sas_debugfs_create_files (struct hisi_hba *hisi_hba) {
Signature · 1 line
2.17.1
On 16/07/2020 09:47, Qinglang Miao wrote:
Not sure why you cc Greg, but SCSI maintainers should have been - James and Martin
Quoted 5 lines
From: Yongqiang Liu <[email protected]>
Use
DEFINE_SHOW_ATTRIBUTEmacro to simplify the code.Signed-off-by Yongqiang Liu <[email protected]>
The sender is not the author, so your signed-off-by should also be here (after sign off from Yongqiang Liu)
Quoted 16 lines
--- drivers/scsi/hisi_sas/hisi_sas_main.c | 137 ++------------------------ 1 file changed, 10 insertions(+), 127 deletions(-)drivers/scsi/hisi_sas/hisi_sas_main.c +0
-4@@ -2870,19 +2870,7 @@ static int hisi_sas_debugfs_global_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_global_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_global_show, - inode->i_private);
drivers/scsi/hisi_sas/hisi_sas_main.c static int hisi_sas_debugfs_global_show(struct seq_file *s, void *p) · line 2873
Quoted 10 lines
drivers/scsi/hisi_sas/hisi_sas_main.c +1
-9-} - -static const struct file_operations hisi_sas_debugfs_global_fops = { - .open = hisi_sas_debugfs_global_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_global);
I couldn't see an equivalent for file_operations which have a read and write method, and the driver has a few of those.
Thanks
Quoted 4 lines · John Garry
On 16/07/2020 09:47, Qinglang Miao wrote:
Not sure why you cc Greg, but SCSI maintainers should have been - James and Martin
Quoted 8 lines
Quoted 5 lines
From: Yongqiang Liu <[email protected]>
Use
DEFINE_SHOW_ATTRIBUTEmacro to simplify the code.Signed-off-by Yongqiang Liu <[email protected]>The sender is not the author, so your signed-off-by should also be here (after sign off from Yongqiang Liu)
Sorry for not knowing this rule, I will send a new patch later on if you don't mind.
Quoted 20 lines
Quoted 20 lines
---
drivers/scsi/hisi_sas/hisi_sas_main.c| 137 ++------------------------1 file changed, 10 insertions(+), 127 deletions(-)drivers/scsi/hisi_sas/hisi_sas_main.c +0
-7@@ -2870,19 +2870,7 @@ static int hisi_sas_debugfs_global_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_global_open(struct inode *inode, struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_global_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_global_fops = { - .open = hisi_sas_debugfs_global_open,
Quoted 8 lines
drivers/scsi/hisi_sas/hisi_sas_main.c static int hisi_sas_debugfs_global_show(struct seq_file *s, void *p) · line 2873
Quoted 6 lines
drivers/scsi/hisi_sas/hisi_sas_main.c +1
-5- .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_global);I couldn't see an equivalent for
file_operationswhich have a read and write method, and the driver has a few of those.
Yes, you're right. There's no equivalence when drivers have read and write method. So the file_operations we cleaned up are those without write method, like hisi_sas_debugfs_global_fops.
Quoted 3 lines
Thanks
.
Thanks
.
Hi, Qinglang
Quoted 20 lines · Qinglang Miao
From: Yongqiang Liu <[email protected]>
Use
DEFINE_SHOW_ATTRIBUTEmacro to simplify the code.Signed-off-by Yongqiang Liu <[email protected]>--- drivers/scsi/hisi_sas/hisi_sas_main.c | 137 ++------------------------ 1 file changed, 10 insertions(+), 127 deletions(-)drivers/scsi/hisi_sas/hisi_sas_main.c +0
-3@@ -2870,19 +2870,7 @@ static int hisi_sas_debugfs_global_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_global_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_global_show,
drivers/scsi/hisi_sas/hisi_sas_main.c static int hisi_sas_debugfs_global_show(struct seq_file *s, void *p) · line 2885
Quoted 10 lines
drivers/scsi/hisi_sas/hisi_sas_main.c +0
-10- inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_global_fops = { - .open = hisi_sas_debugfs_global_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -};
I saw that your code is different from code in kernel 5.8-rc4, and it should be as follow:
static const struct file_operations hisi_sas_debugfs_global_fops = { .open = hisi_sas_debugfs_global_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.owner = THIS_MODULE,
};
Plus, if we use this macro directly when we write this code, it really makes the code simpler. But if we accept the cleanup now,
we might need to consider evading compilation failures when we merge these code back to some older kernel (e.g kernel 4.14 for centOS 7.6).
I think this marco is introduced into kernel 4.16-rc2.
So I don't see much additional benefit to us from this simplification. But this marco is quite helpful and I think I will use it somewhere else.
Thanks
Jiaxing
Quoted 190 lines
drivers/scsi/hisi_sas/hisi_sas_main.c +10
-114+DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_global);static int hisi_sas_debugfs_axi_show (struct seq_file *s,void *p) {@@ -2897,19 +2885,7 @@ static int hisi_sas_debugfs_axi_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_axi_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_axi_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_axi_fops = { - .open = hisi_sas_debugfs_axi_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_axi);static int hisi_sas_debugfs_ras_show (struct seq_file *s,void *p) {@@ -2924,19 +2900,7 @@ static int hisi_sas_debugfs_ras_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_ras_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_ras_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_ras_fops = { - .open = hisi_sas_debugfs_ras_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_ras);static int hisi_sas_debugfs_port_show (struct seq_file *s,void *p) {@@ -2951,18 +2915,7 @@ static int hisi_sas_debugfs_port_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_port_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_port_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_port_fops = { - .open = hisi_sas_debugfs_port_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_port);static void hisi_sas_show_row_64 (struct seq_file *s,int index,int sz,__le64 *ptr)@@ -3019,18 +2972,7 @@ static int hisi_sas_debugfs_cq_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_cq_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_cq_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_cq_fops = { - .open = hisi_sas_debugfs_cq_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_cq);static void hisi_sas_dq_show_slot (struct seq_file *s,int slot,void *dq_ptr) {@@ -3052,18 +2994,7 @@ static int hisi_sas_debugfs_dq_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_dq_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_dq_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_dq_fops = { - .open = hisi_sas_debugfs_dq_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_dq);static int hisi_sas_debugfs_iost_show (struct seq_file *s,void *p) {@@ -3080,18 +3011,7 @@ static int hisi_sas_debugfs_iost_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_iost_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_iost_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_iost_fops = { - .open = hisi_sas_debugfs_iost_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_iost);static int hisi_sas_debugfs_iost_cache_show (struct seq_file *s,void *p) {@@ -3117,20 +3037,7 @@ static int hisi_sas_debugfs_iost_cache_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_iost_cache_open (struct inode *inode, -struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_iost_cache_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_iost_cache_fops = { - .open = hisi_sas_debugfs_iost_cache_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_iost_cache);static int hisi_sas_debugfs_itct_show (struct seq_file *s,void *p) {@@ -3147,18 +3054,7 @@ static int hisi_sas_debugfs_itct_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_itct_open (struct inode *inode,struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_itct_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_itct_fops = { - .open = hisi_sas_debugfs_itct_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_itct);static int hisi_sas_debugfs_itct_cache_show (struct seq_file *s,void *p) {@@ -3184,20 +3080,7 @@ static int hisi_sas_debugfs_itct_cache_show(struct seq_file *s, void *p)return 0 ; } -static int hisi_sas_debugfs_itct_cache_open (struct inode *inode, -struct file *filp) -{ -return single_open (filp, hisi_sas_debugfs_itct_cache_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_itct_cache_fops = { - .open = hisi_sas_debugfs_itct_cache_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner =THIS_MODULE , -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_itct_cache);static void hisi_sas_debugfs_create_files (struct hisi_hba *hisi_hba) {
Quoted 38 lines · luojiaxing
Hi, Qinglang
Quoted 21 lines · Qinglang Miao
From: Yongqiang Liu <[email protected]>
Use
DEFINE_SHOW_ATTRIBUTEmacro to simplify the code.Signed-off-by Yongqiang Liu <[email protected]>---
drivers/scsi/hisi_sas/hisi_sas_main.c| 137 ++------------------------1 file changed, 10 insertions(+), 127 deletions(-)drivers/scsi/hisi_sas/hisi_sas_main.c +0
-3@@ -2870,19 +2870,7 @@ static int hisi_sas_debugfs_global_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_global_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_global_show,drivers/scsi/hisi_sas/hisi_sas_main.c static int hisi_sas_debugfs_global_show(struct · line 2886
Quoted 10 lines
drivers/scsi/hisi_sas/hisi_sas_main.c +0
-10- inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_global_fops = { - .open = hisi_sas_debugfs_global_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -};I saw that your code is different from code in kernel 5.8-rc4, and it should be as follow:
Quoted 8 lines
static const struct
file_operationshisi_sas_debugfs_global_fops= {
.open =hisi_sas_debugfs_global_open,
.read =seq_read,
.llseek =seq_lseek,
.release =single_release,
.owner =THIS_MODULE,
};
Sorry I didn't mention it in commit log, but this patch is based on linux-next where commit <4d4901c6d7> has switched over direct seq_read method calls to seq_read_iter. I can send a new patch based on v5.8-rc if you don't mind.
Quoted 7 lines
Plus, if we use this macro directly when we write this code, it really makes the code simpler. But if we accept the cleanup now,
we might need to consider evading compilation failures when we merge these code back to some older kernel (e.g kernel 4.14 for centOS 7.6).
I think this marco is introduced into kernel 4.16-rc2.
Yes, you're right, the macro and commit <4d4901c6d7> need to be applied before this clean up patch. But I don't think this patch as well as commit<4d4901c6d7> need to be merged back to older kernel.
Quoted 7 lines
So I don't see much additional benefit to us from this simplification. But this marco is quite helpful and I think I will use it somewhere else.
Thanks
Jiaxing
Glad to know your opnions.
Thanks.
Quoted 194 lines
Quoted 182 lines
drivers/scsi/hisi_sas/hisi_sas_main.c +4
-38+DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_global); static int hisi_sas_debugfs_axi_show(struct seq_file *s, void *p) {@@ -2897,19 +2885,7 @@ static int hisi_sas_debugfs_axi_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_axi_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_axi_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_axi_fops = { - .open = hisi_sas_debugfs_axi_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_axi); static int hisi_sas_debugfs_ras_show(struct seq_file *s, void *p) {@@ -2924,19 +2900,7 @@ static int hisi_sas_debugfs_ras_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_ras_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_ras_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_ras_fops = { - .open = hisi_sas_debugfs_ras_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_ras); static int hisi_sas_debugfs_port_show(struct seq_file *s, void *p) {@@ -2951,18 +2915,7 @@ static int hisi_sas_debugfs_port_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_port_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_port_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_port_fops = { - .open = hisi_sas_debugfs_port_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_port); static void hisi_sas_show_row_64(struct seq_file *s, int index,int sz,
__le64*ptr)drivers/scsi/hisi_sas/hisi_sas_main.c +1
-12@@ -3019,18 +2972,7 @@ static int hisi_sas_debugfs_cq_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_cq_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_cq_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_cq_fops = { - .open = hisi_sas_debugfs_cq_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_cq); static void hisi_sas_dq_show_slot(struct seq_file *s, int slot, void *dq_ptr){
drivers/scsi/hisi_sas/hisi_sas_main.c +1
-12@@ -3052,18 +2994,7 @@ static int hisi_sas_debugfs_dq_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_dq_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_dq_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_dq_fops = { - .open = hisi_sas_debugfs_dq_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_dq); static int hisi_sas_debugfs_iost_show(struct seq_file *s, void *p){
drivers/scsi/hisi_sas/hisi_sas_main.c +1
-12@@ -3080,18 +3011,7 @@ static int hisi_sas_debugfs_iost_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_iost_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_iost_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_iost_fops = { - .open = hisi_sas_debugfs_iost_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_iost); static int hisi_sas_debugfs_iost_cache_show(struct seq_file *s, void *p){
drivers/scsi/hisi_sas/hisi_sas_main.c +2
-26@@ -3117,20 +3037,7 @@ static int hisi_sas_debugfs_iost_cache_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_iost_cache_open (struct inode *inode, - struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_iost_cache_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_iost_cache_fops = { - .open = hisi_sas_debugfs_iost_cache_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_iost_cache); static int hisi_sas_debugfs_itct_show(struct seq_file *s, void *p) {@@ -3147,18 +3054,7 @@ static int hisi_sas_debugfs_itct_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_itct_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_itct_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_itct_fops = { - .open = hisi_sas_debugfs_itct_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_itct); static int hisi_sas_debugfs_itct_cache_show(struct seq_file *s, void *p){
drivers/scsi/hisi_sas/hisi_sas_main.c +0
-7@@ -3184,20 +3080,7 @@ static int hisi_sas_debugfs_itct_cache_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_itct_cache_open (struct inode *inode, - struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_itct_cache_show, - inode->i_private); -} -drivers/scsi/hisi_sas/hisi_sas_main.c static int · line 3085
Quoted 10 lines
drivers/scsi/hisi_sas/hisi_sas_main.c +1
-7-static const struct file_operations hisi_sas_debugfs_itct_cache_fops = { - .open = hisi_sas_debugfs_itct_cache_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_itct_cache); static void hisi_sas_debugfs_create_files(struct hisi_hba *hisi_hba) {.
Quoted 51 lines · luojiaxing
Hi, Qinglang
Quoted 21 lines · Qinglang Miao
From: Yongqiang Liu <[email protected]>
Use
DEFINE_SHOW_ATTRIBUTEmacro to simplify the code.Signed-off-by Yongqiang Liu <[email protected]>---
drivers/scsi/hisi_sas/hisi_sas_main.c| 137 ++------------------------1 file changed, 10 insertions(+), 127 deletions(-)drivers/scsi/hisi_sas/hisi_sas_main.c +0
-3@@ -2870,19 +2870,7 @@ static int hisi_sas_debugfs_global_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_global_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_global_show,drivers/scsi/hisi_sas/hisi_sas_main.c static int hisi_sas_debugfs_global_show(struct · line 2886
Quoted 10 lines
drivers/scsi/hisi_sas/hisi_sas_main.c +0
-10- inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_global_fops = { - .open = hisi_sas_debugfs_global_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -};I saw that your code is different from code in kernel 5.8-rc4, and it should be as follow:
static const struct
file_operationshisi_sas_debugfs_global_fops= {
.open =hisi_sas_debugfs_global_open,
.read =seq_read,
.llseek =seq_lseek,
.release =single_release,
.owner =THIS_MODULE,
};Plus, if we use this macro directly when we write this code, it really makes the code simpler. But if we accept the cleanup now,
we might need to consider evading compilation failures when we merge these code back to some older kernel (e.g kernel 4.14 for centOS 7.6).
Quoted 8 lines
I think this marco is introduced into kernel 4.16-rc2.
So I don't see much additional benefit to us from this simplification. But this marco is quite helpful and I think I will use it somewhere else.
Thanks
Jiaxing
Hi Jiaxing,
I think the 'clean-up' patch means to standardize codes, which can also make readers understand codes better.
As for 'merge back', if this situation really exists, evading compilation failures should be necessary. But all you need to do is to introduce the macro.
I respect your opnion anyhow. But I still resent a new patch based against linux-next(20200917) which can be applied to mainline cleanly now just in case you need it.
Thanks.
Quoted 195 lines
Quoted 183 lines
drivers/scsi/hisi_sas/hisi_sas_main.c +4
-38+DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_global); static int hisi_sas_debugfs_axi_show(struct seq_file *s, void *p) {@@ -2897,19 +2885,7 @@ static int hisi_sas_debugfs_axi_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_axi_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_axi_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_axi_fops = { - .open = hisi_sas_debugfs_axi_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_axi); static int hisi_sas_debugfs_ras_show(struct seq_file *s, void *p) {@@ -2924,19 +2900,7 @@ static int hisi_sas_debugfs_ras_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_ras_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_ras_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_ras_fops = { - .open = hisi_sas_debugfs_ras_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_ras); static int hisi_sas_debugfs_port_show(struct seq_file *s, void *p) {@@ -2951,18 +2915,7 @@ static int hisi_sas_debugfs_port_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_port_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_port_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_port_fops = { - .open = hisi_sas_debugfs_port_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_port); static void hisi_sas_show_row_64(struct seq_file *s, int index,int sz,
__le64*ptr)drivers/scsi/hisi_sas/hisi_sas_main.c +1
-12@@ -3019,18 +2972,7 @@ static int hisi_sas_debugfs_cq_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_cq_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_cq_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_cq_fops = { - .open = hisi_sas_debugfs_cq_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_cq); static void hisi_sas_dq_show_slot(struct seq_file *s, int slot, void *dq_ptr){
drivers/scsi/hisi_sas/hisi_sas_main.c +1
-12@@ -3052,18 +2994,7 @@ static int hisi_sas_debugfs_dq_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_dq_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_dq_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_dq_fops = { - .open = hisi_sas_debugfs_dq_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_dq); static int hisi_sas_debugfs_iost_show(struct seq_file *s, void *p){
drivers/scsi/hisi_sas/hisi_sas_main.c +1
-12@@ -3080,18 +3011,7 @@ static int hisi_sas_debugfs_iost_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_iost_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_iost_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_iost_fops = { - .open = hisi_sas_debugfs_iost_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_iost); static int hisi_sas_debugfs_iost_cache_show(struct seq_file *s, void *p){
drivers/scsi/hisi_sas/hisi_sas_main.c +2
-26@@ -3117,20 +3037,7 @@ static int hisi_sas_debugfs_iost_cache_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_iost_cache_open (struct inode *inode, - struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_iost_cache_show, - inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_iost_cache_fops = { - .open = hisi_sas_debugfs_iost_cache_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_iost_cache); static int hisi_sas_debugfs_itct_show(struct seq_file *s, void *p) {@@ -3147,18 +3054,7 @@ static int hisi_sas_debugfs_itct_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_itct_open (struct inode *inode,struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_itct_show, inode->i_private); -} - -static const struct file_operations hisi_sas_debugfs_itct_fops = { - .open = hisi_sas_debugfs_itct_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_itct); static int hisi_sas_debugfs_itct_cache_show(struct seq_file *s, void *p){
drivers/scsi/hisi_sas/hisi_sas_main.c +0
-7@@ -3184,20 +3080,7 @@ static int hisi_sas_debugfs_itct_cache_show(struct seq_file *s, void *p) return 0; } -static int hisi_sas_debugfs_itct_cache_open (struct inode *inode, - struct file *filp) -{ - return single_open(filp, hisi_sas_debugfs_itct_cache_show, - inode->i_private); -} -drivers/scsi/hisi_sas/hisi_sas_main.c static int · line 3085
Quoted 10 lines
drivers/scsi/hisi_sas/hisi_sas_main.c +1
-7-static const struct file_operations hisi_sas_debugfs_itct_cache_fops = { - .open = hisi_sas_debugfs_itct_cache_open, - .read_iter = seq_read_iter, - .llseek = seq_lseek, - .release = single_release, - .owner = THIS_MODULE, -}; +DEFINE_SHOW_ATTRIBUTE (hisi_sas_debugfs_itct_cache); static void hisi_sas_debugfs_create_files(struct hisi_hba *hisi_hba) {.