Skip to contentSkip to conversation

skeletonfb: check fb_alloc_cmap return value and handle failure properly

PATCH In review Andres Salomon 2 participants 3 messages Feb 7, 2009 – Feb 9, 2009 Framebuffer layer

lore
Share & tools
lore
#0 lore raw

PATCH 5/15 skeletonfb: check fb_alloc_cmap return value and handle failure properly

Bad example code, no cookie!

---
 drivers/video/skeletonfb.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/video/skeletonfb.c +6 -3
index df53365..a439159 100644
@@ -795,8 +795,9 @@ static int __devinit xxxfb_probe(struct pci_dev *dev,
     if (!retval || retval == 4)
 	return -EINVAL;			
 
-    /* This has to been done !!! */	
-    fb_alloc_cmap(&info->cmap, cmap_len, 0);
+    /* This has to be done! */
+    if (fb_alloc_cmap(&info->cmap, cmap_len, 0))
+	return -ENOMEM;
 	
     /* 
      * The following is done in the case of having hardware with a static 
@@ -820,8 +821,10 @@ static int __devinit xxxfb_probe(struct pci_dev *dev,
      */
     /* xxxfb_set_par(info); */
 
-    if (register_framebuffer(info) < 0)
+    if (register_framebuffer(info) < 0) {
+	fb_dealloc_cmap(&info->cmap);
 	return -EINVAL;
+    }
     printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
 	   info->fix.id);
     pci_set_drvdata(dev, info); /* or platform_set_drvdata(pdev, info) */
Signature · 9 lines
1.5.6.5


------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
#1 lore raw
Quoted 3 lines · On Sat, 7 Feb 2009 12:13:02 -0500 Andres Salomon <[email protected]> wrote:

Bad example code, no cookie!

It is even worse than you thought.

Quoted 10 lines
---
 drivers/video/skeletonfb.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/video/skeletonfb.c +0 -0
index df53365..a439159 100644

drivers/video/skeletonfb.c static int __devinit xxxfb_probe(struct pci_dev *dev, · line 801

Quoted 9 lines
drivers/video/skeletonfb.c +3 -2
@@ -795,8 +795,9 @@ static int __devinit xxxfb_probe(struct pci_dev *dev,
     if (!retval || retval == 4)
 	return -EINVAL;			
 
-    /* This has to been done !!! */	
-    fb_alloc_cmap(&info->cmap, cmap_len, 0);
+    /* This has to be done! */
+    if (fb_alloc_cmap(&info->cmap, cmap_len, 0))
+	return -ENOMEM;
 

The info pointer should be freed before the return here ...

drivers/video/skeletonfb.c static int __devinit xxxfb_probe(struct pci_dev *dev, · line 825

Quoted 9 lines
drivers/video/skeletonfb.c +2 -1
     /* 
      * The following is done in the case of having hardware with a static 
@@ -820,8 +821,10 @@ static int __devinit xxxfb_probe(struct pci_dev *dev,
      */
     /* xxxfb_set_par(info); */
 
-    if (register_framebuffer(info) < 0)
+    if (register_framebuffer(info) < 0) {
+	fb_dealloc_cmap(&info->cmap);

... and here.

drivers/video/skeletonfb.c static int __devinit xxxfb_probe(struct pci_dev *dev, · line 830

Quoted 6 lines
drivers/video/skeletonfb.c +1 -0
 	return -EINVAL;
+    }
     printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
 	   info->fix.id);
     pci_set_drvdata(dev, info); /* or platform_set_drvdata(pdev, info) */

Kind regards,
Krzysztof

----------------------------------------------------------------------
Zostan mistrzem parkowania w Bombaju!
Zagraj >> http://link.interia.pl/f204e

#2 lore raw
Quoted 8 lines · On Mon, 9 Feb 2009 07:29:29 +0100 Krzysztof Helt <[email protected]> wrote:
Quoted 3 lines · On Sat, 7 Feb 2009 12:13:02 -0500 Andres Salomon <[email protected]> wrote:

Bad example code, no cookie!

It is even worse than you thought.

Maybe skeletonfb.c should simply be dropped completely? Incorrect documentation is worse than no documentation. If it's unmaintained, buggy, and incorrect in many places...

Quoted 51 lines
Quoted 11 lines
---
 drivers/video/skeletonfb.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/video/skeletonfb.c +0 -0
index df53365..a439159 100644

drivers/video/skeletonfb.c static int __devinit xxxfb_probe(struct pci_dev · line 801

Quoted 9 lines
drivers/video/skeletonfb.c +3 -2
@@ -795,8 +795,9 @@ static int __devinit xxxfb_probe(struct pci_dev
 *dev, if (!retval || retval == 4)
 	return -EINVAL;			
 
-    /* This has to been done !!! */	
-    fb_alloc_cmap(&info->cmap, cmap_len, 0);
+    /* This has to be done! */
+    if (fb_alloc_cmap(&info->cmap, cmap_len, 0))
+	return -ENOMEM;
 

The info pointer should be freed before the return here ...

drivers/video/skeletonfb.c static int __devinit xxxfb_probe(struct pci_dev *dev, · line 825

Quoted 9 lines
drivers/video/skeletonfb.c +0 -0
     /* 
      * The following is done in the case of having hardware with a

static @@ -820,8 +821,10 @@ static int __devinit xxxfb_probe(struct pci_dev *dev, */

     /* xxxfb_set_par(info); */
drivers/video/skeletonfb.c +2 -1
-    if (register_framebuffer(info) < 0)
+    if (register_framebuffer(info) < 0) {
+	fb_dealloc_cmap(&info->cmap);

... and here.

Quoted 6 lines
drivers/video/skeletonfb.c +1 -0
 	return -EINVAL;
+    }
     printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
 	   info->fix.id);
     pci_set_drvdata(dev, info); /* or platform_set_drvdata(pdev,

info) */ --

Kind regards,
Krzysztof

----------------------------------------------------------------------
Zostan mistrzem parkowania w Bombaju!
Zagraj >> http://link.interia.pl/f204e