From 7e08fbf2c8de2b2da48904f12b155be9e4ccb7d4 Mon Sep 17 00:00:00 2001 From: Ren Jianing Date: Wed, 6 Jan 2021 17:30:53 +0800 Subject: [PATCH] usb: gadget: f_fs: fix ep req_match error for composite device This patch add direction index for eps_revmap, which can avoid matching to the requests for other functions. For example, if we config ep1in for uac and ep1out for adb, the requests for ep1in will be matching to ffs without this patch. Change-Id: Ic7a52fca35503656bbc306c9f0014dfdea61392b Signed-off-by: Ren Jianing Signed-off-by: Frank Wang --- drivers/usb/gadget/function/f_fs.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index c045a16ab05d..58a5dd48fdbc 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -71,7 +71,7 @@ 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; @@ -2798,7 +2798,7 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, struct ffs_function *func = priv; struct ffs_ep *ffs_ep; unsigned ep_desc_id; - int idx; + int idx, ep_num; static const char *speed_names[] = { "full", "high", "super" }; if (type != FFS_DESCRIPTOR) @@ -2871,8 +2871,9 @@ 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; + ep_num = ((ds->bEndpointAddress & USB_ENDPOINT_DIR_MASK) >> 3) | + (ds->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); + func->eps_revmap[ep_num] = idx + 1; /* * If we use virtual address mapping, we restore * original bEndpointAddress value. @@ -3409,7 +3410,10 @@ 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]; + int ep_num = ((num & USB_ENDPOINT_DIR_MASK) >> 3) | + (num & USB_ENDPOINT_NUMBER_MASK); + + num = func->eps_revmap[ep_num]; return num ? num : -EDOM; }