mtd: use DEFINE_SHOW_ATTRIBUTE() instead of open-coding it
PATCH 1/1 mtd: use DEFINE_SHOW_ATTRIBUTE() instead of open-coding it
DEFINE_SHOW_ATTRIBUTE macro can help us simplify the code,so change to it.And change the DEBUGFS_RO_ATTR macro defined in some file to a standard macro.
--- drivers/mtd/devices/docg3.c | 16 ++++++++-------- drivers/mtd/devices/docg3.h | 11 ----------- drivers/mtd/mtdswap.c | 13 +------------ drivers/mtd/nand/raw/nandsim.c | 17 +++-------------- 4 files changed, 12 insertions(+), 45 deletions(-)
drivers/mtd/devices/docg3.c +8 -8
@@ -1603,7 +1603,7 @@ static void doc_unregister_sysfs(struct platform_device *pdev,/* * Debug sysfs entries */ -static int dbg_flashctrl_show (struct seq_file *s,void *p) +static int flashcontrol_show (struct seq_file *s,void *p) {struct docg3 *docg3 = (struct docg3 *)s->private;
@@ -1623,9 +1623,9 @@ static int dbg_flashctrl_show(struct seq_file *s, void *p)return 0 ; } -DEBUGFS_RO_ATTR (flashcontrol, dbg_flashctrl_show); +DEFINE_SHOW_ATTRIBUTE (flashcontrol); -static int dbg_asicmode_show (struct seq_file *s,void *p) +static int asic_mode_show (struct seq_file *s,void *p) {struct docg3 *docg3 = (struct docg3 *)s->private;
@@ -1660,9 +1660,9 @@ static int dbg_asicmode_show(struct seq_file *s, void *p)seq_puts (s,")\n" );return 0 ; } -DEBUGFS_RO_ATTR (asic_mode, dbg_asicmode_show); +DEFINE_SHOW_ATTRIBUTE (asic_mode); -static int dbg_device_id_show (struct seq_file *s,void *p) +static int device_id_show (struct seq_file *s,void *p) {struct docg3 *docg3 = (struct docg3 *)s->private;int id;
@@ -1674,9 +1674,9 @@ static int dbg_device_id_show(struct seq_file *s, void *p)seq_printf (s,"DeviceId = %d\n" , id);return 0 ; } -DEBUGFS_RO_ATTR (device_id, dbg_device_id_show); +DEFINE_SHOW_ATTRIBUTE (device_id); -static int dbg_protection_show (struct seq_file *s,void *p) +static int protection_show (struct seq_file *s,void *p) {struct docg3 *docg3 = (struct docg3 *)s->private;int protect, dps0, dps0_low, dps0_high, dps1, dps1_low, dps1_high;
@@ -1726,7 +1726,7 @@ static int dbg_protection_show(struct seq_file *s, void *p) !!(dps1 & DOC_DPS_KEY_OK));return 0 ; } -DEBUGFS_RO_ATTR (protection, dbg_protection_show); +DEFINE_SHOW_ATTRIBUTE (protection);static void __init doc_dbg_register (struct mtd_info *floor) {
drivers/mtd/devices/docg3.h +0 -11
@@ -317,17 +317,6 @@ struct docg3 { #define doc_info(fmt, arg...) dev_info(docg3->dev, (fmt), ## arg) #define doc_dbg(fmt, arg...) dev_dbg(docg3->dev, (fmt), ## arg) #define doc_vdbg(fmt, arg...) dev_vdbg(docg3->dev, (fmt), ## arg) - -#define DEBUGFS_RO_ATTR (name, show_fct) \ - static int name##_open(struct inode *inode, struct file *file) \ - { return single_open(file, show_fct, inode->i_private); } \ - static const struct file_operations name##_fops = { \ - .owner = THIS_MODULE, \ - .open = name##_open, \ - .llseek = seq_lseek, \ - .read = seq_read, \ - .release = single_release \ - };#endif /*
drivers/mtd/mtdswap.c +1 -12
@@ -1265,18 +1265,7 @@ static int mtdswap_show(struct seq_file *s, void *data)return 0 ; } - -static int mtdswap_open (struct inode *inode,struct file *file) -{ -return single_open (file, mtdswap_show, inode->i_private); -} - -static const struct file_operations mtdswap_fops = { - .open = mtdswap_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; +DEFINE_SHOW_ATTRIBUTE (mtdswap);static int mtdswap_add_debugfs (struct mtdswap_dev *d) {
drivers/mtd/nand/raw/nandsim.c +3 -14
@@ -443,7 +443,7 @@ static unsigned long total_wear = 0;/* MTD structure for NAND controller */ static struct mtd_info *nsmtd; -static int nandsim_debugfs_show (struct seq_file *m,void *private) +static int nandsim_show (struct seq_file *m,void *private) {unsigned long wmin =-1 , wmax =0 , avg;unsigned long deciles[10 ], decile_max[10 ], tot =0 ;
@@ -494,18 +494,7 @@ static int nandsim_debugfs_show(struct seq_file *m, void *private)return 0 ; } - -static int nandsim_debugfs_open (struct inode *inode,struct file *file) -{ -return single_open (file, nandsim_debugfs_show, inode->i_private); -} - -static const struct file_operations dfs_fops = { - .open = nandsim_debugfs_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; +DEFINE_SHOW_ATTRIBUTE (nandsim);/** * nandsim_debugfs_create - initialize debugfs
@@ -531,7 +520,7 @@ static int nandsim_debugfs_create(struct nandsim *dev) } dent =debugfs_create_file ("nandsim_wear_report" ,S_IRUSR , - root, dev, &dfs_fops); + root, dev, &nandsim_fops);if (IS_ERR_OR_NULL (dent)) {NS_ERR ("cannot create \"nandsim_wear_report\" debugfs entry\n" );return -1 ;
Signature · 1 line
2.17.0
Should be [PATCH v4]
Quoted 3 lines · On Sun, 2 Dec 2018 03:33:58 -0500 Yangtao Li <[email protected]> wrote:
DEFINE_SHOW_ATTRIBUTEmacro can help us simplify the code,so change to it.And change theDEBUGFS_RO_ATTRmacro defined in some file to a standard macro.
You still don't put spaces after commas or periods
Quoted 3 lines
Signed-off-by Yangtao Li <[email protected]>---
and you miss a changelog here.
Anyway, no need to send a new version, I'll fix the commit message when applying the patch.
Thanks,
Boris
Quoted 152 lines
drivers/mtd/devices/docg3.c | 16 ++++++++-------- drivers/mtd/devices/docg3.h | 11 ----------- drivers/mtd/mtdswap.c | 13 +------------ drivers/mtd/nand/raw/nandsim.c | 17 +++-------------- 4 files changed, 12 insertions(+), 45 deletions(-)drivers/mtd/devices/docg3.c +8
-8@@ -1603,7 +1603,7 @@ static void doc_unregister_sysfs(struct platform_device *pdev,/* * Debug sysfs entries */ -static int dbg_flashctrl_show (struct seq_file *s,void *p) +static int flashcontrol_show (struct seq_file *s,void *p) {struct docg3 *docg3 = (struct docg3 *)s->private;@@ -1623,9 +1623,9 @@ static int dbg_flashctrl_show(struct seq_file *s, void *p)return 0 ; } -DEBUGFS_RO_ATTR (flashcontrol, dbg_flashctrl_show); +DEFINE_SHOW_ATTRIBUTE (flashcontrol); -static int dbg_asicmode_show (struct seq_file *s,void *p) +static int asic_mode_show (struct seq_file *s,void *p) {struct docg3 *docg3 = (struct docg3 *)s->private;@@ -1660,9 +1660,9 @@ static int dbg_asicmode_show(struct seq_file *s, void *p)seq_puts (s,")\n" );return 0 ; } -DEBUGFS_RO_ATTR (asic_mode, dbg_asicmode_show); +DEFINE_SHOW_ATTRIBUTE (asic_mode); -static int dbg_device_id_show (struct seq_file *s,void *p) +static int device_id_show (struct seq_file *s,void *p) {struct docg3 *docg3 = (struct docg3 *)s->private;int id;@@ -1674,9 +1674,9 @@ static int dbg_device_id_show(struct seq_file *s, void *p)seq_printf (s,"DeviceId = %d\n" , id);return 0 ; } -DEBUGFS_RO_ATTR (device_id, dbg_device_id_show); +DEFINE_SHOW_ATTRIBUTE (device_id); -static int dbg_protection_show (struct seq_file *s,void *p) +static int protection_show (struct seq_file *s,void *p) {struct docg3 *docg3 = (struct docg3 *)s->private;int protect, dps0, dps0_low, dps0_high, dps1, dps1_low, dps1_high;@@ -1726,7 +1726,7 @@ static int dbg_protection_show(struct seq_file *s, void *p) !!(dps1 & DOC_DPS_KEY_OK));return 0 ; } -DEBUGFS_RO_ATTR (protection, dbg_protection_show); +DEFINE_SHOW_ATTRIBUTE (protection);static void __init doc_dbg_register (struct mtd_info *floor) {drivers/mtd/devices/docg3.h +0
-11@@ -317,17 +317,6 @@ struct docg3 { #define doc_info(fmt, arg...) dev_info(docg3->dev, (fmt), ## arg) #define doc_dbg(fmt, arg...) dev_dbg(docg3->dev, (fmt), ## arg) #define doc_vdbg(fmt, arg...) dev_vdbg(docg3->dev, (fmt), ## arg) - -#define DEBUGFS_RO_ATTR (name, show_fct) \ - static int name##_open(struct inode *inode, struct file *file) \ - { return single_open(file, show_fct, inode->i_private); } \ - static const struct file_operations name##_fops = { \ - .owner = THIS_MODULE, \ - .open = name##_open, \ - .llseek = seq_lseek, \ - .read = seq_read, \ - .release = single_release \ - };#endif /* drivers/mtd/mtdswap.c +1
-12@@ -1265,18 +1265,7 @@ static int mtdswap_show(struct seq_file *s, void *data)return 0 ; } - -static int mtdswap_open (struct inode *inode,struct file *file) -{ -return single_open (file, mtdswap_show, inode->i_private); -} - -static const struct file_operations mtdswap_fops = { - .open = mtdswap_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; +DEFINE_SHOW_ATTRIBUTE (mtdswap);static int mtdswap_add_debugfs (struct mtdswap_dev *d) {drivers/mtd/nand/raw/nandsim.c +3
-14@@ -443,7 +443,7 @@ static unsigned long total_wear = 0;/* MTD structure for NAND controller */ static struct mtd_info *nsmtd; -static int nandsim_debugfs_show (struct seq_file *m,void *private) +static int nandsim_show (struct seq_file *m,void *private) {unsigned long wmin =-1 , wmax =0 , avg;unsigned long deciles[10 ], decile_max[10 ], tot =0 ;@@ -494,18 +494,7 @@ static int nandsim_debugfs_show(struct seq_file *m, void *private)return 0 ; } - -static int nandsim_debugfs_open (struct inode *inode,struct file *file) -{ -return single_open (file, nandsim_debugfs_show, inode->i_private); -} - -static const struct file_operations dfs_fops = { - .open = nandsim_debugfs_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; +DEFINE_SHOW_ATTRIBUTE (nandsim);/** * nandsim_debugfs_create - initialize debugfs @@ -531,7 +520,7 @@ static int nandsim_debugfs_create(struct nandsim *dev) } dent =debugfs_create_file ("nandsim_wear_report" ,S_IRUSR , - root, dev, &dfs_fops); + root, dev, &nandsim_fops);if (IS_ERR_OR_NULL (dent)) {NS_ERR ("cannot create \"nandsim_wear_report\" debugfs entry\n" );return -1 ;
Quoted 10 lines · Boris Brezillon
Should be [PATCH v4]
Quoted 3 lines · On Sun, 2 Dec 2018 03:33:58 -0500 Yangtao Li <[email protected]> wrote:
DEFINE_SHOW_ATTRIBUTEmacro can help us simplify the code,so change to it.And change theDEBUGFS_RO_ATTRmacro defined in some file to a standard macro.
Quoted 7 lines
You still don't put spaces after commas or periods
Quoted 3 lines
Signed-off-by Yangtao Li <[email protected]>---
and you miss a changelog here.
---
Changes in v2:
-Remove a missing DEBUGFS_RO_ATTR
Changes in v3:
-remove the blank line between the function
definition and DEFINE_SHOW_ATTRIBUTE()
Changes in v4:
-update subject and changelog
---
Yours,
Yangtao
Quoted 7 lines
Anyway, no need to send a new version, I'll fix the commit message when applying the patch.
Thanks,
Boris
Boris Brezillon
AppliedQuoted 5 lines · Yangtao Li
DEFINE_SHOW_ATTRIBUTEmacro can help us simplify the code,so change to it.And change theDEBUGFS_RO_ATTRmacro defined in some file to a standard macro.Signed-off-by Yangtao Li <[email protected]>
Applied to http://git.infradead.org/linux-mtd.git mtd/next, thanks.
Boris