mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Abbott <abbotti@mev.co.uk>
To: <driverdev-devel@linuxdriverproject.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Ian Abbott <abbotti@mev.co.uk>,
	H Hartley Sweeten <hartleys@visionengravers.com>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH 1/7] staging: comedi: maybe force CMDF_WRITE command flag
Date: Thu, 30 Oct 2014 12:42:26 +0000	[thread overview]
Message-ID: <1414672952-1587-2-git-send-email-abbotti@mev.co.uk> (raw)
In-Reply-To: <1414672952-1587-1-git-send-email-abbotti@mev.co.uk>

Most comedi subdevices that support asynchronous commands only support
data transfer in either the "read" or "write" direction, as indicated by
the `SDF_CMD_READ` and `SDF_CMD_WRITE` subdevice flags, although a few
support both directions on the same subdevice (though not
simultaneously).  The `struct comedi_cmd` structure passed via ioctl
call to set up the command contains a `CMDF_WRITE` flag that can be used
to choose the direction if the subdevice supports both directions, but
the flag is optional if the subdevice only supports data transfer in one
direction.

If the subdevice only supports asynchronous data transfer in a sing
direction, set the `CMDF_WRITE` flag to the correct state so that Comedi
can make use of it later.  In the case of the `COMEDI_CMDTEST` ioctl,
the updated flag will be written back to the `struct comedi_cmd` in
user-space.  In the case of the `COMEDI_CMD` ioctl, the flag only gets
written back if an error is detected while testing the command, or if
the `CMDF_BOGUS` command flag is set.  Since `__comedi_get_user_cmd()`
is called for both ioctls, that's a good place to set the flag.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/staging/comedi/comedi_fops.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 224af2b..fef68da 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -1451,6 +1451,21 @@ static int __comedi_get_user_cmd(struct comedi_device *dev,
 		return -EINVAL;
 	}
 
+	/*
+	 * Set the CMDF_WRITE flag to the correct state if the subdevice
+	 * supports only "read" commands or only "write" commands.
+	 */
+	switch (s->subdev_flags & (SDF_CMD_READ | SDF_CMD_WRITE)) {
+	case SDF_CMD_READ:
+		cmd->flags &= ~CMDF_WRITE;
+		break;
+	case SDF_CMD_WRITE:
+		cmd->flags |= CMDF_WRITE;
+		break;
+	default:
+		break;
+	}
+
 	return 0;
 }
 
-- 
2.1.1


  reply	other threads:[~2014-10-30 12:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-30 12:42 [PATCH 0/7] staging: comedi: enforce data transfer direction Ian Abbott
2014-10-30 12:42 ` Ian Abbott [this message]
2014-10-30 12:42 ` [PATCH 2/7] staging: comedi: me4000: don't clobber command flags Ian Abbott
2014-10-30 12:42 ` [PATCH 3/7] staging: comedi: ni_mio_common: don't change CMDF_WRITE flag Ian Abbott
2014-10-30 12:42 ` [PATCH 4/7] staging: comedi: don't allow read() on async command set up for "write" Ian Abbott
2014-10-30 18:05   ` Hartley Sweeten
2014-10-30 20:27     ` Ian Abbott
2014-10-30 20:45       ` Hartley Sweeten
2014-10-30 21:00         ` Ian Abbott
2014-10-30 12:42 ` [PATCH 5/7] staging: comedi: don't allow write() on async command set up for "read" Ian Abbott
2014-10-30 18:07   ` Hartley Sweeten
2014-10-30 20:29     ` Ian Abbott
2014-10-30 12:42 ` [PATCH 6/7] staging: comedi: check command direction in poll() file operation Ian Abbott
2014-10-30 12:42 ` [PATCH 7/7] staging: comedi: check actual data direction for COMEDI_BUFINFO ioctl Ian Abbott
2014-10-30 21:29 ` [PATCH 0/7] staging: comedi: enforce data transfer direction Hartley Sweeten

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1414672952-1587-2-git-send-email-abbotti@mev.co.uk \
    --to=abbotti@mev.co.uk \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hartleys@visionengravers.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®