linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: f_fs: Send a create event for endpoint files
@ 2023-03-07 23:26 Jerry Zhang
  2023-03-09 14:22 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Jerry Zhang @ 2023-03-07 23:26 UTC (permalink / raw)
  Cc: embedded, linux-usb, Jerry Zhang

From: Jerry Zhang <jerry@skydio.com>

If userspace is creating a composite gadget with one or
more functionfs functions, it generally goes through a process of:

1. mount functionfs devices
2. start up driver processes
3. driver processes open ep0 and write descriptors
4. once all descriptors are written, enable gadget

The user may want the gadget to be enabled as soon as possible.
However there is no race-free way to know when to enable the gadget
since the gadget enable process doesn't know the status of the
other driver processes. Furthermore, other driver processes
may be fixed binaries, so there may not be an opportunity to
modify their source to use a cooperative synchronization method.

This can be resolved by enabling inotify create events for endpoint
files. The gadget enable process can create inotify watches in each
driver's directory, and a create event for "ep1" will indicate that
the driver has finished writing descriptors. Once events for all
drivers have been received, the gadget is ready to be enabled.

Signed-off-by: Jerry Zhang <jerry@skydio.com>
---
 drivers/usb/gadget/function/f_fs.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index ddfc537c7526..fc038db46e14 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -13,10 +13,11 @@
 
 /* #define DEBUG */
 /* #define VERBOSE_DEBUG */
 
 #include <linux/blkdev.h>
+#include <linux/fsnotify.h>
 #include <linux/pagemap.h>
 #include <linux/export.h>
 #include <linux/fs_parser.h>
 #include <linux/hid.h>
 #include <linux/mm.h>
@@ -1443,10 +1444,11 @@ static struct dentry *ffs_sb_create_file(struct super_block *sb,
 		dput(dentry);
 		return NULL;
 	}
 
 	d_add(dentry, inode);
+	fsnotify_create(dentry->d_parent->d_inode, dentry);
 	return dentry;
 }
 
 /* Super block */
 static const struct super_operations ffs_sb_operations = {
-- 
2.37.3


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

end of thread, other threads:[~2023-03-09 14:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-07 23:26 [PATCH] usb: gadget: f_fs: Send a create event for endpoint files Jerry Zhang
2023-03-09 14:22 ` Greg KH

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).