From patchwork Thu May 12 13:47:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Issa Gorissen X-Patchwork-Id: 780072 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p4CDlca5008082 for ; Thu, 12 May 2011 13:47:38 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757046Ab1ELNrg (ORCPT ); Thu, 12 May 2011 09:47:36 -0400 Received: from cmsout01.mbox.net ([165.212.64.31]:46399 "EHLO cmsout01.mbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756571Ab1ELNrg (ORCPT ); Thu, 12 May 2011 09:47:36 -0400 Received: from cmsout01.mbox.net (cmsout01-lo [127.0.0.1]) by cmsout01.mbox.net (Postfix) with ESMTP id 08C773AC0DB for ; Thu, 12 May 2011 13:47:35 +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 390PeLNvG7920M01; Thu, 12 May 2011 13:47:32 -0000 X-USANET-Routed: 3 gwsout-vs Q:bmvirus Received: from cmsapps04.cms.usa.net [165.212.11.133] by cmsout01.mbox.net via smtad (C8.MAIN.3.72B) with ESMTP id XID406PeLNvG6876X01; Thu, 12 May 2011 13:47:32 -0000 X-USANET-Source: 165.212.11.133 IN flop.m@usa.net cmsapps04.cms.usa.net X-USANET-MsgId: XID406PeLNvG6876X01 Received: from [158.166.147.88] [158.169.131.14] by cmsapps04.cms.usa.net (ESMTPSA/flop.m@usa.net) via mtad (C8.MAIN.3.72B) with ESMTPSA id 628PeLNvf8368M40; Thu, 12 May 2011 13:47:31 -0000 X-USANET-Auth: 158.169.131.14 AUTH flop.m@usa.net [158.166.147.88] Message-ID: <4DCBE4DD.1040202@usa.net> Date: Thu, 12 May 2011 15:47:09 +0200 From: Issa Gorissen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 MIME-Version: 1.0 To: linux-media@vger.kernel.org Subject: [PATCH] ngene: blocking and nonblocking io for sec0 Z-USANET-MsgId: XID628PeLNvG8368X40 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]); Thu, 12 May 2011 13:47:38 +0000 (UTC) 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-05-12 15:28:53.573185365 +0200 @@ -53,15 +53,29 @@ 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_avail(&dev->tsout_rbuf); + if (!avail) + return -EAGAIN; + } else { + while (1) { + if (wait_event_interruptible(dev->tsout_rbuf.queue, + dvb_ringbuffer_free + (&dev->tsout_rbuf) >= count) >= 0) + break; + } + 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 +84,35 @@ 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; + } else { + while (!avail) { + if (wait_event_interruptible( + dev->tsin_rbuf.queue, + dvb_ringbuffer_avail(&dev->tsin_rbuf) > 0) < 0) + continue; + + avail = dvb_ringbuffer_avail(&dev->tsin_rbuf); + } } - return count; + + if (avail > count) + avail = count; + if (avail > 0) + dvb_ringbuffer_read_user(&dev->tsin_rbuf, buf, avail); + + if (!avail) + return -EAGAIN; + else + return avail; + } static const struct file_operations ci_fops = { @@ -98,9 +125,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, };