diff options
author | Florian Tobias Schandinat <FlorianSchandinat@gmx.de> | 2011-06-05 21:27:34 -0400 |
---|---|---|
committer | Florian Tobias Schandinat <FlorianSchandinat@gmx.de> | 2011-07-16 20:11:15 -0400 |
commit | 936a3f770b8de7042d793272f008ef1bb08522e9 (patch) | |
tree | 3863e60ae9cf13e48ecf2bcb131c92bc9c2b848b /drivers/video/via | |
parent | d933990c57b498c092ceef591c7c5d69dbfe9f30 (diff) |
viafb: improve pitch handling
This patch adds checks for minimum and maximum pitch size to prevent
invalid settings which could otherwise crash the machine. Also the
alignment is done in a slightly more readable way.
Signed-off-by: Florian Tobias Schandinat <FlorianSchandinat@gmx.de>
Cc: stable@kernel.org
Diffstat (limited to 'drivers/video/via')
-rw-r--r-- | drivers/video/via/via_modesetting.h | 5 | ||||
-rw-r--r-- | drivers/video/via/viafbdev.c | 11 |
2 files changed, 13 insertions, 3 deletions
diff --git a/drivers/video/via/via_modesetting.h b/drivers/video/via/via_modesetting.h index ae35cfdeb37c..013884543e91 100644 --- a/drivers/video/via/via_modesetting.h +++ b/drivers/video/via/via_modesetting.h | |||
@@ -28,6 +28,11 @@ | |||
28 | 28 | ||
29 | #include <linux/types.h> | 29 | #include <linux/types.h> |
30 | 30 | ||
31 | |||
32 | #define VIA_PITCH_SIZE (1<<3) | ||
33 | #define VIA_PITCH_MAX 0x3FF8 | ||
34 | |||
35 | |||
31 | void via_set_primary_address(u32 addr); | 36 | void via_set_primary_address(u32 addr); |
32 | void via_set_secondary_address(u32 addr); | 37 | void via_set_secondary_address(u32 addr); |
33 | void via_set_primary_pitch(u32 pitch); | 38 | void via_set_primary_pitch(u32 pitch); |
diff --git a/drivers/video/via/viafbdev.c b/drivers/video/via/viafbdev.c index aa87529d7d6a..bddae58ecd8a 100644 --- a/drivers/video/via/viafbdev.c +++ b/drivers/video/via/viafbdev.c | |||
@@ -151,7 +151,8 @@ static void viafb_update_fix(struct fb_info *info) | |||
151 | 151 | ||
152 | info->fix.visual = | 152 | info->fix.visual = |
153 | bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; | 153 | bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; |
154 | info->fix.line_length = (info->var.xres_virtual * bpp / 8 + 7) & ~7; | 154 | info->fix.line_length = ALIGN(info->var.xres_virtual * bpp / 8, |
155 | VIA_PITCH_SIZE); | ||
155 | } | 156 | } |
156 | 157 | ||
157 | static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix, | 158 | static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix, |
@@ -238,8 +239,12 @@ static int viafb_check_var(struct fb_var_screeninfo *var, | |||
238 | depth = 24; | 239 | depth = 24; |
239 | 240 | ||
240 | viafb_fill_var_color_info(var, depth); | 241 | viafb_fill_var_color_info(var, depth); |
241 | line = (var->xres_virtual * var->bits_per_pixel / 8 + 7) & ~7; | 242 | if (var->xres_virtual < var->xres) |
242 | if (line * var->yres_virtual > ppar->memsize) | 243 | var->xres_virtual = var->xres; |
244 | |||
245 | line = ALIGN(var->xres_virtual * var->bits_per_pixel / 8, | ||
246 | VIA_PITCH_SIZE); | ||
247 | if (line > VIA_PITCH_MAX || line * var->yres_virtual > ppar->memsize) | ||
243 | return -EINVAL; | 248 | return -EINVAL; |
244 | 249 | ||
245 | /* Based on var passed in to calculate the refresh, | 250 | /* Based on var passed in to calculate the refresh, |