Commit 7a3e7a62 authored by Andrew Morton's avatar Andrew Morton Committed by Greg Kroah-Hartman

[PATCH] janitor: video/fbcmap: kmalloc() audit

From: "Randy.Dunlap" <rddunlap@osdl.org>

From: Leann Ogasawara <ogasawara@osdl.org>

Handle kmalloc() failures
parent d53303ed
...@@ -98,14 +98,14 @@ int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp) ...@@ -98,14 +98,14 @@ int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp)
if (!len) if (!len)
return 0; return 0;
if (!(cmap->red = kmalloc(size, GFP_ATOMIC))) if (!(cmap->red = kmalloc(size, GFP_ATOMIC)))
return -1; goto fail;
if (!(cmap->green = kmalloc(size, GFP_ATOMIC))) if (!(cmap->green = kmalloc(size, GFP_ATOMIC)))
return -1; goto fail;
if (!(cmap->blue = kmalloc(size, GFP_ATOMIC))) if (!(cmap->blue = kmalloc(size, GFP_ATOMIC)))
return -1; goto fail;
if (transp) { if (transp) {
if (!(cmap->transp = kmalloc(size, GFP_ATOMIC))) if (!(cmap->transp = kmalloc(size, GFP_ATOMIC)))
return -1; goto fail;
} else } else
cmap->transp = NULL; cmap->transp = NULL;
} }
...@@ -113,6 +113,10 @@ int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp) ...@@ -113,6 +113,10 @@ int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp)
cmap->len = len; cmap->len = len;
fb_copy_cmap(fb_default_cmap(len), cmap, 0); fb_copy_cmap(fb_default_cmap(len), cmap, 0);
return 0; return 0;
fail:
fb_dealloc_cmap(cmap);
return -1;
} }
/** /**
...@@ -126,14 +130,10 @@ int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp) ...@@ -126,14 +130,10 @@ int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp)
void fb_dealloc_cmap(struct fb_cmap *cmap) void fb_dealloc_cmap(struct fb_cmap *cmap)
{ {
if (cmap->red) kfree(cmap->red);
kfree(cmap->red); kfree(cmap->green);
if (cmap->green) kfree(cmap->blue);
kfree(cmap->green); kfree(cmap->transp);
if (cmap->blue)
kfree(cmap->blue);
if (cmap->transp)
kfree(cmap->transp);
cmap->red = cmap->green = cmap->blue = cmap->transp = NULL; cmap->red = cmap->green = cmap->blue = cmap->transp = NULL;
cmap->len = 0; cmap->len = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment