- proc cleanup for
Subsystems (2)
RFC PATCH 1/1 - proc cleanup for
Hi list,
Doing some greps, I found a bad proc setup in some drivers. This
is the case of drivers/char/genrtc.c.
Bellow is a trivial patch to fix it. I would like to know if
someone think that this work should _not_ be done.
(Note that my last if is "if(..)" insteed of "if (..)", I'm doing this because the "if" above do that too. I _think_ is bad to have two different ways, but I can change if someone not agree).
drivers/char/genrtc.c +16 -6
@@ -466,6 +466,19 @@ return len; } +static int __init gen_rtc_proc_init (struct miscdevice *dev) +{ +struct proc_dir_entry *r; + + r =create_proc_read_entry ("driver/rtc" ,0 ,0 , gen_rtc_read_proc,NULL ); +if (!r) { +misc_deregister (dev); +return -ENOMEM ; + } +return 0 ; +} +#else +static inline int gen_rtc_proc_init (struct miscdevice *dev) {return 0 ; }#endif /* CONFIG_PROC_FS */
@@ -501,12 +514,9 @@if (retval <0 )return retval; -#ifdef CONFIG_PROC_FS -if ((create_proc_read_entry ("driver/rtc" ,0 ,0 , gen_rtc_read_proc,NULL )) =NULL ){ -misc_deregister (&rtc_gen_dev); -return -ENOMEM ; - } -#endif + retval =gen_rtc_proc_init (&rtc_gen_dev); +if (retval <0 ) +return retval;return 0 ; }
Signature · 8 lines
Luiz Fernando N. Capitulino <[email protected]> <http://www.telecentros.sp.gov.br> _______________________________________________ Kernel-janitors mailing list [email protected] http://lists.osdl.org/mailman/listinfo/kernel-janitors
Luiz Fernando Capitulino <[email protected]> :
[...]
drivers/char/genrtc.c line 519
Quoted 13 lines
drivers/char/genrtc.c +3
-6@@ -501,12 +514,9 @@if (retval <0 )return retval; -#ifdef CONFIG_PROC_FS -if ((create_proc_read_entry ("driver/rtc" ,0 ,0 , gen_rtc_read_proc,NULL )) =NULL ){ -misc_deregister (&rtc_gen_dev); -return -ENOMEM ; - } -#endif + retval =gen_rtc_proc_init (&rtc_gen_dev); +if (retval <0 ) +return retval;
You do not need to test retval: simply return it.
We have an xxx_init() function which deregisters something that has been registered in a completely different place -> not pretty Moreover the procfs related #ifdef pops up a bit everywhere.
Could the compiler be smart enough to do the right thing (TM) if the various proc functions were defined in a central place when CONFIG_PROC_FS is not set ?
This way it would even be possible to notify the caller of such functions when the interface is obsoleted in 2.x.y :o)
--
Ueimor
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors
Bonjour mon ami,
Em Qui, 2004-02-19 às 19:26, Francois Romieu escreveu:
Quoted 6 lines
Luiz Fernando Capitulino <[email protected]> :
[...]Quoted 4 lines
drivers/char/genrtc.c +0
-0@@ -501,12 +514,9 @@if (retval <0 )return retval;
Quoted 11 lines
drivers/char/genrtc.c line 519
Quoted 9 lines
drivers/char/genrtc.c +3
-6-#ifdef CONFIG_PROC_FS -if ((create_proc_read_entry ("driver/rtc" ,0 ,0 , gen_rtc_read_proc,NULL )) =NULL ){ -misc_deregister (&rtc_gen_dev); -return -ENOMEM ; - } -#endif + retval =gen_rtc_proc_init (&rtc_gen_dev); +if (retval <0 ) +return retval;You do not need to test retval: simply return it.
Wow, I didn't noticed this. :-)
I will rediff.
Signature · 9 lines
Luiz Fernando N. Capitulino <[email protected]> <http://www.telecentros.sp.gov.br> _______________________________________________ Kernel-janitors mailing list [email protected] http://lists.osdl.org/mailman/listinfo/kernel-janitors
Em Qui, 2004-02-19 às 19:26, Francois Romieu escreveu:
Quoted 6 lines
Luiz Fernando Capitulino <[email protected]> :
[...]Quoted 4 lines
drivers/char/genrtc.c +0
-0@@ -501,12 +514,9 @@if (retval <0 )return retval;
Quoted 11 lines
drivers/char/genrtc.c line 519
Quoted 9 lines
drivers/char/genrtc.c +3
-6-#ifdef CONFIG_PROC_FS -if ((create_proc_read_entry ("driver/rtc" ,0 ,0 , gen_rtc_read_proc,NULL )) =NULL ){ -misc_deregister (&rtc_gen_dev); -return -ENOMEM ; - } -#endif + retval =gen_rtc_proc_init (&rtc_gen_dev); +if (retval <0 ) +return retval;You do not need to test retval: simply return it.
A question, should I do:
retval = gen_rtc_proc_init();
return retval
Or
return gen_rtc_proc_init();
?
I like the first one.
Signature · 9 lines
Luiz Fernando N. Capitulino <[email protected]> <http://www.telecentros.sp.gov.br> _______________________________________________ Kernel-janitors mailing list [email protected] http://lists.osdl.org/mailman/listinfo/kernel-janitors
Luiz Fernando Capitulino <[email protected]> :
[...]
Quoted 9 lines
A question, should I do:
retval =
gen_rtc_proc_init();return retval
Or
return
gen_rtc_proc_init();
Your choice. I would probably do:
ret = misc_register(frob);
if (ret >= 0)
ret = rtc_gen_proc_init();
return ret;
--
Ueimor
_______________________________________________
Kernel-janitors mailing list
[email protected]
http://lists.osdl.org/mailman/listinfo/kernel-janitors