lkml.org 
[lkml]   [2005]   [Jul]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] add NULL short circuit to fb_dealloc_cmap()
Date
Resource freeing functions should generally be safe to call with NULL pointers.
Why?
- there is some precedence in the kernel for this for deallocation functions.
- removes the need for callers to check pointers for NULL.
- space is saved overall by less code to test pointers for NULL all over the place.
- removes possible NULL pointer dereferences when a caller forgot to check.

This patch makes fb_dealloc_cmap() safe to call with a NULL pointer argument.


Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
---

drivers/video/fbcmap.c | 3 +++
1 files changed, 3 insertions(+)

--- linux-2.6.13-rc3-orig/drivers/video/fbcmap.c 2005-06-17 21:48:29.000000000 +0200
+++ linux-2.6.13-rc3/drivers/video/fbcmap.c 2005-07-17 20:33:43.000000000 +0200
@@ -130,6 +130,9 @@ fail:

void fb_dealloc_cmap(struct fb_cmap *cmap)
{
+ if (unlikely(!cmap))
+ return;
+
kfree(cmap->red);
kfree(cmap->green);
kfree(cmap->blue);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-07-17 20:29    [W:0.214 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site