Commit adf6b206546414fd006098d027e81f2b576ea2aa
Committed by
Linus Torvalds
1 parent
357b819dda
Exists in
master
and in
7 other branches
[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>
Showing 2 changed files with 31 additions and 30 deletions Side-by-side Diff
drivers/video/fbcmap.c
... | ... | @@ -18,63 +18,64 @@ |
18 | 18 | |
19 | 19 | #include <asm/uaccess.h> |
20 | 20 | |
21 | -static u16 red2[] = { | |
21 | +static u16 red2[] __read_mostly = { | |
22 | 22 | 0x0000, 0xaaaa |
23 | 23 | }; |
24 | -static u16 green2[] = { | |
24 | +static u16 green2[] __read_mostly = { | |
25 | 25 | 0x0000, 0xaaaa |
26 | 26 | }; |
27 | -static u16 blue2[] = { | |
27 | +static u16 blue2[] __read_mostly = { | |
28 | 28 | 0x0000, 0xaaaa |
29 | 29 | }; |
30 | 30 | |
31 | -static u16 red4[] = { | |
31 | +static u16 red4[] __read_mostly = { | |
32 | 32 | 0x0000, 0xaaaa, 0x5555, 0xffff |
33 | 33 | }; |
34 | -static u16 green4[] = { | |
34 | +static u16 green4[] __read_mostly = { | |
35 | 35 | 0x0000, 0xaaaa, 0x5555, 0xffff |
36 | 36 | }; |
37 | -static u16 blue4[] = { | |
37 | +static u16 blue4[] __read_mostly = { | |
38 | 38 | 0x0000, 0xaaaa, 0x5555, 0xffff |
39 | 39 | }; |
40 | 40 | |
41 | -static u16 red8[] = { | |
41 | +static u16 red8[] __read_mostly = { | |
42 | 42 | 0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa |
43 | 43 | }; |
44 | -static u16 green8[] = { | |
44 | +static u16 green8[] __read_mostly = { | |
45 | 45 | 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa |
46 | 46 | }; |
47 | -static u16 blue8[] = { | |
47 | +static u16 blue8[] __read_mostly = { | |
48 | 48 | 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa |
49 | 49 | }; |
50 | 50 | |
51 | -static u16 red16[] = { | |
51 | +static u16 red16[] __read_mostly = { | |
52 | 52 | 0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa, |
53 | 53 | 0x5555, 0x5555, 0x5555, 0x5555, 0xffff, 0xffff, 0xffff, 0xffff |
54 | 54 | }; |
55 | -static u16 green16[] = { | |
55 | +static u16 green16[] __read_mostly = { | |
56 | 56 | 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa, |
57 | 57 | 0x5555, 0x5555, 0xffff, 0xffff, 0x5555, 0x5555, 0xffff, 0xffff |
58 | 58 | }; |
59 | -static u16 blue16[] = { | |
59 | +static u16 blue16[] __read_mostly = { | |
60 | 60 | 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, |
61 | 61 | 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff |
62 | 62 | }; |
63 | 63 | |
64 | -static struct fb_cmap default_2_colors = { | |
65 | - 0, 2, red2, green2, blue2, NULL | |
64 | +static const struct fb_cmap default_2_colors = { | |
65 | + .len=2, .red=red2, .green=green2, .blue=blue2 | |
66 | 66 | }; |
67 | -static struct fb_cmap default_8_colors = { | |
68 | - 0, 8, red8, green8, blue8, NULL | |
67 | +static const struct fb_cmap default_8_colors = { | |
68 | + .len=8, .red=red8, .green=green8, .blue=blue8 | |
69 | 69 | }; |
70 | -static struct fb_cmap default_4_colors = { | |
71 | - 0, 4, red4, green4, blue4, NULL | |
70 | +static const struct fb_cmap default_4_colors = { | |
71 | + .len=4, .red=red4, .green=green4, .blue=blue4 | |
72 | 72 | }; |
73 | -static struct fb_cmap default_16_colors = { | |
74 | - 0, 16, red16, green16, blue16, NULL | |
73 | +static const struct fb_cmap default_16_colors = { | |
74 | + .len=16, .red=red16, .green=green16, .blue=blue16 | |
75 | 75 | }; |
76 | 76 | |
77 | 77 | |
78 | + | |
78 | 79 | /** |
79 | 80 | * fb_alloc_cmap - allocate a colormap |
80 | 81 | * @cmap: frame buffer colormap structure |
... | ... | @@ -146,7 +147,7 @@ |
146 | 147 | * Copy contents of colormap from @from to @to. |
147 | 148 | */ |
148 | 149 | |
149 | -int fb_copy_cmap(struct fb_cmap *from, struct fb_cmap *to) | |
150 | +int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to) | |
150 | 151 | { |
151 | 152 | int tooff = 0, fromoff = 0; |
152 | 153 | int size; |
... | ... | @@ -170,7 +171,7 @@ |
170 | 171 | return 0; |
171 | 172 | } |
172 | 173 | |
173 | -int fb_cmap_to_user(struct fb_cmap *from, struct fb_cmap_user *to) | |
174 | +int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to) | |
174 | 175 | { |
175 | 176 | int tooff = 0, fromoff = 0; |
176 | 177 | int size; |
... | ... | @@ -282,7 +283,7 @@ |
282 | 283 | * |
283 | 284 | */ |
284 | 285 | |
285 | -struct fb_cmap *fb_default_cmap(int len) | |
286 | +const struct fb_cmap *fb_default_cmap(int len) | |
286 | 287 | { |
287 | 288 | if (len <= 2) |
288 | 289 | return &default_2_colors; |
289 | 290 | |
290 | 291 | |
291 | 292 | |
... | ... | @@ -305,22 +306,22 @@ |
305 | 306 | { |
306 | 307 | u_int i; |
307 | 308 | |
308 | - for (i = 0; i < 2; i++) { | |
309 | + for (i = 0; i < ARRAY_SIZE(red2); i++) { | |
309 | 310 | red2[i] = ~red2[i]; |
310 | 311 | green2[i] = ~green2[i]; |
311 | 312 | blue2[i] = ~blue2[i]; |
312 | 313 | } |
313 | - for (i = 0; i < 4; i++) { | |
314 | + for (i = 0; i < ARRAY_SIZE(red4); i++) { | |
314 | 315 | red4[i] = ~red4[i]; |
315 | 316 | green4[i] = ~green4[i]; |
316 | 317 | blue4[i] = ~blue4[i]; |
317 | 318 | } |
318 | - for (i = 0; i < 8; i++) { | |
319 | + for (i = 0; i < ARRAY_SIZE(red8); i++) { | |
319 | 320 | red8[i] = ~red8[i]; |
320 | 321 | green8[i] = ~green8[i]; |
321 | 322 | blue8[i] = ~blue8[i]; |
322 | 323 | } |
323 | - for (i = 0; i < 16; i++) { | |
324 | + for (i = 0; i < ARRAY_SIZE(red16); i++) { | |
324 | 325 | red16[i] = ~red16[i]; |
325 | 326 | green16[i] = ~green16[i]; |
326 | 327 | blue16[i] = ~blue16[i]; |
include/linux/fb.h
... | ... | @@ -970,11 +970,11 @@ |
970 | 970 | /* drivers/video/fbcmap.c */ |
971 | 971 | extern int fb_alloc_cmap(struct fb_cmap *cmap, int len, int transp); |
972 | 972 | extern void fb_dealloc_cmap(struct fb_cmap *cmap); |
973 | -extern int fb_copy_cmap(struct fb_cmap *from, struct fb_cmap *to); | |
974 | -extern int fb_cmap_to_user(struct fb_cmap *from, struct fb_cmap_user *to); | |
973 | +extern int fb_copy_cmap(const struct fb_cmap *from, struct fb_cmap *to); | |
974 | +extern int fb_cmap_to_user(const struct fb_cmap *from, struct fb_cmap_user *to); | |
975 | 975 | extern int fb_set_cmap(struct fb_cmap *cmap, struct fb_info *fb_info); |
976 | 976 | extern int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *fb_info); |
977 | -extern struct fb_cmap *fb_default_cmap(int len); | |
977 | +extern const struct fb_cmap *fb_default_cmap(int len); | |
978 | 978 | extern void fb_invert_cmaps(void); |
979 | 979 | |
980 | 980 | struct fb_videomode { |