Skip to contentSkip to conversation

mm: Re-use DEFINE_SHOW_ATTRIBUTE() macro

PATCH In review Andy Shevchenko 5 participants 6 messages Feb 14, 2018 – Feb 17, 2018

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: Re-use DEFINE_SHOW_ATTRIBUTE() macro

...instead of open coding file operations followed by custom ->open() callbacks per each attribute.

---
 mm/backing-dev.c  | 12 +-----------
 mm/memblock.c     | 12 +-----------
 mm/percpu-stats.c | 12 +-----------
 mm/zsmalloc.c     | 12 +-----------
 4 files changed, 4 insertions(+), 44 deletions(-)
mm/backing-dev.c +1 -11
index ffa0c6b9e78a..71292de5f026 100644
@@ -101,17 +101,7 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
 	return 0;
 }
 
-static int bdi_debug_stats_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, bdi_debug_stats_show, inode->i_private);
-}
-
-static const struct file_operations bdi_debug_stats_fops = {
-	.open		= bdi_debug_stats_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(bdi_debug_stats);
 
 static int bdi_debug_register(struct backing_dev_info *bdi, const char *name)
 {
mm/memblock.c +1 -11
index 5a9ca2a1751b..c2e5925ebdc4 100644
@@ -1847,17 +1847,7 @@ static int memblock_debug_show(struct seq_file *m, void *private)
 	return 0;
 }
 
-static int memblock_debug_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, memblock_debug_show, inode->i_private);
-}
-
-static const struct file_operations memblock_debug_fops = {
-	.open = memblock_debug_open,
-	.read = seq_read,
-	.llseek = seq_lseek,
-	.release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(memblock_debug);
 
 static int __init memblock_init_debugfs(void)
 {
mm/percpu-stats.c +1 -11
index 7a58460bfd27..0305cc4cbc3e 100644
@@ -224,17 +224,7 @@ static int percpu_stats_show(struct seq_file *m, void *v)
 	return 0;
 }
 
-static int percpu_stats_open(struct inode *inode, struct file *filp)
-{
-	return single_open(filp, percpu_stats_show, NULL);
-}
-
-static const struct file_operations percpu_stats_fops = {
-	.open		= percpu_stats_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(percpu_stats);
 
 static int __init init_percpu_stats_debugfs(void)
 {
mm/zsmalloc.c +1 -11
index c3013505c305..1b5cea3fe9fe 100644
@@ -642,17 +642,7 @@ static int zs_stats_size_show(struct seq_file *s, void *v)
 	return 0;
 }
 
-static int zs_stats_size_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, zs_stats_size_show, inode->i_private);
-}
-
-static const struct file_operations zs_stat_size_ops = {
-	.open           = zs_stats_size_open,
-	.read           = seq_read,
-	.llseek         = seq_lseek,
-	.release        = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(zs_stats_size);
 
 static void zs_pool_stat_create(struct zs_pool *pool, const char *name)
 {
Signature · 7 lines
2.15.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Andy Shevchenko

...instead of open coding file operations followed by custom ->open() callbacks per each attribute.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 8 lines · Matthew Wilcox
Quoted 4 lines · Andy Shevchenko

...instead of open coding file operations followed by custom ->open() callbacks per each attribute.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Reviewed-by on v1 1/1
#3 lore raw
In reply to Andy Shevchenko
Quoted 5 lines · Andy Shevchenko

...instead of open coding file operations followed by custom ->open() callbacks per each attribute.

FWIW,

	-ss

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw
In reply to Andy Shevchenko
I love your patch! Yet something to improve:

Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on mmotm/master]
[also build test ERROR on v4.16-rc1 next-20180216]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/mm-Re-use-DEFINE_SHOW_ATTRIBUTE-macro/20180217-204603
base:   git://git.cmpxchg.org/linux-mmotm.git master
config: i386-randconfig-a1-201806 (attached as .config)
compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

mm/backing-dev.c:104:1: warning: data definition has no type or storage class

    DEFINE_SHOW_ATTRIBUTE(bdi_debug_stats);
    ^
   mm/backing-dev.c:104:1: error: type defaults to 'int' in declaration of 'DEFINE_SHOW_ATTRIBUTE' [-Werror=implicit-int]
   mm/backing-dev.c:104:1: warning: parameter names (without types) in function declaration
   mm/backing-dev.c: In function 'bdi_debug_register':
>> mm/backing-dev.c:116:19: error: 'bdi_debug_stats_fops' undeclared (first use in this function)
                bdi, &bdi_debug_stats_fops);
                      ^

mm/backing-dev.c:116:19: note: each undeclared identifier is reported only once for each function it appears in mm/backing-dev.c: At top level:
mm/backing-dev.c:44:12: warning: 'bdi_debug_stats_show' defined but not used [-Wunused-function]
static int bdi_debug_stats_show(struct seq_file *m, void *v)
^
cc1: some warnings being treated as errors
--
mm/zsmalloc.c:645:1: warning: data definition has no type or storage class

    DEFINE_SHOW_ATTRIBUTE(zs_stats_size);
    ^
   mm/zsmalloc.c:645:1: error: type defaults to 'int' in declaration of 'DEFINE_SHOW_ATTRIBUTE' [-Werror=implicit-int]
   mm/zsmalloc.c:645:1: warning: parameter names (without types) in function declaration
   mm/zsmalloc.c: In function 'zs_pool_stat_create':
