From patchwork Wed Jun 1 21:01:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 841902 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 p51LVXmo021775 for ; Wed, 1 Jun 2011 21:31:34 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759872Ab1FAVbc (ORCPT ); Wed, 1 Jun 2011 17:31:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1100 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756988Ab1FAVbb (ORCPT ); Wed, 1 Jun 2011 17:31:31 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p51L1tFW018957 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 1 Jun 2011 17:02:06 -0400 Received: from [10.3.236.199] (vpn-236-199.phx2.redhat.com [10.3.236.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p51L1qAX005767; Wed, 1 Jun 2011 17:01:53 -0400 Message-ID: <4DE6A8C0.4060603@redhat.com> Date: Wed, 01 Jun 2011 18:01:52 -0300 From: Mauro Carvalho Chehab User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110419 Red Hat/3.1.10-1.el6_0 Thunderbird/3.1.10 MIME-Version: 1.0 To: Oliver Endriss , Ralph Metzler CC: Linux Media Mailing List Subject: Fwd: [PATCH] ngene: blocking and nonblocking io for sec0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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]); Wed, 01 Jun 2011 21:31:34 +0000 (UTC) Oliver/Ralph, Could you please review this patch? On a quick look, it looks fine on my eyes, but I don't have any ngene hardware here for testing. Thanks! Mauro -------- Mensagem original -------- Date: Thu, 12 May 2011 15:47:09 +0200 From: Issa Gorissen To: linux-media@vger.kernel.org Subject: [PATCH] ngene: blocking and nonblocking io for sec0 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 -- 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, };