From patchwork Tue Jun 21 21:58:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Issa Gorissen X-Patchwork-Id: 902932 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5LLxTT5009644 for ; Tue, 21 Jun 2011 21:59:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754854Ab1FUV71 (ORCPT ); Tue, 21 Jun 2011 17:59:27 -0400 Received: from cmsout01.mbox.net ([165.212.64.31]:59092 "EHLO cmsout01.mbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753791Ab1FUV70 (ORCPT ); Tue, 21 Jun 2011 17:59:26 -0400 Received: from cmsout01.mbox.net (cmsout01-lo [127.0.0.1]) by cmsout01.mbox.net (Postfix) with ESMTP id 9E88E2ACD51; Tue, 21 Jun 2011 21:59:25 +0000 (GMT) X-USANET-Received: from cmsout01.mbox.net [127.0.0.1] by cmsout01.mbox.net via mtad (C8.MAIN.3.72B) with ESMTP id 622PFuV8w5888M01; Tue, 21 Jun 2011 21:59:22 -0000 X-USANET-Routed: 3 gwsout-vs Q:bmvirus Received: from cmsapps03.cms.usa.net [165.212.11.132] by cmsout01.mbox.net via smtad (C8.MAIN.3.72B) with ESMTP id XID033PFuV8w8637X01; Tue, 21 Jun 2011 21:59:22 -0000 X-USANET-Source: 165.212.11.132 IN flop.m@usa.net cmsapps03.cms.usa.net X-USANET-MsgId: XID033PFuV8w8637X01 Received: from hp8540w.home [85.201.143.112] by cmsapps03.cms.usa.net (ESMTPSA/flop.m@usa.net) via mtad (C8.MAIN.3.72B) with ESMTPSA id 819PFuV8V1472M39; Tue, 21 Jun 2011 21:59:22 -0000 X-USANET-Auth: 85.201.143.112 AUTH flop.m@usa.net hp8540w.home Message-ID: <4E011418.7040601@usa.net> Date: Tue, 21 Jun 2011 23:58:48 +0200 From: Issa Gorissen User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.2.17) Gecko/20110414 SUSE/3.1.10 Thunderbird/3.1.10 MIME-Version: 1.0 To: Linux Media Mailing List CC: Oliver Endriss , Mauro Carvalho Chehab , Ralph Metzler Subject: Re: Fwd: [PATCH] ngene: blocking and nonblocking io for sec0 References: <4DE6A8C0.4060603@redhat.com> <201106181307.32895@orion.escape-edv.de> In-Reply-To: <201106181307.32895@orion.escape-edv.de> Z-USANET-MsgId: XID819PFuV8w1472X39 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 21 Jun 2011 21:59:29 +0000 (UTC) Haven't fully understood the usage of wake_event_interruptible, now I have read its description. Sorry for the lame patch. Please find a fixed version below. Patch allows for blocking or nonblocking io on the ngene sec0 device. It also enforces one reader and one writer at a time. Signed-off-by: Issa Gorissen --- -- 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 --- a/linux/drivers/media/dvb/ngene/ngene-dvb.c 2011-05-10 19:11:21.000000000 +0200 +++ b/linux/drivers/media/dvb/ngene/ngene-dvb.c 2011-06-21 23:46:09.000000000 +0200 @@ -53,15 +53,30 @@ static ssize_t ts_write(struct file *fil struct dvb_device *dvbdev = file->private_data; struct ngene_channel *chan = dvbdev->priv; struct ngene *dev = chan->dev; + int avail = 0; + char nonblock = file->f_flags & O_NONBLOCK; - if (wait_event_interruptible(dev->tsout_rbuf.queue, - dvb_ringbuffer_free - (&dev->tsout_rbuf) >= count) < 0) + if (!count) return 0; - dvb_ringbuffer_write(&dev->tsout_rbuf, buf, count); + if (nonblock) { + avail = dvb_ringbuffer_free(&dev->tsout_rbuf); + if (!avail) + return -EAGAIN; + if (count < avail) + avail = count; + } else { + if (wait_event_interruptible(dev->tsout_rbuf.queue, + dvb_ringbuffer_free + (&dev->tsout_rbuf) >= count) < 0) + return -EINTR; + + avail = count; + } + + dvb_ringbuffer_write(&dev->tsout_rbuf, buf, avail); + return avail; - return count; } static ssize_t ts_read(struct file *file, char *buf, @@ -70,22 +85,29 @@ static ssize_t ts_read(struct file *file struct dvb_device *dvbdev = file->private_data; struct ngene_channel *chan = dvbdev->priv; struct ngene *dev = chan->dev; - int left, avail; + int avail = 0; + char nonblock = file->f_flags & O_NONBLOCK; - left = count; - while (left) { - if (wait_event_interruptible( - dev->tsin_rbuf.queue, - dvb_ringbuffer_avail(&dev->tsin_rbuf) > 0) < 0) - return -EAGAIN; + if (!count) + return 0; + + if (nonblock) { avail = dvb_ringbuffer_avail(&dev->tsin_rbuf); - if (avail > left) - avail = left; - dvb_ringbuffer_read_user(&dev->tsin_rbuf, buf, avail); - left -= avail; - buf += avail; + if (!avail) + return -EAGAIN; + if (avail > count) + avail = count; + } else { + if (wait_event_interruptible(dev->tsin_rbuf.queue, + dvb_ringbuffer_avail + (&dev->tsin_rbuf) >= count) < 0) + return -EINTR; + + avail = count; } - return count; + + dvb_ringbuffer_read_user(&dev->tsin_rbuf, buf, avail); + return avail; } static const struct file_operations ci_fops = { @@ -98,9 +120,9 @@ static const struct file_operations ci_f struct dvb_device ngene_dvbdev_ci = { .priv = 0, - .readers = -1, - .writers = -1, - .users = -1, + .readers = 1, + .writers = 1, + .users = 2, .fops = &ci_fops, };