add NULL short circuit to fb_dealloc_cmap()
PATCH 1/1 add NULL short circuit to fb_dealloc_cmap()
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.
---
drivers/video/fbcmap.c | 3 +++ 1 files changed, 3 insertions(+)
drivers/video/fbcmap.c +3 -0
@@ -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);
Quoted 8 lines · Jesper Juhl
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.
The fb cmap copde would be a lot simpler if it did everything with a single allocation instead of five. Make a super cmap struct:
struct fb_super_cmap {
struct fb_cmap cmap;
__u16 red[255];
__u16 blue[255];
__u16 green[255];
__u16 transp[255];
}
Then adjust the code as need. Have the embedded cmap struct point to the fields in the super_cmap and the drivers don't have to be changed.
Signature · 2 lines
Jon Smirl [email protected]
Quoted 13 lines · Jon Smirl
Quoted 8 lines · Jesper Juhl
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.The fb cmap copde would be a lot simpler if it did everything with a single allocation instead of five. Make a super cmap struct:
Quoted 6 lines
struct fb_super_cmap {
struct fb_cmap cmap;
__u16 red[255];
__u16 blue[255];
__u16 green[255];
__u16 transp[255];^^^
I assume you meant 256?
Quoted 4 lines
}
Then adjust the code as need. Have the embedded cmap struct point to the fields in the
super_cmapand the drivers don't have to be changed.
What if your colormap has more than 256 entries?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
Quoted 8 lines
Quoted 6 lines
struct fb_super_cmap { struct fb_cmap cmap; __u16 red[255]; __u16 blue[255]; __u16 green[255]; __u16 transp[255];^^^I assume you meant 256?
Even if it really was 255, it should probably be made 256 to have things aligned <-- if that matters.
Jan Engelhardt
Quoted 8 lines · Geert Uytterhoeven
Quoted 7 lines
struct fb_super_cmap { struct fb_cmap cmap; __u16 red[255]; __u16 blue[255]; __u16 green[255]; __u16 transp[255];^^^
Quoted 8 lines
I assume you meant 256?
Quoted 4 lines
}
Then adjust the code as need. Have the embedded cmap struct point to the fields in the
super_cmapand the drivers don't have to be changed.What if your colormap has more than 256 entries?
I meant 256. Does any hardware exist that takes more that 256 entries? They are __u16 values but I have never seen hardware that take more that __u8 either.
Signature · 2 lines
Jon Smirl [email protected]
Quoted 11 lines · Jon Smirl
Quoted 10 lines · Geert Uytterhoeven
Quoted 7 lines
struct fb_super_cmap { struct fb_cmap cmap; __u16 red[255]; __u16 blue[255]; __u16 green[255]; __u16 transp[255];^^^I assume you meant 256?
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
}
Then adjust the code as need. Have the embedded cmap struct point to the fields in the
super_cmapand the drivers don't have to be changed.What if your colormap has more than 256 entries?
I meant 256. Does any hardware exist that takes more that 256 entries?
1024 was quite common on high-end graphics hardware.
Quoted 2 lines
They are
__u16values but I have never seen hardware that take more that__u8either.
10 bit was quite common on high-end graphics hardware.
IIRC, DEC TGA can do at least one of them.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click