aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHelge Deller <deller@gmx.de>2006-12-08 05:40:27 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-08 11:29:05 -0500
commitadf6b206546414fd006098d027e81f2b576ea2aa (patch)
treec1147f1f850e6e0578e62093a1c50f50cd81c307
parent357b819dda03e642f9c2d737596ad6cdc0022c00 (diff)
[PATCH] fbcmap.c: mark structs const or __read_mostly
- Mark the default colormaps read-only, as nobody should be allowed to modify them - Additionally mark color values as __read_mostly since they will only be modified (very seldom) by fb_invert_cmaps() - Add named C99-initializers in fb_cmap structs and use the ARRAY_SIZE() macro Signed-off-by: Helge Deller <deller@gmx.de> Acked-by: James Simmons <jsimmons@infradead.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/video/fbcmap.c55
-rw-r--r--include/linux/fb.h6
2 files changed, 31 insertions, 30 deletions
diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
index e8b135f3d80d..148108afdd51 100644
--- a/drivers/video/fbcmap.c
+++ b/drivers/video/fbcmap.c
@@ -18,63 +18,64 @@
18 18
19#include <asm/uaccess.h> 19#include <asm/uaccess.h>
20 20
21static u16 red2[] = { 21static u16 red2[] __read_mostly = {
22 0x0000, 0xaaaa 22 0x0000, 0xaaaa
23}; 23};
24static u16 green2[] = { 24static u16 green2[] __read_mostly = {
25 0x0000, 0xaaaa 25 0x0000, 0xaaaa
26}; 26};
27static u16 blue2[] = { 27static u16 blue2[] __read_mostly = {
28 0x0000, 0xaaaa 28 0x0000, 0xaaaa
29}; 29};
30 30
31static u16 red4[] = { 31static u16 red4[] __read_mostly = {
32 0x0000, 0xaaaa, 0x5555, 0xffff 32 0x0000, 0xaaaa, 0x5555, 0xffff
33}; 33};
34static u16 green4[] = { 34static u16 green4[] __read_mostly = {
35 0x0000, 0xaaaa, 0x5555, 0xffff 35 0x0000, 0xaaaa, 0x5555, 0xffff
36}; 36};
37static u16 blue4[] = { 37static u16 blue4[] __read_mostly = {
38 0x0000, 0xaaaa, 0x5555, 0xffff 38 0x0000, 0xaaaa, 0x5555, 0xffff
39}; 39};
40 40
41static u16 red8[] = { 41static u16 red8[] __read_mostly = {
42 0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa 42 0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa
43}; 43};
44static u16 green8[] = { 44static u16 green8[] __read_mostly = {
45 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa 45 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa
46}; 46};
47static u16 blue8[] = { 47static u16 blue8[] __read_mostly = {
48 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa 48 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa
49}; 49};
50 50
51static u16 red16[] = { 51static u16 red16[] __read_mostly = {
52 0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa, 52 0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa,
53 0x5555, 0x5555, 0x5555, 0x5555, 0xffff, 0xffff, 0xffff, 0xffff 53 0x5555, 0x5555, 0x5555, 0x5555, 0xffff, 0xffff, 0xffff, 0xffff
54}; 54};
55static u16 green16[] = { 55static u16 green16[] __read_mostly = {
56 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa, 56 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa,
57 0x5555, 0x5555, 0xffff, 0xffff, 0x5555, 0x5555, 0xffff, 0xffff 57 0x5555, 0x5555, 0xffff, 0xffff, 0x5555, 0x5555, 0xffff, 0xffff
58}; 58};
59static u16 blue16[] = { 59static u16 blue16[] __read_mostly = {
60 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 60 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa,
61 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff 61 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff
62}; 62};
63 63
64static struct fb_cmap default_2_colors = { 64static const struct fb_cmap default_2_colors = {
65 0, 2, red2, green2, blue2, NULL 65 .len=2, .red=red2, .green=green2, .blue=blue2
66}; 66};
67static struct fb_cmap default_8_colors = { 67static const struct fb_cmap default_8_colors = {
68 0, 8, red8, green8, blue8, NULL 68 .len=8, .red=red8, .green=green8, .blue=blue8
69}; 69};
70static struct fb_cmap default_4_colors = { 70static const struct fb_cmap default_4_colors = {
71 0, 4, red4, green4, blue4, NULL 71 .len=4, .red=red4, .green=green4, .blue=blue4
72}; 72};
73static struct fb_cmap default_16_colors = { 73static const struct fb_cmap default_16_colors = {
74 0, 16, red16, green16, blue16, NULL 74 .len=16, .red=red16, .green=green16, .blue=blue16
75}; 75};
76 76
77 77
78
78/** 79/**
79 * fb_alloc_cmap - allocate a colormap 80 * fb_alloc_cmap - allocate a colormap
80 * @cmap: frame buffer colormap structure 81 * @cmap: frame buffer colormap structure
@@ -146,7 +147,7 @@ void fb_dealloc_cmap(struct fb_cmap *cmap)
146 * Copy contents of colormap from @from to @to. 147 * Copy contents of colormap from @from to @to.
147 */ 148 */
148 149
149int fb_copy_cmap(struct fb_cmap *from, struct fb_cmap *to) 150int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to)
150{ 151{
151 int tooff = 0, fromoff = 0; 152 int tooff = 0, fromoff = 0;
152 int size; 153 int size;
@@ -170,7 +171,7 @@ int fb_copy_cmap(struct fb_cmap *from, struct fb_cmap *to)
170 return 0; 171 return 0;
171} 172}
172 173
173int fb_cmap_to_user(struct fb_cmap *from, struct fb_cmap_user *to) 174int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to)
174{ 175{
175 int tooff = 0, fromoff = 0; 176 int tooff = 0, fromoff = 0;
176 int size; 177 int size;
@@ -282,7 +283,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
282 * 283 *
283 */ 284 */
284 285
285struct fb_cmap *fb_default_cmap(int len) 286const struct fb_cmap *fb_default_cmap(int len)
286{ 287{
287 if (len <= 2) 288 if (len <= 2)
288 return &default_2_colors; 289 return &default_2_colors;
@@ -305,22 +306,22 @@ void fb_invert_cmaps(void)
305{ 306{
306 u_int i; 307 u_int i;
307 308
308 for (i = 0; i < 2; i++) { 309 for (i = 0; i < ARRAY_SIZE(red2); i++) {
309 red2[i] = ~red2[i]; 310 red2[i] = ~red2[i];
310 green2[i] = ~green2[i]; 311 green2[i] = ~green2[i];
311 blue2[i] = ~blue2[i]; 312 blue2[i] = ~blue2[i];
312 } 313 }
313 for (i = 0; i < 4; i++) { 314 for (i = 0; i < ARRAY_SIZE(red4); i++) {
314 red4[i] = ~red4[i]; 315 red4[i] = ~red4[i];
315 green4[i] = ~green4[i]; 316 green4[i] = ~green4[i];
316 blue4[i] = ~blue4[i]; 317 blue4[i] = ~blue4[i];
317 } 318 }
318 for (i = 0; i < 8; i++) { 319 for (i = 0; i < ARRAY_SIZE(red8); i++) {
319 red8[i] = ~red8[i]; 320 red8[i] = ~red8[i];
320 green8[i] = ~green8[i]; 321 green8[i] = ~green8[i];
321 blue8[i] = ~blue8[i]; 322 blue8[i] = ~blue8[i];
322 } 323 }
323 for (i = 0; i < 16; i++) { 324 for (i = 0; i < ARRAY_SIZE(red16); i++) {
324 red16[i] = ~red16[i]; 325 red16[i] = ~red16[i];
325 green16[i] = ~green16[i]; 326 green16[i] = ~green16[i];
326 blue16[i] = ~blue16[i]; 327 blue16[i] = ~blue16[i];
diff --git a/include/linux/fb.h b/include/linux/fb.h
index fa23e0671bb3..6fe56aaa6685 100644
--- a/include/linux/fb.h
+++ b/include/linux/fb.h
@@ -970,11 +970,11 @@ extern struct fb_videomode *fb_find_best_display(struct fb_monspecs *specs,
970/* drivers/video/fbcmap.c */ 970/* drivers/video/fbcmap.c */
971extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp); 971extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp);
972extern void fb_dealloc_cmap(struct fb_cmap *cmap); 972extern void fb_dealloc_cmap(struct fb_cmap *cmap);
973extern int fb_copy_cmap(struct fb_cmap *from, struct fb_cmap *to); 973extern int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to);
974extern int fb_cmap_to_user(struct fb_cmap *from, struct fb_cmap_user *to); 974extern int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to);
975extern int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *fb_info); 975extern int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *fb_info);
976extern int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *fb_info); 976extern int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *fb_info);
977extern struct fb_cmap *fb_default_cmap(int len); 977extern const struct fb_cmap *fb_default_cmap(int len);
978extern void fb_invert_cmaps(void); 978extern void fb_invert_cmaps(void);
979 979
980struct fb_videomode { 980struct fb_videomode {