* [2/3] usb: gadget: f_fs: Add FUNCTIONFS_CONTROL_ONLY flag
@ 2018-07-02 22:01 Jerry Zhang
0 siblings, 0 replies; 2+ messages in thread
From: Jerry Zhang @ 2018-07-02 22:01 UTC (permalink / raw)
To: Felipe Balbi, Michal Nazarewicz, Greg Kroah-Hartman
Cc: linux-usb, zhangjerry, jerryxzha, android-kernel-team
This flag allows users to directly specify when
they want a ffs instance to be used for handling
control requests only via the configfs control_config/
group. When the flag is set, user must set *none*
of the speed descriptor flags and provide no
speeds in the descriptor. This ensures that it
cannot be mixed up with a normal function.
Signed-off-by: Jerry Zhang <zhangjerry@google.com>
---
drivers/usb/gadget/function/f_fs.c | 22 +++++++++++-----------
include/uapi/linux/usb/functionfs.h | 1 +
2 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index a6868f936c78..ddec3606c0e1 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -339,11 +339,6 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
case FFS_READ_DESCRIPTORS:
case FFS_READ_STRINGS:
/* Copy data */
- if (unlikely(len < 16)) {
- ret = -EINVAL;
- break;
- }
-
data = ffs_prepare_buffer(buf, len);
if (IS_ERR(data)) {
ret = PTR_ERR(data);
@@ -2393,10 +2388,19 @@ static int __ffs_data_got_descs(struct ffs_data *ffs,
FUNCTIONFS_VIRTUAL_ADDR |
FUNCTIONFS_EVENTFD |
FUNCTIONFS_ALL_CTRL_RECIP |
- FUNCTIONFS_CONFIG0_SETUP)) {
+ FUNCTIONFS_CONFIG0_SETUP |
+ FUNCTIONFS_CONTROL_ONLY)) {
ret = -ENOSYS;
goto error;
}
+ if ((bool) (flags & (FUNCTIONFS_HAS_FS_DESC |
+ FUNCTIONFS_HAS_HS_DESC |
+ FUNCTIONFS_HAS_SS_DESC)) ==
+ (bool) (flags & FUNCTIONFS_CONTROL_ONLY)) {
+ pr_err("Must have at least one speed descriptor "
+ "or CONTROL_ONLY (but not both)\n");
+ goto error;
+ }
data += 12;
len -= 12;
break;
@@ -2476,7 +2480,7 @@ static int __ffs_data_got_descs(struct ffs_data *ffs,
len -= ret;
}
- if (raw_descs == data || len) {
+ if (len) {
ret = -EINVAL;
goto error;
}
@@ -3030,10 +3034,6 @@ static int _ffs_func_bind(struct usb_configuration *c,
ENTER();
- /* Has descriptors only for speeds gadget does not support */
- if (unlikely(!(full | high | super)))
- return -ENOTSUPP;
-
/* Allocate a single chunk, less management later on */
vlabuf = kzalloc(vla_group_size(d), GFP_KERNEL);
if (unlikely(!vlabuf))
diff --git a/include/uapi/linux/usb/functionfs.h b/include/uapi/linux/usb/functionfs.h
index d77ee6b65328..25e55f485a6e 100644
--- a/include/uapi/linux/usb/functionfs.h
+++ b/include/uapi/linux/usb/functionfs.h
@@ -24,6 +24,7 @@ enum functionfs_flags {
FUNCTIONFS_EVENTFD = 32,
FUNCTIONFS_ALL_CTRL_RECIP = 64,
FUNCTIONFS_CONFIG0_SETUP = 128,
+ FUNCTIONFS_CONTROL_ONLY = 256,
};
/* Descriptor of an non-audio endpoint */
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [2/3] usb: gadget: f_fs: Add FUNCTIONFS_CONTROL_ONLY flag
@ 2018-07-03 18:23 Jerry Zhang
0 siblings, 0 replies; 2+ messages in thread
From: Jerry Zhang @ 2018-07-03 18:23 UTC (permalink / raw)
To: Felipe Balbi, Greg Kroah-Hartman
Cc: linux-usb, zhangjerry, jerryxzha, android-kernel-team
This flag allows users to directly specify when
they want a ffs instance to be used for handling
control requests only via the configfs control_config/
group. When the flag is set, user must set *none*
of the speed descriptor flags and provide no
speeds in the descriptor. This ensures that it
cannot be mixed up with a normal function.
Signed-off-by: Jerry Zhang <zhangjerry@google.com>
---
drivers/usb/gadget/function/f_fs.c | 22 +++++++++++-----------
include/uapi/linux/usb/functionfs.h | 1 +
2 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index a6868f936c78..ddec3606c0e1 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -339,11 +339,6 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf,
case FFS_READ_DESCRIPTORS:
case FFS_READ_STRINGS:
/* Copy data */
- if (unlikely(len < 16)) {
- ret = -EINVAL;
- break;
- }
-
data = ffs_prepare_buffer(buf, len);
if (IS_ERR(data)) {
ret = PTR_ERR(data);
@@ -2393,10 +2388,19 @@ static int __ffs_data_got_descs(struct ffs_data *ffs,
FUNCTIONFS_VIRTUAL_ADDR |
FUNCTIONFS_EVENTFD |
FUNCTIONFS_ALL_CTRL_RECIP |
- FUNCTIONFS_CONFIG0_SETUP)) {
+ FUNCTIONFS_CONFIG0_SETUP |
+ FUNCTIONFS_CONTROL_ONLY)) {
ret = -ENOSYS;
goto error;
}
+ if ((bool) (flags & (FUNCTIONFS_HAS_FS_DESC |
+ FUNCTIONFS_HAS_HS_DESC |
+ FUNCTIONFS_HAS_SS_DESC)) ==
+ (bool) (flags & FUNCTIONFS_CONTROL_ONLY)) {
+ pr_err("Must have at least one speed descriptor "
+ "or CONTROL_ONLY (but not both)\n");
+ goto error;
+ }
data += 12;
len -= 12;
break;
@@ -2476,7 +2480,7 @@ static int __ffs_data_got_descs(struct ffs_data *ffs,
len -= ret;
}
- if (raw_descs == data || len) {
+ if (len) {
ret = -EINVAL;
goto error;
}
@@ -3030,10 +3034,6 @@ static int _ffs_func_bind(struct usb_configuration *c,
ENTER();
- /* Has descriptors only for speeds gadget does not support */
- if (unlikely(!(full | high | super)))
- return -ENOTSUPP;
-
/* Allocate a single chunk, less management later on */
vlabuf = kzalloc(vla_group_size(d), GFP_KERNEL);
if (unlikely(!vlabuf))
diff --git a/include/uapi/linux/usb/functionfs.h b/include/uapi/linux/usb/functionfs.h
index d77ee6b65328..25e55f485a6e 100644
--- a/include/uapi/linux/usb/functionfs.h
+++ b/include/uapi/linux/usb/functionfs.h
@@ -24,6 +24,7 @@ enum functionfs_flags {
FUNCTIONFS_EVENTFD = 32,
FUNCTIONFS_ALL_CTRL_RECIP = 64,
FUNCTIONFS_CONFIG0_SETUP = 128,
+ FUNCTIONFS_CONTROL_ONLY = 256,
};
/* Descriptor of an non-audio endpoint */
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-07-03 18:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-03 18:23 [2/3] usb: gadget: f_fs: Add FUNCTIONFS_CONTROL_ONLY flag Jerry Zhang
-- strict thread matches above, loose matches on Subject: below --
2018-07-02 22:01 Jerry Zhang
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).