diff options
author | Antonino A. Daplas <adaplas@gmail.com> | 2007-07-17 07:05:37 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-17 13:23:12 -0400 |
commit | 24fc72239ab5a2d26ebdd4f6950539e6120d1a54 (patch) | |
tree | 4725301358a10bfd94e3616efbe519c5ef107cff | |
parent | 9058be43cf9f32b6c636aa6954b4f1a6b22098f6 (diff) |
macfb: fix pseudo_palette size and overrun
- the pseudo_palette is only 16 elements long.
- do not write to the pseudo_palette if regno (array index) is more than 15.
Signed-off-by: Antonino Daplas <adaplas@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/video/macfb.c | 93 |
1 files changed, 50 insertions, 43 deletions
diff --git a/drivers/video/macfb.c b/drivers/video/macfb.c index f7d647dda978..aa8c714d6245 100644 --- a/drivers/video/macfb.c +++ b/drivers/video/macfb.c | |||
@@ -170,7 +170,7 @@ static struct fb_fix_screeninfo macfb_fix = { | |||
170 | }; | 170 | }; |
171 | 171 | ||
172 | static struct fb_info fb_info; | 172 | static struct fb_info fb_info; |
173 | static u32 pseudo_palette[17]; | 173 | static u32 pseudo_palette[16]; |
174 | static int inverse = 0; | 174 | static int inverse = 0; |
175 | static int vidtest = 0; | 175 | static int vidtest = 0; |
176 | 176 | ||
@@ -529,56 +529,63 @@ static int macfb_setcolreg(unsigned regno, unsigned red, unsigned green, | |||
529 | if (regno >= fb_info->cmap.len) | 529 | if (regno >= fb_info->cmap.len) |
530 | return 1; | 530 | return 1; |
531 | 531 | ||
532 | switch (fb_info->var.bits_per_pixel) { | 532 | if (fb_info->var.bits_per_pixel <= 8) { |
533 | case 1: | 533 | switch (fb_info->var.bits_per_pixel) { |
534 | /* We shouldn't get here */ | 534 | case 1: |
535 | break; | 535 | /* We shouldn't get here */ |
536 | case 2: | 536 | break; |
537 | case 4: | 537 | case 2: |
538 | case 8: | 538 | case 4: |
539 | if (macfb_setpalette) | 539 | case 8: |
540 | macfb_setpalette(regno, red, green, blue, fb_info); | 540 | if (macfb_setpalette) |
541 | else | 541 | macfb_setpalette(regno, red, green, blue, |
542 | return 1; | 542 | fb_info); |
543 | break; | 543 | else |
544 | case 16: | 544 | return 1; |
545 | if (fb_info->var.red.offset == 10) { | 545 | break; |
546 | /* 1:5:5:5 */ | 546 | } |
547 | ((u32*) (fb_info->pseudo_palette))[regno] = | 547 | } else if (regno < 16) { |
548 | switch (fb_info->var.bits_per_pixel) { | ||
549 | case 16: | ||
550 | if (fb_info->var.red.offset == 10) { | ||
551 | /* 1:5:5:5 */ | ||
552 | ((u32*) (fb_info->pseudo_palette))[regno] = | ||
548 | ((red & 0xf800) >> 1) | | 553 | ((red & 0xf800) >> 1) | |
549 | ((green & 0xf800) >> 6) | | 554 | ((green & 0xf800) >> 6) | |
550 | ((blue & 0xf800) >> 11) | | 555 | ((blue & 0xf800) >> 11) | |
551 | ((transp != 0) << 15); | 556 | ((transp != 0) << 15); |
552 | } else { | 557 | } else { |
553 | /* 0:5:6:5 */ | 558 | /* 0:5:6:5 */ |
554 | ((u32*) (fb_info->pseudo_palette))[regno] = | 559 | ((u32*) (fb_info->pseudo_palette))[regno] = |
555 | ((red & 0xf800) ) | | 560 | ((red & 0xf800) ) | |
556 | ((green & 0xfc00) >> 5) | | 561 | ((green & 0xfc00) >> 5) | |
557 | ((blue & 0xf800) >> 11); | 562 | ((blue & 0xf800) >> 11); |
563 | } | ||
564 | break; | ||
565 | /* I'm pretty sure that one or the other of these | ||
566 | doesn't exist on 68k Macs */ | ||
567 | case 24: | ||
568 | red >>= 8; | ||
569 | green >>= 8; | ||
570 | blue >>= 8; | ||
571 | ((u32 *)(fb_info->pseudo_palette))[regno] = | ||
572 | (red << fb_info->var.red.offset) | | ||
573 | (green << fb_info->var.green.offset) | | ||
574 | (blue << fb_info->var.blue.offset); | ||
575 | break; | ||
576 | case 32: | ||
577 | red >>= 8; | ||
578 | green >>= 8; | ||
579 | blue >>= 8; | ||
580 | ((u32 *)(fb_info->pseudo_palette))[regno] = | ||
581 | (red << fb_info->var.red.offset) | | ||
582 | (green << fb_info->var.green.offset) | | ||
583 | (blue << fb_info->var.blue.offset); | ||
584 | break; | ||
558 | } | 585 | } |
559 | break; | 586 | } |
560 | /* I'm pretty sure that one or the other of these | 587 | |
561 | doesn't exist on 68k Macs */ | 588 | return 0; |
562 | case 24: | ||
563 | red >>= 8; | ||
564 | green >>= 8; | ||
565 | blue >>= 8; | ||
566 | ((u32 *)(fb_info->pseudo_palette))[regno] = | ||
567 | (red << fb_info->var.red.offset) | | ||
568 | (green << fb_info->var.green.offset) | | ||
569 | (blue << fb_info->var.blue.offset); | ||
570 | break; | ||
571 | case 32: | ||
572 | red >>= 8; | ||
573 | green >>= 8; | ||
574 | blue >>= 8; | ||
575 | ((u32 *)(fb_info->pseudo_palette))[regno] = | ||
576 | (red << fb_info->var.red.offset) | | ||
577 | (green << fb_info->var.green.offset) | | ||
578 | (blue << fb_info->var.blue.offset); | ||
579 | break; | ||
580 | } | ||
581 | return 0; | ||
582 | } | 589 | } |
583 | 590 | ||
584 | static struct fb_ops macfb_ops = { | 591 | static struct fb_ops macfb_ops = { |