linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: ffs: don't allow to open with O_NONBLOCK flag
@ 2015-04-01  9:39 Robert Baldyga
  2015-04-01 15:17 ` Michal Nazarewicz
  0 siblings, 1 reply; 6+ messages in thread
From: Robert Baldyga @ 2015-04-01  9:39 UTC (permalink / raw)
  To: balbi; +Cc: gregkh, mina86, linux-usb, linux-kernel, Robert Baldyga

FunctionFS can't support O_NONBLOCK because read/write operatons are
directly translated into USB requests which are asynchoronous, so we
can't know how long we will have to wait for request completion. For
this reason in case of open with O_NONBLOCK flag we return -EWOULDBLOCK.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
 drivers/usb/gadget/function/f_fs.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 175c995..1014911 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -538,6 +538,14 @@ static int ffs_ep0_open(struct inode *inode, struct file *file)
 	if (unlikely(ffs->state == FFS_CLOSING))
 		return -EBUSY;
 
+	/*
+	 * We are not supporting O_NONBLOCK because read/write operatons are
+	 * directly translated into USB requests which are asynchoronous, so
+	 * we can't know how long we will have to wait for request completion.
+	 */
+	if (unlikely(file->f_flags & O_NONBLOCK))
+		return -EWOULDBLOCK;
+
 	file->private_data = ffs;
 	ffs_data_opened(ffs);
 
@@ -874,6 +882,14 @@ ffs_epfile_open(struct inode *inode, struct file *file)
 	if (WARN_ON(epfile->ffs->state != FFS_ACTIVE))
 		return -ENODEV;
 
+	/*
+	 * We are not supporting O_NONBLOCK because read/write operatons are
+	 * directly translated into USB requests which are asynchoronous, so
+	 * we can't know how long we will have to wait for request completion.
+	 */
+	if (unlikely(file->f_flags & O_NONBLOCK))
+		return -EWOULDBLOCK;
+
 	file->private_data = epfile;
 	ffs_data_opened(epfile->ffs);
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-04-07 19:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-01  9:39 [PATCH] usb: gadget: ffs: don't allow to open with O_NONBLOCK flag Robert Baldyga
2015-04-01 15:17 ` Michal Nazarewicz
2015-04-03  6:14   ` Robert Baldyga
2015-04-07 13:44     ` Michal Nazarewicz
2015-04-07 16:52     ` David Laight
2015-04-07 19:48       ` Michal Nazarewicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).