From patchwork Sun Jan 25 01:27:09 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Trent Piepho X-Patchwork-Id: 449 Return-path: Envelope-to: mchehab@infradead.org Delivery-date: Sun, 25 Jan 2009 01:27:14 +0000 Received: from vger.kernel.org ([209.132.176.167]) by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux)) id 1LQtmM-0003nN-DG for mchehab@infradead.org; Sun, 25 Jan 2009 01:27:14 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754156AbZAYB1M (ORCPT ); Sat, 24 Jan 2009 20:27:12 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754254AbZAYB1M (ORCPT ); Sat, 24 Jan 2009 20:27:12 -0500 Received: from mail4.sea5.speakeasy.net ([69.17.117.6]:57814 "EHLO mail4.sea5.speakeasy.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754239AbZAYB1L (ORCPT ); Sat, 24 Jan 2009 20:27:11 -0500 Received: (qmail 29878 invoked from network); 25 Jan 2009 01:27:09 -0000 Received: from shell2.sea5.speakeasy.net ([69.17.116.3]) (envelope-sender ) by mail4.sea5.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 25 Jan 2009 01:27:09 -0000 Date: Sat, 24 Jan 2009 17:27:09 -0800 (PST) From: Trent Piepho X-X-Sender: xyzzy@shell2.speakeasy.net To: Roel Kluin cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, Linux and Kernel Video Subject: Re: [PATCH] Bttv: move check on unsigned In-Reply-To: Message-ID: References: <497250C7.6030502@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org On Mon, 19 Jan 2009, Trent Piepho wrote: > On Sat, 17 Jan 2009, Roel Kluin wrote: > > Please review, this patch was not tested. > > > > The static function set_tvnorm is called in > > drivers/media/video/bt8xx/bttv-driver.c: > > > > 1355: set_tvnorm(btv, norm); > > 1868: set_tvnorm(btv, i); > > 3273: set_tvnorm(btv,btv->tvnorm); > > > > in the first two with an unsigned, but bttv->tvnorm is signed. > > Probably better to just change bttv->tvnorm is unsigned if we can. Here is an improved patch that does a full tvnorm fix for the driver. The tvnorm value is an index into an array and is never allowed to be negative or otherwise invalid. Most places it was passed around were unsigned, but a few structs and functions had signed values. I got rid of the "< 0" checks and changed some ">= BTTV_TVNORMS" checks to BUG_ON(). Any problems with this patch Roel? Mauro, don't apply as is, I'll send a pull request for a real patch later. --- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff -r 6a6eb9efc6cd linux/drivers/media/video/bt8xx/bttv-cards.c --- a/linux/drivers/media/video/bt8xx/bttv-cards.c Fri Jan 23 22:35:12 2009 -0200 +++ b/linux/drivers/media/video/bt8xx/bttv-cards.c Sat Jan 24 16:54:53 2009 -0800 @@ -4131,7 +4131,7 @@ static void __devinit avermedia_eeprom(s } /* used on Voodoo TV/FM (Voodoo 200), S0 wired to 0x10000 */ -void bttv_tda9880_setnorm(struct bttv *btv, int norm) +void bttv_tda9880_setnorm(struct bttv *btv, unsigned int norm) { /* fix up our card entry */ if(norm==V4L2_STD_NTSC) { diff -r 6a6eb9efc6cd linux/drivers/media/video/bt8xx/bttv-driver.c --- a/linux/drivers/media/video/bt8xx/bttv-driver.c Fri Jan 23 22:35:12 2009 -0200 +++ b/linux/drivers/media/video/bt8xx/bttv-driver.c Sat Jan 24 17:15:43 2009 -0800 @@ -1300,7 +1300,7 @@ bttv_crop_calc_limits(struct bttv_crop * } static void -bttv_crop_reset(struct bttv_crop *c, int norm) +bttv_crop_reset(struct bttv_crop *c, unsigned int norm) { c->rect = bttv_tvnorms[norm].cropcap.defrect; bttv_crop_calc_limits(c); @@ -1313,16 +1313,13 @@ set_tvnorm(struct bttv *btv, unsigned in const struct bttv_tvnorm *tvnorm; v4l2_std_id id; - if (norm < 0 || norm >= BTTV_TVNORMS) - return -EINVAL; + BUG_ON(norm >= BTTV_TVNORMS); + BUG_ON(btv->tvnorm >= BTTV_TVNORMS); tvnorm = &bttv_tvnorms[norm]; - if (btv->tvnorm < 0 || - btv->tvnorm >= BTTV_TVNORMS || - 0 != memcmp(&bttv_tvnorms[btv->tvnorm].cropcap, - &tvnorm->cropcap, - sizeof (tvnorm->cropcap))) { + if (!memcmp(&bttv_tvnorms[btv->tvnorm].cropcap, &tvnorm->cropcap, + sizeof (tvnorm->cropcap))) { bttv_crop_reset(&btv->crop[0], norm); btv->crop[1] = btv->crop[0]; /* current = default */ diff -r 6a6eb9efc6cd linux/drivers/media/video/bt8xx/bttv-vbi.c --- a/linux/drivers/media/video/bt8xx/bttv-vbi.c Fri Jan 23 22:35:12 2009 -0200 +++ b/linux/drivers/media/video/bt8xx/bttv-vbi.c Sat Jan 24 17:02:43 2009 -0800 @@ -411,7 +411,7 @@ int bttv_g_fmt_vbi_cap(struct file *file return 0; } -void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, int norm) +void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm) { const struct bttv_tvnorm *tvnorm; unsigned int real_samples_per_line; diff -r 6a6eb9efc6cd linux/drivers/media/video/bt8xx/bttv.h --- a/linux/drivers/media/video/bt8xx/bttv.h Fri Jan 23 22:35:12 2009 -0200 +++ b/linux/drivers/media/video/bt8xx/bttv.h Sat Jan 24 17:00:13 2009 -0800 @@ -266,7 +266,7 @@ extern void bttv_init_card2(struct bttv /* card-specific funtions */ extern void tea5757_set_freq(struct bttv *btv, unsigned short freq); -extern void bttv_tda9880_setnorm(struct bttv *btv, int norm); +extern void bttv_tda9880_setnorm(struct bttv *btv, unsigned int norm); /* extra tweaks for some chipsets */ extern void bttv_check_chipset(void); diff -r 6a6eb9efc6cd linux/drivers/media/video/bt8xx/bttvp.h --- a/linux/drivers/media/video/bt8xx/bttvp.h Fri Jan 23 22:35:12 2009 -0200 +++ b/linux/drivers/media/video/bt8xx/bttvp.h Sat Jan 24 16:54:07 2009 -0800 @@ -137,7 +137,7 @@ struct bttv_buffer { /* bttv specific */ const struct bttv_format *fmt; - int tvnorm; + unsigned int tvnorm; int btformat; int btswap; struct bttv_geometry geo; @@ -156,7 +156,7 @@ struct bttv_buffer_set { }; struct bttv_overlay { - int tvnorm; + unsigned int tvnorm; struct v4l2_rect w; enum v4l2_field field; struct v4l2_clip *clips; @@ -176,7 +176,7 @@ struct bttv_vbi_fmt { }; /* bttv-vbi.c */ -void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, int norm); +void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm); struct bttv_crop { /* A cropping rectangle in struct bttv_tvnorm.cropcap units. */ @@ -380,7 +380,8 @@ struct bttv { unsigned int audio; unsigned int mute; unsigned long freq; - int tvnorm,hue,contrast,bright,saturation; + unsigned int tvnorm; + int hue, contrast, bright, saturation; struct v4l2_framebuffer fbuf; unsigned int field_count;