From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2992615AbcBSQOw (ORCPT ); Fri, 19 Feb 2016 11:14:52 -0500 Received: from smtp73.iad3a.emailsrvr.com ([173.203.187.73]:34503 "EHLO smtp73.iad3a.emailsrvr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1949298AbcBSQOO (ORCPT ); Fri, 19 Feb 2016 11:14:14 -0500 X-Auth-ID: abbotti@mev.co.uk X-Sender-Id: abbotti@mev.co.uk From: Ian Abbott To: devel@driverdev.osuosl.org Cc: Greg Kroah-Hartman , Ian Abbott , H Hartley Sweeten , linux-kernel@vger.kernel.org Subject: [PATCH 7/8] staging: comedi: COMEDI_BUFINFO: return -EPIPE for abnormal read Date: Fri, 19 Feb 2016 16:13:56 +0000 Message-Id: <1455898437-4640-8-git-send-email-abbotti@mev.co.uk> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1455898437-4640-1-git-send-email-abbotti@mev.co.uk> References: <1455898437-4640-1-git-send-email-abbotti@mev.co.uk> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The `COMEDI_BUFINFO` ioctl is used to advance the current position in the buffer by a specified amount (which can be 0) and get the current position. If an asynchronous command in the "read" direction has stopped normally, the command is terminated as soon as the position has been advanced to the end of all available data. This is not currently done if the command terminated with an error. Change it to allow the command to be terminated even if it stopped with an error, but report an `EPIPE` error to the user first. The `EPIPE` error will not be reported until the "read" position reported back to the user has been advanced to the end of all available data. Signed-off-by: Ian Abbott --- drivers/staging/comedi/comedi_fops.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index ffe58208..7cb1d06 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -686,13 +686,6 @@ static bool __comedi_is_subdevice_running(struct comedi_subdevice *s) return comedi_is_runflags_running(runflags); } -static bool comedi_is_subdevice_idle(struct comedi_subdevice *s) -{ - unsigned runflags = comedi_get_subdevice_runflags(s); - - return !(runflags & COMEDI_SRF_BUSY_MASK); -} - bool comedi_can_auto_free_spriv(struct comedi_subdevice *s) { unsigned runflags = __comedi_get_subdevice_runflags(s); @@ -1111,6 +1104,8 @@ static int do_bufinfo_ioctl(struct comedi_device *dev, struct comedi_bufinfo bi; struct comedi_subdevice *s; struct comedi_async *async; + unsigned int runflags; + int retval = 0; bool become_nonbusy = false; if (copy_from_user(&bi, arg, sizeof(bi))) @@ -1132,9 +1127,20 @@ static int do_bufinfo_ioctl(struct comedi_device *dev, comedi_buf_read_alloc(s, bi.bytes_read); bi.bytes_read = comedi_buf_read_free(s, bi.bytes_read); } - if (comedi_is_subdevice_idle(s) && - comedi_buf_read_n_available(s) == 0) + /* + * If nothing left to read, and command has stopped, and + * {"read" position not updated or command stopped normally}, + * then become non-busy. + */ + runflags = comedi_get_subdevice_runflags(s); + if (comedi_buf_read_n_available(s) == 0 && + !comedi_is_runflags_running(runflags) && + (bi.bytes_read == 0 || + !comedi_is_runflags_in_error(runflags))) { become_nonbusy = true; + if (comedi_is_runflags_in_error(runflags)) + retval = -EPIPE; + } bi.bytes_written = 0; } else { /* command was set up in "write" direction */ @@ -1156,6 +1162,9 @@ static int do_bufinfo_ioctl(struct comedi_device *dev, if (become_nonbusy) do_become_nonbusy(dev, s); + if (retval) + return retval; + if (copy_to_user(arg, &bi, sizeof(bi))) return -EFAULT; -- 2.7.0