diff mbox series

usb: gadget: f_fs: increase eps_revmap length

Message ID 20230912103417.18839-1-jiazi.li@transsion.com (mailing list archive)
State Superseded
Headers show
Series usb: gadget: f_fs: increase eps_revmap length | expand

Commit Message

Jiazi Li Sept. 12, 2023, 10:34 a.m. UTC
Commit 41dc9ac163e7 ("usb: gadget: f_fs: Accept up to 30 endpoints.")
increase eps_addrmap length to 31, eps_revmap also need to increase.
Increase it's length to 32.

For same-address, opposite-direction endpoints, will use same idx in
eps_revmap, so add new marco REVMAP_IDX to calculate idx for endpoints.

Signed-off-by: Jiazi.Li <jiazi.li@transsion.com>
---
 drivers/usb/gadget/function/f_fs.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Greg KH Sept. 12, 2023, 10:50 a.m. UTC | #1
On Tue, Sep 12, 2023 at 06:34:17PM +0800, Jiazi.Li wrote:
> Commit 41dc9ac163e7 ("usb: gadget: f_fs: Accept up to 30 endpoints.")
> increase eps_addrmap length to 31, eps_revmap also need to increase.
> Increase it's length to 32.

Why 32?

> 
> For same-address, opposite-direction endpoints, will use same idx in
> eps_revmap, so add new marco REVMAP_IDX to calculate idx for endpoints.
> 
> Signed-off-by: Jiazi.Li <jiazi.li@transsion.com>

Please use your real name here, not your email alias.  Same for the
 From: line in your email


> ---
>  drivers/usb/gadget/function/f_fs.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index 6e9ef35a43a7..4a210368bd33 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -71,12 +71,14 @@ struct ffs_function {
>  	struct ffs_data			*ffs;
>  
>  	struct ffs_ep			*eps;
> -	u8				eps_revmap[16];
> +	u8				eps_revmap[32];
>  	short				*interfaces_nums;
>  
>  	struct usb_function		function;
>  };
>  
> +#define REVMAP_IDX(epaddr)	((epaddr & USB_ENDPOINT_NUMBER_MASK) \
> +				* 2 + ((epaddr & USB_DIR_IN) ? 1 : 0))

What is the * 2 for?  Also, this macro is hard to read, can you make
this an inline function instead, explaining what you are trying to
calculate?

thanks,

greg k-h
diff mbox series

Patch

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 6e9ef35a43a7..4a210368bd33 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -71,12 +71,14 @@  struct ffs_function {
 	struct ffs_data			*ffs;
 
 	struct ffs_ep			*eps;
-	u8				eps_revmap[16];
+	u8				eps_revmap[32];
 	short				*interfaces_nums;
 
 	struct usb_function		function;
 };
 
+#define REVMAP_IDX(epaddr)	((epaddr & USB_ENDPOINT_NUMBER_MASK) \
+				* 2 + ((epaddr & USB_DIR_IN) ? 1 : 0))
 
 static struct ffs_function *ffs_func_from_usb(struct usb_function *f)
 {
@@ -2843,8 +2845,7 @@  static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep,
 
 		ffs_ep->ep  = ep;
 		ffs_ep->req = req;
-		func->eps_revmap[ds->bEndpointAddress &
-				 USB_ENDPOINT_NUMBER_MASK] = idx + 1;
+		func->eps_revmap[REVMAP_IDX(ds->bEndpointAddress)] = idx + 1;
 		/*
 		 * If we use virtual address mapping, we restore
 		 * original bEndpointAddress value.
@@ -3371,7 +3372,7 @@  static void ffs_func_resume(struct usb_function *f)
 
 static int ffs_func_revmap_ep(struct ffs_function *func, u8 num)
 {
-	num = func->eps_revmap[num & USB_ENDPOINT_NUMBER_MASK];
+	num = func->eps_revmap[REVMAP_IDX(num)];
 	return num ? num : -EDOM;
 }