From patchwork Sun Jul 17 00:34:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Tobias Schandinat X-Patchwork-Id: 982712 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p6H0Ggex000990 for ; Sun, 17 Jul 2011 00:16:51 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754400Ab1GQAQQ (ORCPT ); Sat, 16 Jul 2011 20:16:16 -0400 Received: from mailout-de.gmx.net ([213.165.64.23]:48160 "HELO mailout-de.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1753792Ab1GQAQQ (ORCPT ); Sat, 16 Jul 2011 20:16:16 -0400 Received: (qmail invoked by alias); 17 Jul 2011 00:16:14 -0000 Received: from dslb-088-065-180-016.pools.arcor-ip.net (EHLO localhost.localdomain) [88.65.180.16] by mail.gmx.net (mp059) with SMTP; 17 Jul 2011 02:16:14 +0200 X-Authenticated: #10250065 X-Provags-ID: V01U2FsdGVkX190hcUJhf50ZRRQKdtcge6ZbTpj1/uOvhL+laNooP qJR5wXsz+1ZhyZ From: Florian Tobias Schandinat To: linux-fbdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Florian Tobias Schandinat , stable@kernel.org Subject: [PATCH 2/2] viafb: improve pitch handling Date: Sun, 17 Jul 2011 00:34:03 +0000 Message-Id: <1310862843-4526-1-git-send-email-FlorianSchandinat@gmx.de> X-Mailer: git-send-email 1.6.3.2 X-Y-GMX-Trusted: 0 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sun, 17 Jul 2011 00:17:35 +0000 (UTC) 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 Cc: stable@kernel.org --- drivers/video/via/via_modesetting.h | 5 +++++ 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 ae35cfd..0138845 100644 --- a/drivers/video/via/via_modesetting.h +++ b/drivers/video/via/via_modesetting.h @@ -28,6 +28,11 @@ #include + +#define VIA_PITCH_SIZE (1<<3) +#define VIA_PITCH_MAX 0x3FF8 + + void via_set_primary_address(u32 addr); void via_set_secondary_address(u32 addr); void via_set_primary_pitch(u32 pitch); diff --git a/drivers/video/via/viafbdev.c b/drivers/video/via/viafbdev.c index aa87529..bddae58 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) info->fix.visual = bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; - info->fix.line_length = (info->var.xres_virtual * bpp / 8 + 7) & ~7; + info->fix.line_length = ALIGN(info->var.xres_virtual * bpp / 8, + VIA_PITCH_SIZE); } static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix, @@ -238,8 +239,12 @@ static int viafb_check_var(struct fb_var_screeninfo *var, depth = 24; viafb_fill_var_color_info(var, depth); - line = (var->xres_virtual * var->bits_per_pixel / 8 + 7) & ~7; - if (line * var->yres_virtual > ppar->memsize) + if (var->xres_virtual < var->xres) + var->xres_virtual = var->xres; + + line = ALIGN(var->xres_virtual * var->bits_per_pixel / 8, + VIA_PITCH_SIZE); + if (line > VIA_PITCH_MAX || line * var->yres_virtual > ppar->memsize) return -EINVAL; /* Based on var passed in to calculate the refresh,