PPC: CHRP - fix possible NULL pointer dereference
PATCH 1/1 PPC: CHRP - fix possible NULL pointer dereference
From: Cyrill Gorcunov <[email protected]>
This patch does fix possible NULL pointer dereference inside of strncmp() if of_get_property() failed.
---
arch/powerpc/platforms/chrp/setup.c | 23 +++++++++++++---------- 1 files changed, 13 insertions(+), 10 deletions(-)
arch/powerpc/platforms/chrp/setup.c +13 -10
@@ -115,7 +115,7 @@ void chrp_show_cpuinfo(struct seq_file *m)seq_printf (m,"machine\t\t: CHRP %s\n" , model);/* longtrail (goldengate) stuff */ -if (!strncmp (model,"IBM,LongTrail" ,13 )) { +if (model && !strncmp (model,"IBM,LongTrail" ,13 )) {/* VLSI VAS96011/12 `Golden Gate 2' */ /* Memory banks */ sdramen = (in_le32(gg2_pci_config_base + GG2_PCI_DRAM_CTRL)
@@ -203,16 +203,19 @@ static void __init sio_fixup_irq(const char *name, u8 device, u8 level,static void __init sio_init (void ) {struct device_node *root; +const char *model =NULL ; -if ((root =of_find_node_by_path ("/" )) && - !strncmp (of_get_property (root,"model" ,NULL ), -"IBM,LongTrail" ,13 )) { -/* logical device 0 (KBC/Keyboard) */ -sio_fixup_irq ("keyboard" ,0 ,1 ,2 ); -/* select logical device 1 (KBC/Mouse) */ -sio_fixup_irq ("mouse" ,1 ,12 ,2 ); - } -of_node_put (root); + root =of_find_node_by_path ("/" ); +if (root) { + model =of_get_property (root,"model" ,NULL ); +if (model && !strncmp (model,"IBM,LongTrail" ,13 )) { +/* logical device 0 (KBC/Keyboard) */ +sio_fixup_irq ("keyboard" ,0 ,1 ,2 ); +/* select logical device 1 (KBC/Mouse) */ +sio_fixup_irq ("mouse" ,1 ,12 ,2 ); + } +of_node_put (root); + } }
Quoted 3 lines · On Thu, 22 Nov 2007 22:54:23 +0300 Cyrill Gorcunov <[email protected]> wrote:
This patch does fix possible NULL pointer dereference inside of
strncmp()ifof_get_property()failed.
Thanks for this.
arch/powerpc/platforms/chrp/setup.c static void __init sio_fixup_irq(const char *name, u8 device, u8 level, · line 206
Quoted 4 lines
static void
__initsio_init(void)
{arch/powerpc/platforms/chrp/setup.c +1
-0struct device_node *root; +const char *model =NULL ;
You don't need this initialization as you always assign the variable before you use it.
arch/powerpc/platforms/chrp/setup.c static void __init sio_fixup_irq(const char *name, u8 device, u8 level, · line 209
Quoted 2 lines
arch/powerpc/platforms/chrp/setup.c +2
-0+ root =of_find_node_by_path ("/" ); +if (root) {
if (!root) return;
would save a level of indentation. Not important.
Signature · 3 lines
Cheers, Stephen Rothwell [email protected] http://www.canb.auug.org.au/~sfr/
Quoted 22 lines · Stephen Rothwell
Quoted 3 lines · On Thu, 22 Nov 2007 22:54:23 +0300 Cyrill Gorcunov <[email protected]> wrote:
This patch does fix possible NULL pointer dereference inside of
strncmp()ifof_get_property()failed.Thanks for this.
Quoted 4 lines
static void
__initsio_init(void)
{
structdevice_node*root;
+ const char *model = NULL;You don't need this initialization as you always assign the variable before you use it.
Quoted 2 lines
+ root =
of_find_node_by_path("/");
+ if (root) {if (!root)
return;
Quoted 7 lines
would save a level of indentation. Not important.
--
Cheers,
Stephen Rothwell [email protected]
http://www.canb.auug.org.au/~sfr/
Oh my :) Thanks. I'll fix it and resend.
Here is updated version
---
From: Cyrill Gorcunov <[email protected]>
This patch does fix possible NULL pointer dereference inside of strncmp() if of_get_property() failed.
---
arch/powerpc/platforms/chrp/setup.c | 13 +++++++++---- 1 files changed, 9 insertions(+), 4 deletions(-)
arch/powerpc/platforms/chrp/setup.c +9 -4
@@ -115,7 +115,7 @@ void chrp_show_cpuinfo(struct seq_file *m)seq_printf (m,"machine\t\t: CHRP %s\n" , model);/* longtrail (goldengate) stuff */ -if (!strncmp (model,"IBM,LongTrail" ,13 )) { +if (model && !strncmp (model,"IBM,LongTrail" ,13 )) {/* VLSI VAS96011/12 `Golden Gate 2' */ /* Memory banks */ sdramen = (in_le32(gg2_pci_config_base + GG2_PCI_DRAM_CTRL)
@@ -203,15 +203,20 @@ static void __init sio_fixup_irq(const char *name, u8 device, u8 level,static void __init sio_init (void ) {struct device_node *root; +const char *model; -if ((root =of_find_node_by_path ("/" )) && - !strncmp (of_get_property (root,"model" ,NULL ), -"IBM,LongTrail" ,13 )) { + root =of_find_node_by_path ("/" ); +if (!root) +return ; + + model =of_get_property (root,"model" ,NULL ); +if (model && !strncmp (model,"IBM,LongTrail" ,13 )) {/* logical device 0 (KBC/Keyboard) */ sio_fixup_irq ("keyboard" ,0 ,1 ,2 );/* select logical device 1 (KBC/Mouse) */ sio_fixup_irq ("mouse" ,1 ,12 ,2 ); } +of_node_put (root); }