test_printf: Refactor fwnode_pointer() to make it more readable
PATCH 1/1 test_printf: Refactor fwnode_pointer() to make it more readable
Converting fwnode_pointer() to use better swnode API allows to make code more readable.
While at it, rename full_name to full_name_third to show exact relation in the hierarchy.
--- lib/test_printf.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
lib/test_printf.c +12 -14
@@ -704,31 +704,29 @@ flags(void)static void __init fwnode_pointer (void ) { -const struct software_node softnodes[] = { - { .name ="first" , }, - { .name ="second" , .parent = &softnodes[0 ], }, - { .name ="third" , .parent = &softnodes[1 ], }, - {NULL /* Guardian */ } - }; -const char *const full_name ="first/second/third" ; +const struct software_node first = { .name ="first" }; +const struct software_node second = { .name ="second" , .parent = &first }; +const struct software_node third = { .name ="third" , .parent = &second }; +const struct software_node *group[] = { &first, &second, &third,NULL };const char *const full_name_second ="first/second" ; +const char *const full_name_third ="first/second/third" ;const char *const second_name ="second" ;const char *const third_name ="third" ;int rval; - rval =software_node_register_nodes (softnodes); + rval =software_node_register_node_group (group);if (rval) {pr_warn ("cannot register softnodes; rval %d\n" , rval);return ; } -test (full_name_second,"%pfw" ,software_node_fwnode (&softnodes[1 ])); -test (full_name,"%pfw" ,software_node_fwnode (&softnodes[2 ])); -test (full_name,"%pfwf" ,software_node_fwnode (&softnodes[2 ])); -test (second_name,"%pfwP" ,software_node_fwnode (&softnodes[1 ])); -test (third_name,"%pfwP" ,software_node_fwnode (&softnodes[2 ])); +test (full_name_second,"%pfw" ,software_node_fwnode (&second)); +test (full_name_third,"%pfw" ,software_node_fwnode (&third)); +test (full_name_third,"%pfwf" ,software_node_fwnode (&third)); +test (second_name,"%pfwP" ,software_node_fwnode (&second)); +test (third_name,"%pfwP" ,software_node_fwnode (&third)); -software_node_unregister_nodes (softnodes); +software_node_unregister_node_group (group); }static void __init fourcc_pointer (void )
Signature · 1 line
2.35.1
Quoted 5 lines · Andy Shevchenko
Converting
fwnode_pointer()to use better swnode API allows to make code more readable.While at it, rename
full_nametofull_name_thirdto show exact relation in the hierarchy.
Any comments?
Note, I would like to reduce exported swnode APIs and this will help to do so.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 11 lines · Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Converting
fwnode_pointer()to use better swnode API allows to make code more readable.While at it, rename
full_nametofull_name_thirdto show exact relation in the hierarchy.Any comments?
Note, I would like to reduce exported swnode APIs and this will help to do so.
JFYI, I have just pushed the patch into printk/linux.git, branch for-6.2.
I am sorry that it took so long. I have got a long backlog of mails to proceed.
Best Regards,
Petr
Quoted 8 lines · Petr Mladek
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Andy Shevchenko
Converting
fwnode_pointer()to use better swnode API allows to make code more readable.While at it, rename
full_nametofull_name_thirdto show exact relation in the hierarchy.
Quoted 7 lines
Quoted 4 lines
Any comments?
Note, I would like to reduce exported swnode APIs and this will help to do so.
JFYI, I have just pushed the patch into printk/linux.git, branch for-6.2.
Thank you!
Quoted 2 lines
I am sorry that it took so long. I have got a long backlog of mails to proceed.
No problem.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 19 lines · On Wed, 24 Aug 2022 20:05:42 +0300 Andy Shevchenko…
Converting
fwnode_pointer()to use better swnode API allows to make code more readable.While at it, rename
full_nametofull_name_thirdto show exact relation in the hierarchy.Signed-off-by Andy Shevchenko <[email protected]>--- lib/test_printf.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)lib/test_printf.c +0
-0@@ -704,31 +704,29 @@ flags(void)static void __init fwnode_pointer (void ) {
lib/test_printf.c flags(void) · line 709
Quoted 10 lines
lib/test_printf.c +3
-7-const struct software_node softnodes[] = { - { .name ="first" , }, - { .name ="second" , .parent = &softnodes[0 ], }, - { .name ="third" , .parent = &softnodes[1 ], }, - {NULL /* Guardian */ } - }; -const char *const full_name ="first/second/third" ; +const struct software_node first = { .name ="first" }; +const struct software_node second = { .name ="second" , .parent = &first }; +const struct software_node third = { .name ="third" , .parent = &second };
I personally do not find the above more readable, but honestly, I'm not attached to this code at all.
lib/test_printf.c flags(void) · line 710
Quoted 1 line
lib/test_printf.c +1
-0+const struct software_node *group[] = { &first, &second, &third,NULL };
Could this just be:
const struct software_node *group[] = {
&softnodes[0], &softnodes[1], &softnodes[2], NULL };Quoted 13 lines
lib/test_printf.c +2
-1const char *const full_name_second ="first/second" ; +const char *const full_name_third ="first/second/third" ;const char *const second_name ="second" ;const char *const third_name ="third" ;int rval; - rval =software_node_register_nodes (softnodes); + rval =software_node_register_node_group (group);if (rval) {pr_warn ("cannot register softnodes; rval %d\n" , rval);return ; }
lib/test_printf.c flags(void) · line 727
Quoted 10 lines
lib/test_printf.c +5
-5-test (full_name_second,"%pfw" ,software_node_fwnode (&softnodes[1 ])); -test (full_name,"%pfw" ,software_node_fwnode (&softnodes[2 ])); -test (full_name,"%pfwf" ,software_node_fwnode (&softnodes[2 ])); -test (second_name,"%pfwP" ,software_node_fwnode (&softnodes[1 ])); -test (third_name,"%pfwP" ,software_node_fwnode (&softnodes[2 ])); +test (full_name_second,"%pfw" ,software_node_fwnode (&second)); +test (full_name_third,"%pfw" ,software_node_fwnode (&third)); +test (full_name_third,"%pfwf" ,software_node_fwnode (&third)); +test (second_name,"%pfwP" ,software_node_fwnode (&second)); +test (third_name,"%pfwP" ,software_node_fwnode (&third));
Then the above doesn't need to change.
But again, I'm not maintaining this code, so I'm not attached. Just adding my $0.02 to this (as I'm triaging my inbox and found this email).
-- Steve
Quoted 6 lines
lib/test_printf.c +1
-1-software_node_unregister_nodes (softnodes); +software_node_unregister_node_group (group); }static void __init fourcc_pointer (void )
Quoted 2 lines · Steven Rostedt
On Wed, 24 Aug 2022 20:05:42 +0300
Andy Shevchenko <[email protected]> wrote:
Thank you for review, my answers below.
...
Quoted 7 lines
lib/test_printf.c flags(void) · line 709
Quoted 3 lines
lib/test_printf.c +3
-0+const struct software_node first = { .name ="first" }; +const struct software_node second = { .name ="second" , .parent = &first }; +const struct software_node third = { .name ="third" , .parent = &second };I personally do not find the above more readable, but honestly, I'm not attached to this code at all.
Quoted 6 lines
lib/test_printf.c flags(void) · line 710
Quoted 1 line
lib/test_printf.c +1
-0+const struct software_node *group[] = { &first, &second, &third,NULL };Could this just be:
const struct software_node *group[] = { &softnodes[0], &softnodes[1], &softnodes[2], NULL };
It could, but the issue is that it will loose the self-explanatory naming scheme. It's much easier to see what we test and what we expect in the below calls...
Quoted 13 lines
Quoted 13 lines
lib/test_printf.c +2
-1const char *const full_name_second ="first/second" ; +const char *const full_name_third ="first/second/third" ;const char *const second_name ="second" ;const char *const third_name ="third" ;int rval; - rval =software_node_register_nodes (softnodes); + rval =software_node_register_node_group (group);if (rval) {pr_warn ("cannot register softnodes; rval %d\n" , rval);return ; }
Quoted 10 lines
lib/test_printf.c flags(void) · line 727
Quoted 10 lines
lib/test_printf.c +5
-5-test (full_name_second,"%pfw" ,software_node_fwnode (&softnodes[1 ])); -test (full_name,"%pfw" ,software_node_fwnode (&softnodes[2 ])); -test (full_name,"%pfwf" ,software_node_fwnode (&softnodes[2 ])); -test (second_name,"%pfwP" ,software_node_fwnode (&softnodes[1 ])); -test (third_name,"%pfwP" ,software_node_fwnode (&softnodes[2 ])); +test (full_name_second,"%pfw" ,software_node_fwnode (&second)); +test (full_name_third,"%pfw" ,software_node_fwnode (&third)); +test (full_name_third,"%pfwf" ,software_node_fwnode (&third)); +test (second_name,"%pfwP" ,software_node_fwnode (&second)); +test (third_name,"%pfwP" ,software_node_fwnode (&third));
...here.
Quoted 1 line
Then the above doesn't need to change.
And that's why I want to change them.
Quoted 8 lines
But again, I'm not maintaining this code, so I'm not attached. Just adding my $0.02 to this (as I'm triaging my inbox and found this email).
Quoted 5 lines
lib/test_printf.c +1
-1-software_node_unregister_nodes (softnodes); +software_node_unregister_node_group (group); }static void __init fourcc_pointer (void )
Signature · 2 lines
With Best Regards, Andy Shevchenko