From 2f390380ca69e1617cdddb12d8da94f0a9f4319d Mon Sep 17 00:00:00 2001 From: Krzysztof Helt Date: Tue, 15 Dec 2009 16:46:25 -0800 Subject: [PATCH] fbdev: add palette register check to several drivers Add check if palette register number is in correct range for few drivers which miss it. The regno value comes indirectly from user space. Two drivers has converted check from BUG_ON() macro to just return an error (non-zero value). Signed-off-by: Krzysztof Helt Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/video/atafb.c | 3 +++ drivers/video/ep93xx-fb.c | 2 ++ drivers/video/maxinefb.c | 3 +++ drivers/video/pmag-ba-fb.c | 3 ++- drivers/video/pmagb-b-fb.c | 3 ++- 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/video/atafb.c b/drivers/video/atafb.c index b7687c55fe1..2051c9dc813 100644 --- a/drivers/video/atafb.c +++ b/drivers/video/atafb.c @@ -2245,6 +2245,9 @@ static int ext_setcolreg(unsigned int regno, unsigned int red, if (regno > 255) return 1; + if (regno > 255) + return 1; + switch (external_card_type) { case IS_VGA: OUTB(0x3c8, regno); diff --git a/drivers/video/ep93xx-fb.c b/drivers/video/ep93xx-fb.c index bd9d46f9529..27aab4a0619 100644 --- a/drivers/video/ep93xx-fb.c +++ b/drivers/video/ep93xx-fb.c @@ -358,6 +358,8 @@ static int ep93xxfb_setcolreg(unsigned int regno, unsigned int red, switch (info->fix.visual) { case FB_VISUAL_PSEUDOCOLOR: + if (regno > 255) + return 1; rgb = ((red & 0xff00) << 8) | (green & 0xff00) | ((blue & 0xff00) >> 8); diff --git a/drivers/video/maxinefb.c b/drivers/video/maxinefb.c index 5e91c2b30af..7854c7a37dc 100644 --- a/drivers/video/maxinefb.c +++ b/drivers/video/maxinefb.c @@ -92,6 +92,9 @@ static int maxinefb_setcolreg(unsigned regno, unsigned red, unsigned green, /* value to be written into the palette reg. */ unsigned long hw_colorvalue = 0; + if (regno > 255) + return 1; + red >>= 8; /* The cmap fields are 16 bits */ green >>= 8; /* wide, but the harware colormap */ blue >>= 8; /* registers are only 8 bits wide */ diff --git a/drivers/video/pmag-ba-fb.c b/drivers/video/pmag-ba-fb.c index 0573ec685a5..0f361b6100d 100644 --- a/drivers/video/pmag-ba-fb.c +++ b/drivers/video/pmag-ba-fb.c @@ -98,7 +98,8 @@ static int pmagbafb_setcolreg(unsigned int regno, unsigned int red, { struct pmagbafb_par *par = info->par; - BUG_ON(regno >= info->cmap.len); + if (regno >= info->cmap.len) + return 1; red >>= 8; /* The cmap fields are 16 bits */ green >>= 8; /* wide, but the hardware colormap */ diff --git a/drivers/video/pmagb-b-fb.c b/drivers/video/pmagb-b-fb.c index 98748723af9..2de0806421b 100644 --- a/drivers/video/pmagb-b-fb.c +++ b/drivers/video/pmagb-b-fb.c @@ -102,7 +102,8 @@ static int pmagbbfb_setcolreg(unsigned int regno, unsigned int red, { struct pmagbbfb_par *par = info->par; - BUG_ON(regno >= info->cmap.len); + if (regno >= info->cmap.len) + return 1; red >>= 8; /* The cmap fields are 16 bits */ green >>= 8; /* wide, but the hardware colormap */ -- 2.20.1