From patchwork Tue Jun 16 16:31:29 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Figo.zhang" X-Patchwork-Id: 30641 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n5GGVh9g026534 for ; Tue, 16 Jun 2009 16:31:43 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756090AbZFPQbb (ORCPT ); Tue, 16 Jun 2009 12:31:31 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756358AbZFPQbb (ORCPT ); Tue, 16 Jun 2009 12:31:31 -0400 Received: from mail-px0-f189.google.com ([209.85.216.189]:35269 "EHLO mail-px0-f189.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756090AbZFPQba (ORCPT ); Tue, 16 Jun 2009 12:31:30 -0400 Received: by pxi27 with SMTP id 27so1068415pxi.33 for ; Tue, 16 Jun 2009 09:31:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:cc :content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=PiSPFxzGubHbZeN1rdVeIVpifXWwWaA+Bmg68qI9gzQ=; b=WgmIp4fmtpwZ7mRoxP3vj3/0F1/qetYeLvVguyG7vsV7sd3nw9Fx+b7c4Vgi2GtWwD ay6yZyUXXJT5MKaMtgzqfK4WDG2o1b/DKNdP0/kmRmzqm67QiJAirPkYYqwq0auxrNWL PRNu2bK02NzDne+KWimErPI1sdgBapaJAfsRQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; b=FoB9JdTcd/gFGRwBDUuoayf4y1e1w9KxZzik+fIbaLOij1dgCkJWVNtQQliGaT7IHh X7FKfeKM1Z9Wgk9qdAzrEF1sD/xh3DLKPx8qtBuQS7deEtcvyG344sl2Dt+X/6o8GzgN RaygrnfcEzqucIaZ+kP5s3WA0xetU8Mq+r3Co= Received: by 10.114.15.9 with SMTP id 9mr13776654wao.146.1245169892701; Tue, 16 Jun 2009 09:31:32 -0700 (PDT) Received: from ?118.132.134.147? ([118.132.134.147]) by mx.google.com with ESMTPS id v9sm8640739wah.1.2009.06.16.09.31.30 (version=SSLv3 cipher=RC4-MD5); Tue, 16 Jun 2009 09:31:32 -0700 (PDT) Subject: [PATCH v3]poll method lose race condition From: "Figo.zhang" To: Mauro Carvalho Chehab Cc: Linux Media Mailing List Date: Wed, 17 Jun 2009 00:31:29 +0800 Message-Id: <1245169889.6397.7.camel@myhost> Mime-Version: 1.0 X-Mailer: Evolution 2.26.2 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org bttv-driver.c,cx23885-video.c,cx88-video.c: poll method lose race condition for capture video. In v2, use the clear logic.Thanks to Trent Piepho's help. In v3, fix a hold mutex locked issue. Signed-off-by: Figo.zhang --- drivers/media/video/bt8xx/bttv-driver.c | 11 +++++++---- drivers/media/video/cx23885/cx23885-video.c | 14 ++++++++++---- drivers/media/video/cx88/cx88-video.c | 14 ++++++++++---- 3 files changed, 27 insertions(+), 12 deletions(-) -- 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 --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c index 23b7499..3688b6e 100644 --- a/drivers/media/video/bt8xx/bttv-driver.c +++ b/drivers/media/video/bt8xx/bttv-driver.c @@ -3152,6 +3152,7 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait) struct bttv_fh *fh = file->private_data; struct bttv_buffer *buf; enum v4l2_field field; + unsigned int rc = POLLERR; if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { if (!check_alloc_btres(fh->btv,fh,RESOURCE_VBI)) @@ -3160,9 +3161,10 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait) } if (check_btres(fh,RESOURCE_VIDEO_STREAM)) { + mutex_lock(&fh->cap.vb_lock); /* streaming capture */ if (list_empty(&fh->cap.stream)) - return POLLERR; + goto err; buf = list_entry(fh->cap.stream.next,struct bttv_buffer,vb.stream); } else { /* read() capture */ @@ -3191,11 +3193,12 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait) poll_wait(file, &buf->vb.done, wait); if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) - return POLLIN|POLLRDNORM; - return 0; + rc = POLLIN|POLLRDNORM; + else + rc = 0; err: mutex_unlock(&fh->cap.vb_lock); - return POLLERR; + return rc; } static int bttv_open(struct file *file) diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c index 68068c6..66bbd2e 100644 --- a/drivers/media/video/cx23885/cx23885-video.c +++ b/drivers/media/video/cx23885/cx23885-video.c @@ -796,6 +796,7 @@ static unsigned int video_poll(struct file *file, { struct cx23885_fh *fh = file->private_data; struct cx23885_buffer *buf; + unsigned int rc = POLLERR; if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { if (!res_get(fh->dev, fh, RESOURCE_VBI)) @@ -803,23 +804,28 @@ static unsigned int video_poll(struct file *file, return videobuf_poll_stream(file, &fh->vbiq, wait); } + mutex_lock(&fh->vidq.vb_lock); if (res_check(fh, RESOURCE_VIDEO)) { /* streaming capture */ if (list_empty(&fh->vidq.stream)) - return POLLERR; + goto done; buf = list_entry(fh->vidq.stream.next, struct cx23885_buffer, vb.stream); } else { /* read() capture */ buf = (struct cx23885_buffer *)fh->vidq.read_buf; if (NULL == buf) - return POLLERR; + goto done; } poll_wait(file, &buf->vb.done, wait); if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) - return POLLIN|POLLRDNORM; - return 0; + rc = POLLIN|POLLRDNORM; + else + rc = 0; +done: + mutex_unlock(&fh->vidq.vb_lock); + return rc; } static int video_release(struct file *file) diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c index b993d42..97545a0 100644 --- a/drivers/media/video/cx88/cx88-video.c +++ b/drivers/media/video/cx88/cx88-video.c @@ -869,6 +869,7 @@ video_poll(struct file *file, struct poll_table_struct *wait) { struct cx8800_fh *fh = file->private_data; struct cx88_buffer *buf; + unsigned int rc = POLLERR; if (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type) { if (!res_get(fh->dev,fh,RESOURCE_VBI)) @@ -876,22 +877,27 @@ video_poll(struct file *file, struct poll_table_struct *wait) return videobuf_poll_stream(file, &fh->vbiq, wait); } + mutex_lock(&fh->vidq.vb_lock); if (res_check(fh,RESOURCE_VIDEO)) { /* streaming capture */ if (list_empty(&fh->vidq.stream)) - return POLLERR; + goto done; buf = list_entry(fh->vidq.stream.next,struct cx88_buffer,vb.stream); } else { /* read() capture */ buf = (struct cx88_buffer*)fh->vidq.read_buf; if (NULL == buf) - return POLLERR; + goto done; } poll_wait(file, &buf->vb.done, wait); if (buf->vb.state == VIDEOBUF_DONE || buf->vb.state == VIDEOBUF_ERROR) - return POLLIN|POLLRDNORM; - return 0; + rc = POLLIN|POLLRDNORM; + else + rc = 0; +done: + mutex_unlock(&fh->vidq.vb_lock); + return rc; } static int video_release(struct file *file)