>> mm/zsmalloc.c:664:30: error: 'zs_stat_size_ops' undeclared (first use in this function)
       pool->stat_dentry, pool, &zs_stat_size_ops);
                                 ^

mm/zsmalloc.c:664:30: note: each undeclared identifier is reported only once for each function it appears in mm/zsmalloc.c: At top level:
mm/zsmalloc.c:587:12: warning: 'zs_stats_size_show' defined but not used [-Wunused-function]
static int zs_stats_size_show(struct seq_file *s, void *v)
^
cc1: some warnings being treated as errors

vim +/bdi_debug_stats_fops +116 mm/backing-dev.c

76f1418b Miklos Szeredi 2008-04-30 103
bdcdd49e Andy Shevchenko 2018-02-14 @104 DEFINE_SHOW_ATTRIBUTE(bdi_debug_stats);

76f1418b Miklos Szeredi  2008-04-30  105  
97f07697 weiping zhang   2017-10-31  106  static int bdi_debug_register(struct backing_dev_info *bdi, const char *name)
76f1418b Miklos Szeredi  2008-04-30  107  {
97f07697 weiping zhang   2017-10-31  108  	if (!bdi_debug_root)
97f07697 weiping zhang   2017-10-31  109  		return -ENOMEM;
97f07697 weiping zhang   2017-10-31  110  
76f1418b Miklos Szeredi  2008-04-30  111  	bdi->debug_dir = debugfs_create_dir(name, bdi_debug_root);
97f07697 weiping zhang   2017-10-31  112  	if (!bdi->debug_dir)
97f07697 weiping zhang   2017-10-31  113  		return -ENOMEM;
97f07697 weiping zhang   2017-10-31  114  
76f1418b Miklos Szeredi  2008-04-30  115  	bdi->debug_stats = debugfs_create_file("stats", 0444, bdi->debug_dir,
76f1418b Miklos Szeredi  2008-04-30 @116  					       bdi, &bdi_debug_stats_fops);
97f07697 weiping zhang   2017-10-31  117  	if (!bdi->debug_stats) {
97f07697 weiping zhang   2017-10-31  118  		debugfs_remove(bdi->debug_dir);
97f07697 weiping zhang   2017-10-31  119  		return -ENOMEM;
97f07697 weiping zhang   2017-10-31  120  	}
97f07697 weiping zhang   2017-10-31  121  
97f07697 weiping zhang   2017-10-31  122  	return 0;
76f1418b Miklos Szeredi  2008-04-30  123  }
76f1418b Miklos Szeredi  2008-04-30  124  

:::::: The code at line 116 was first introduced by commit
:::::: 76f1418b485da2707531178e517bbb5cf06b3c76 mm: bdi: move statistics to debugfs

:::::: TO: Miklos Szeredi <[email protected]> :::::: CC: Linus Torvalds <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#5 lore raw
Quoted 29 lines · kbuild test robot

Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on mmotm/master]
[also build test ERROR on v4.16-rc1 next-20180216]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Andy-Shevchenko/mm-Re
-use-DEFINE_SHOW_ATTRIBUTE-macro/20180217-204603
base: git://git.cmpxchg.org/linux-mmotm.git master
config: i386-randconfig-a1-201806 (attached as .config)
compiler: gcc-4.9 (Debian 4.9.4-2) 4.9.4 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

mm/backing-dev.c:104:1: warning: data definition has no type or
storage class

    DEFINE_SHOW_ATTRIBUTE(bdi_debug_stats);
    ^

mm/backing-dev.c:104:1: error: type defaults to 'int' in
declaration of 'DEFINE_SHOW_ATTRIBUTE' [-Werror=implicit-int]
mm/backing-dev.c:104:1: warning: parameter names (without types) in
function declaration
mm/backing-dev.c: In function 'bdi_debug_register':

Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

mm/backing-dev.c:116:19: error: 'bdi_debug_stats_fops' undeclared (first use in this function)

                bdi, &bdi_debug_stats_fops);
                      ^

mm/backing-dev.c:116:19: note: each undeclared identifier is
reported only once for each function it appears in

But how?! DEFINE_SHOW_ATTRIBUTE() defines ->open() callback along with struct file_operations.

I have no compilation error with gcc (Debian 7.3.0-3).

Quoted 9 lines

mm/zsmalloc.c:645:1: warning: data definition has no type or
storage class

    DEFINE_SHOW_ATTRIBUTE(zs_stats_size);
    ^

mm/zsmalloc.c:645:1: error: type defaults to 'int' in declaration
of 'DEFINE_SHOW_ATTRIBUTE' [-Werror=implicit-int]
mm/zsmalloc.c:645:1: warning: parameter names (without types) in
function declaration
mm/zsmalloc.c: In function 'zs_pool_stat_create':

Quoted 5 lines
Quoted 2 lines
Quoted 2 lines

mm/zsmalloc.c:664:30: error: 'zs_stat_size_ops' undeclared (first use in this function)

       pool->stat_dentry, pool, &zs_st

at_size_ops); ^

This one valid. Thanks, missed compilation!

Signature · 8 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>