From patchwork Tue Dec 14 00:30:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Philips X-Patchwork-Id: 408192 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBE0d2tH028508 for ; Tue, 14 Dec 2010 00:39:02 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757192Ab0LNAic (ORCPT ); Mon, 13 Dec 2010 19:38:32 -0500 Received: from ifup.org ([198.145.64.140]:51178 "EHLO ifup.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754527Ab0LNAic (ORCPT ); Mon, 13 Dec 2010 19:38:32 -0500 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 14 Dec 2010 00:39:03 +0000 (UTC) X-Greylist: delayed 452 seconds by postgrey-1.27 at vger.kernel.org; Mon, 13 Dec 2010 19:38:32 EST Received: from localhost (c-71-56-137-246.hsd1.or.comcast.net [71.56.137.246]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ifup.org (Postfix) with ESMTPSA id 150B12516155; Mon, 13 Dec 2010 15:37:44 -0800 (PST) Date: Mon, 13 Dec 2010 16:30:24 -0800 From: Brandon Philips To: Torsten Kaiser Cc: Dave Young , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Guennadi Liakhovetski , Chris Clayton Subject: Re: [PATCH] bttv: fix mutex use before init Message-ID: <20101214003024.GA3575@hanuman.home.ifup.org> References: <20101212131550.GA2608@darkstar> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c index a529619..e656424 100644 --- a/drivers/media/video/bt8xx/bttv-driver.c +++ b/drivers/media/video/bt8xx/bttv-driver.c @@ -2391,16 +2391,11 @@ static int setup_window_lock(struct bttv_fh *fh, struct bttv *btv, fh->ov.field = win->field; fh->ov.setup_ok = 1; - /* - * FIXME: btv is protected by btv->lock mutex, while btv->init - * is protected by fh->cap.vb_lock. This seems to open the - * possibility for some race situations. Maybe the better would - * be to unify those locks or to use another way to store the - * init values that will be consumed by videobuf callbacks - */ + mutex_lock(&btv->init.cap.vb_lock); btv->init.ov.w.width = win->w.width; btv->init.ov.w.height = win->w.height; btv->init.ov.field = win->field; + mutex_unlock(&btv->init.cap.vb_lock); /* update overlay if needed */ retval = 0; @@ -2620,9 +2615,11 @@ static int bttv_s_fmt_vid_cap(struct file *file, void *priv, fh->cap.last = V4L2_FIELD_NONE; fh->width = f->fmt.pix.width; fh->height = f->fmt.pix.height; + mutex_lock(&btv->init.cap.vb_lock); btv->init.fmt = fmt; btv->init.width = f->fmt.pix.width; btv->init.height = f->fmt.pix.height; + mutex_unlock(&btv->init.cap.vb_lock); mutex_unlock(&fh->cap.vb_lock); return 0; @@ -2855,6 +2852,7 @@ static int bttv_s_fbuf(struct file *file, void *f, retval = 0; fh->ovfmt = fmt; + mutex_lock(&btv->init.cap.vb_lock); btv->init.ovfmt = fmt; if (fb->flags & V4L2_FBUF_FLAG_OVERLAY) { fh->ov.w.left = 0; @@ -2876,6 +2874,7 @@ static int bttv_s_fbuf(struct file *file, void *f, retval = bttv_switch_overlay(btv, fh, new); } } + mutex_unlock(&btv->init.cap.vb_lock); mutex_unlock(&fh->cap.vb_lock); return retval; } @@ -3141,6 +3140,7 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop) fh->do_crop = 1; mutex_lock(&fh->cap.vb_lock); + mutex_lock(&btv->init.cap.vb_lock); if (fh->width < c.min_scaled_width) { fh->width = c.min_scaled_width; @@ -3158,6 +3158,7 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop) btv->init.height = c.max_scaled_height; } + mutex_unlock(&btv->init.cap.vb_lock); mutex_unlock(&fh->cap.vb_lock); return 0; @@ -3302,9 +3303,9 @@ static int bttv_open(struct file *file) * Let's first copy btv->init at fh, holding cap.vb_lock, and then work * with the rest of init, holding btv->lock. */ - mutex_lock(&fh->cap.vb_lock); + mutex_lock(&btv->init.cap.vb_lock); *fh = btv->init; - mutex_unlock(&fh->cap.vb_lock); + mutex_unlock(&btv->init.cap.vb_lock); fh->type = type; fh->ov.setup_ok = 0; @@ -3502,9 +3503,9 @@ static int radio_open(struct file *file) if (unlikely(!fh)) return -ENOMEM; file->private_data = fh; - mutex_lock(&fh->cap.vb_lock); + mutex_lock(&btv->init.cap.vb_lock); *fh = btv->init; - mutex_unlock(&fh->cap.vb_lock); + mutex_unlock(&btv->init.cap.vb_lock); mutex_lock(&btv->lock); v4l2_prio_open(&btv->prio, &fh->prio); @@ -4489,6 +4490,7 @@ static int __devinit bttv_probe(struct pci_dev *dev, btv->opt_coring = coring; /* fill struct bttv with some useful defaults */ + mutex_init(&btv->init.cap.vb_lock); btv->init.btv = btv; btv->init.ov.w.width = 320; btv->init.ov.w.height = 240;