Hi, QinglangSorry 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.
On 2020/7/16 16:47, Qinglang Miao wrote:
From: Yongqiang Liu <liuyongqiang13@xxxxxxxxxx>
Use DEFINE_SHOW_ATTRIBUTE macro to simplify the code.
Signed-off-by: Yongqiang Liu <liuyongqiang13@xxxxxxxxxx>
---
 drivers/scsi/hisi_sas/hisi_sas_main.c | 137 ++------------------------
 1 file changed, 10 insertions(+), 127 deletions(-)
diff --git a/drivers/scsi/hisi_sas/hisi_sas_main.c b/drivers/scsi/hisi_sas/hisi_sas_main.c
index 852d2620e..f50b0c78f 100644
--- a/drivers/scsi/hisi_sas/hisi_sas_main.c
+++ b/drivers/scsi/hisi_sas/hisi_sas_main.c
@@ -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,
-};
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,
};
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.
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.
Glad to know your opnions.
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
+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)
 {
.