powerpc: legacy_serial loop cleanup
PATCH 1/1 powerpc: legacy_serial loop cleanup
We only ever execute the loop once, so let's move it to a function making it more readable. Cleanup patch, no functional change.
--- arch/powerpc/kernel/legacy_serial.c | 39 +++++++++++++++++++----------------- 1 files changed, 21 insertions(+), 18 deletions(-)
arch/powerpc/kernel/legacy_serial.c +21 -18
@@ -236,6 +236,26 @@ static int __init add_legacy_pci_port(st }#endif +static void __init setup_legacy_serial_console (int console) +{ +if (console >=0 ) { +struct legacy_serial_info *info = + &legacy_serial_infos[legacy_serial_console]; +void __iomem *addr; + +if (info->taddr ==0 ) +return ; + addr =ioremap (info->taddr,0x1000 ); +if (addr ==NULL ) +return ; +if (info->speed ==0 ) + info->speed =udbg_probe_uart_speed (addr, info->clock); +DBG ("default console speed = %d\n" , info->speed); +udbg_init_uart (addr, info->speed, info->clock); + } +return ; +} +/* * This is called very early, as part of setup_system() or eventually * setup_arch(), basically before anything else in this file. This function
@@ -319,24 +339,7 @@ void __init find_legacy_serial_ports(voiDBG ("legacy_serial_console = %d\n" , legacy_serial_console); -/* udbg is 64 bits only for now, that will change soon though ... */ -while (legacy_serial_console >=0 ) { -struct legacy_serial_info *info = - &legacy_serial_infos[legacy_serial_console]; -void __iomem *addr; - -if (info->taddr ==0 ) -break ; - addr =ioremap (info->taddr,0x1000 ); -if (addr ==NULL ) -break ; -if (info->speed ==0 ) - info->speed =udbg_probe_uart_speed (addr, info->clock); -DBG ("default console speed = %d\n" , info->speed); -udbg_init_uart (addr, info->speed, info->clock); -break ; - } - +setup_legacy_serial_console (legacy_serial_console);DBG (" <- find_legacy_serial_port()\n" ); }
Quoted 2 lines · Michael Neuling
We only ever execute the loop once, so let's move it to a function making it more readable. Cleanup patch, no functional change.
I don't understand: it's only used once, so make it a function? Why not just change the "while" to an "if"?
Regardless, two style issues:
- remove the plain "return"
- reduce indenting like so:
if (console < 0)
return;
struct legacy_serial_info *info = ...
Quoted 3 lines
Signed-off-by Michael Neuling <[email protected]>--- arch/powerpc/kernel/legacy_serial.c | 39
+++++++++++++++++++-----------------
Quoted 64 lines
1 files changed, 21 insertions(+), 18 deletions(-)Index:
linux-2.6-linus/arch/powerpc/kernel/legacy_serial.c
===================================================================arch/powerpc/kernel/legacy_serial.c +21
-18@@ -236,6 +236,26 @@ static int __init add_legacy_pci_port(st }#endif +static void __init setup_legacy_serial_console (int console) +{ +if (console >=0 ) { +struct legacy_serial_info *info = + &legacy_serial_infos[legacy_serial_console]; +void __iomem *addr; + +if (info->taddr ==0 ) +return ; + addr =ioremap (info->taddr,0x1000 ); +if (addr ==NULL ) +return ; +if (info->speed ==0 ) + info->speed =udbg_probe_uart_speed (addr, info->clock); +DBG ("default console speed = %d\n" , info->speed); +udbg_init_uart (addr, info->speed, info->clock); + } +return ; +} +/* * This is called very early, as part of setup_system() or eventually * setup_arch(), basically before anything else in this file. This function @@ -319,24 +339,7 @@ void __init find_legacy_serial_ports(voiDBG ("legacy_serial_console = %d\n" , legacy_serial_console); -/* udbg is 64 bits only for now, that will change soon though ... */ -while (legacy_serial_console >=0 ) { -struct legacy_serial_info *info = - &legacy_serial_infos[legacy_serial_console]; -void __iomem *addr; - -if (info->taddr ==0 ) -break ; - addr =ioremap (info->taddr,0x1000 ); -if (addr ==NULL ) -break ; -if (info->speed ==0 ) - info->speed =udbg_probe_uart_speed (addr, info->clock); -DBG ("default console speed = %d\n" , info->speed); -udbg_init_uart (addr, info->speed, info->clock); -break ; - } - +setup_legacy_serial_console (legacy_serial_console);DBG (" <- find_legacy_serial_port()\n" ); }_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev
Quoted 2 lines
I don't understand: it's only used once, so make it a function? Why not just change the "while" to an "if"?
Because you can't use a break statements inside an if. We could you gotos, but the idea was to increase read ability :-)
Quoted 6 lines
Regardless, two style issues:
- remove the plain "return"
- reduce indenting like so:
if (console < 0)
return;
structlegacy_serial_info*info = ...
Agreed. Updated patch below.
Mikey
We only ever execute the loop once, so let's move it to a function making it more readable. Cleanup patch, no functional change.
--- arch/powerpc/kernel/legacy_serial.c | 38 ++++++++++++++++++------------------ 1 files changed, 20 insertions(+), 18 deletions(-)
arch/powerpc/kernel/legacy_serial.c +20 -18
@@ -236,6 +236,25 @@ static int __init add_legacy_pci_port(st }#endif +static void __init setup_legacy_serial_console (int console) +{ +struct legacy_serial_info *info = + &legacy_serial_infos[legacy_serial_console]; +void __iomem *addr; + +if (console <0 ) +return ; +if (info->taddr ==0 ) +return ; + addr =ioremap (info->taddr,0x1000 ); +if (addr ==NULL ) +return ; +if (info->speed ==0 ) + info->speed =udbg_probe_uart_speed (addr, info->clock); +DBG ("default console speed = %d\n" , info->speed); +udbg_init_uart (addr, info->speed, info->clock); +} +/* * This is called very early, as part of setup_system() or eventually * setup_arch(), basically before anything else in this file. This function
@@ -319,24 +338,7 @@ void __init find_legacy_serial_ports(voiDBG ("legacy_serial_console = %d\n" , legacy_serial_console); -/* udbg is 64 bits only for now, that will change soon though ... */ -while (legacy_serial_console >=0 ) { -struct legacy_serial_info *info = - &legacy_serial_infos[legacy_serial_console]; -void __iomem *addr; - -if (info->taddr ==0 ) -break ; - addr =ioremap (info->taddr,0x1000 ); -if (addr ==NULL ) -break ; -if (info->speed ==0 ) - info->speed =udbg_probe_uart_speed (addr, info->clock); -DBG ("default console speed = %d\n" , info->speed); -udbg_init_uart (addr, info->speed, info->clock); -break ; - } - +setup_legacy_serial_console (legacy_serial_console);DBG (" <- find_legacy_serial_port()\n" ); }
arch/powerpc/kernel/legacy_serial.c static int __init add_legacy_pci_port(st · line 242
Quoted 8 lines · On Sat, 25 Mar 2006 15:45:11 +1100 Michael Neuling <[email protected]> wrote:
Agreed. Updated patch below.
. .arch/powerpc/kernel/legacy_serial.c +4
-0+static void __init setup_legacy_serial_console (int console) +{ +struct legacy_serial_info *info = + &legacy_serial_infos[legacy_serial_console];
Except that you don't want to do that ^ (assuming you meant "console")
arch/powerpc/kernel/legacy_serial.c static int __init add_legacy_pci_port(st · line 246
Quoted 4 lines
arch/powerpc/kernel/legacy_serial.c +4
-0+void __iomem *addr; + +if (console <0 ) +return ;
before this ^ ... :-)
Signature · 3 lines
Cheers, Stephen Rothwell [email protected] http://www.canb.auug.org.au/~sfr/
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+static void __init setup_legacy_serial_console(int console) +{ + struct legacy_serial_info *info =3D + &legacy_serial_infos[legacy_serial_console];Except that you don't want to do that ^ (assuming you meant "console")
Quoted 6 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ void __iomem *addr; + + if (console < 0) + return;before this ^ ... :-)
Indeed, thanks. Updated patch below. This time for sure! :-)
Mikey
We only ever execute the loop once, so let's move it to a function making it more readable. Cleanup patch, no functional change.
--- arch/powerpc/kernel/legacy_serial.c | 38 ++++++++++++++++++------------------ 1 files changed, 19 insertions(+), 19 deletions(-)
arch/powerpc/kernel/legacy_serial.c +19 -19
@@ -236,6 +236,23 @@ static int __init add_legacy_pci_port(st }#endif +static void __init setup_legacy_serial_console (int console) +{ +struct legacy_serial_info *info = + &legacy_serial_infos[console]; +void __iomem *addr; + +if (info->taddr ==0 ) +return ; + addr =ioremap (info->taddr,0x1000 ); +if (addr ==NULL ) +return ; +if (info->speed ==0 ) + info->speed =udbg_probe_uart_speed (addr, info->clock); +DBG ("default console speed = %d\n" , info->speed); +udbg_init_uart (addr, info->speed, info->clock); +} +/* * This is called very early, as part of setup_system() or eventually * setup_arch(), basically before anything else in this file. This function
@@ -318,25 +335,8 @@ void __init find_legacy_serial_ports(voi#endif DBG ("legacy_serial_console = %d\n" , legacy_serial_console); - -/* udbg is 64 bits only for now, that will change soon though ... */ -while (legacy_serial_console >=0 ) { -struct legacy_serial_info *info = - &legacy_serial_infos[legacy_serial_console]; -void __iomem *addr; - -if (info->taddr ==0 ) -break ; - addr =ioremap (info->taddr,0x1000 ); -if (addr ==NULL ) -break ; -if (info->speed ==0 ) - info->speed =udbg_probe_uart_speed (addr, info->clock); -DBG ("default console speed = %d\n" , info->speed); -udbg_init_uart (addr, info->speed, info->clock); -break ; - } - +if (legacy_serial_console >=0 ) +setup_legacy_serial_console (legacy_serial_console);DBG (" <- find_legacy_serial_port()\n" ); }
Quoted 9 lines
arch/powerpc/kernel/legacy_serial.c +8
-0+static void __init setup_legacy_serial_console (int console) +{ +if (console >=0 ) { +struct legacy_serial_info *info = + &legacy_serial_infos[legacy_serial_console]; +void __iomem *addr; + +if (info->taddr ==0 )
arch/powerpc/kernel/legacy_serial.c static int __init add_legacy_pci_port(st · line 256
Quoted 10 lines
arch/powerpc/kernel/legacy_serial.c +10
-0+return ; + addr =ioremap (info->taddr,0x1000 ); +if (addr ==NULL ) +return ; +if (info->speed ==0 ) + info->speed =udbg_probe_uart_speed (addr, info->clock); +DBG ("default console speed = %d\n" , info->speed); +udbg_init_uart (addr, info->speed, info->clock); + } +return ;
Hrm... What is the point of having a function ending with return; ?
What about, instead, something like:
if (consoles < 0) return; do shit ...
Ben.