From 47428147b363d8ebdd2bac59345568e5257717b4 Mon Sep 17 00:00:00 2001 From: Peter Chen Date: Thu, 22 Aug 2019 17:37:52 +0800 Subject: [PATCH] MLK-22366-8 usb: cdns3: gadget: improve EP0 init and de-init routine We find there is still EP0 request duirng EP0 configuration, and the pointer for this request is incorrect. In this commit, we make sure the EP0 request has deleted from the list at .udc_stop. If there is still one EP0 request during .udc_start, we will show a warning. Below oops is fixed by this change. [ 6339.760440] init: Sending signal 9 to service 'adbd' (pid 1878) process group... [ 6339.780901] audit: audit_lost=111533 audit_rate_limit=5 audit_backlog_limit=64 [ 6339.788319] audit: rate limit exceeded [ 6339.823842] libprocessgroup: Successfully killed process cgroup uid 0 pid 1878 in 54ms [ 6339.832589] init: Service 'adbd' (pid 1878) received signal 9 [ 6339.839108] init: processing action (init.svc.adbd=stopped) from (/init.usb.configfs.rc:14) [ 6340.002992] init: Received control message 'start' for 'adbd' from pid: 3324 (/vendor/bin/hw/android.hardware.usb@1.1-service.imx) [ 6340.023541] read descriptors [ 6340.026452] read strings [ 6340.927793] Unable to handle kernel paging request at virtual address 00020249 [ 6340.935026] Mem abort info: [ 6340.937824] Exception class = DABT (current EL), IL = 32 bits [ 6340.943747] SET = 0, FnV = 0 [ 6340.946805] EA = 0, S1PTW = 0 [ 6340.949949] Data abort info: [ 6340.952834] ISV = 0, ISS = 0x00000044 [ 6340.956673] CM = 0, WnR = 1 [ 6340.959648] user pgtable: 4k pages, 48-bit VAs, pgd = ffff8008f0309000 [ 6340.966178] [0000000000020249] *pgd=0000000000000000 [ 6340.971151] Internal error: Oops: 96000044 [#1] PREEMPT SMP [ 6340.976726] Modules linked in: [ 6340.979789] CPU: 5 PID: 1910 Comm: usb@1.1-service Not tainted 4.14.98-07858-g3dd4133 #1 [ 6340.987888] Hardware name: Freescale i.MX8QM MEK (DT) [ 6340.992945] task: ffff8008ee468e00 task.stack: ffff00000f1a8000 [ 6340.998884] PC is at cdns3_ep0_config+0x50/0xf0 [ 6341.003418] LR is at cdns3_ep0_config+0x40/0xf0 [ 6341.007949] pc : [] lr : [] pstate: 200001c5 [ 6341.015349] sp : ffff00000f1abc80 [ 6341.018668] x29: ffff00000f1abc80 x28: ffff8008ee468e00 [ 6341.023992] x27: ffff000009022000 x26: 0000000000000040 [ 6341.029318] x25: ffff00000f1abeb0 x24: ffff8008f05a4500 [ 6341.034635] x23: ffff8008f3929680 x22: 0000000000000040 [ 6341.039952] x21: 0000000000400001 x20: ffff00000f1f0000 [ 6341.045268] x19: ffff8008f2d22000 x18: 0000f7c42593c000 [ 6341.050585] x17: 0000f7c4258b17d0 x16: ffff00000829ecd8 [ 6341.055902] x15: 0000000000000000 x14: 0000000430060004 [ 6341.061219] x13: 0002010507010142 x12: ff02000004090002 [ 6341.066535] x11: 0002820507000200 x10: ffff8008eb685e68 [ 6341.071852] x9 : 0000000000000000 x8 : ffff8008ea9efd00 [ 6341.077168] x7 : 0000000000000000 x6 : 000000000000003f [ 6341.082485] x5 : 0000000000000040 x4 : 0000000000000000 [ 6341.087802] x3 : 0000000000020241 x2 : 0000000000000000 [ 6341.093119] x1 : ffff8008f059d040 x0 : ffff8008f059d000 [ 6341.098438] [ 6341.098438] X0: 0xffff8008f059cf80: [ 6341.103405] cf80 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.111623] cfa0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.119842] cfc0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.128051] cfe0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.136261] d000 f059dc00 ffff8008 082a01f8 ffff0000 00000000 00000000 00000000 00000000 [ 6341.144479] d020 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.152689] d040 00020241 00000000 00000000 00000000 00000000 00000000 f059d058 ffff8008 [ 6341.160898] d060 f059d058 ffff8008 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.169110] [ 6341.169110] X1: 0xffff8008f059cfc0: [ 6341.174077] cfc0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.182287] cfe0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.190496] d000 f059dc00 ffff8008 082a01f8 ffff0000 00000000 00000000 00000000 00000000 [ 6341.198706] d020 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.206916] d040 00020241 00000000 00000000 00000000 00000000 00000000 f059d058 ffff8008 [ 6341.215126] d060 f059d058 ffff8008 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.223335] d080 00000000 00000000 00000000 00000000 f3647c00 ffff8008 00000000 00000000 [ 6341.231545] d0a0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.239759] [ 6341.239759] X8: 0xffff8008ea9efc80: [ 6341.244724] fc80 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.252934] fca0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.261145] fcc0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.269371] fce0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.277580] fd00 6d766976 ffffffff 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.285790] fd20 00000000 00000000 00000000 00000000 ebbfb800 ffff8008 f7feee00 ffff8008 [ 6341.294000] fd40 f16a2980 ffff8008 f16a2300 ffff8008 00000000 00000000 00000000 00000000 [ 6341.302209] fd60 0000000d 00000006 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.310430] [ 6341.310430] X10: 0xffff8008eb685de8: [ 6341.315484] 5de8 00000000 00000000 00000000 00000000 00000000 00000000 f2d22010 ffff8008 [ 6341.323693] 5e08 00000000 00000000 00000000 00000000 eb685e18 ffff8008 eb685e18 ffff8008 [ 6341.331903] 5e28 4f894f89 00000000 ea9ef800 ffff8008 00000000 00000000 00000000 00000000 [ 6341.340113] 5e48 eb685e48 ffff8008 eb685e48 ffff8008 00000005 00000003 00000002 00000000 [ 6341.348323] 5e68 00000000 00010001 00000000 00000000 23df23df 00000000 eb685e80 ffff8008 [ 6341.356532] 5e88 eb685e80 ffff8008 00000003 00000000 316e316e 00000000 0fbcbdb8 ffff0000 [ 6341.364741] 5ea8 0fbcbdb8 ffff0000 00000000 00000000 f3b05b80 ffff8008 f2f2ce80 ffff8008 [ 6341.372952] 5ec8 eea86900 ffff8008 eea8691c ffff8008 00000074 00000003 00000003 00000005 [ 6341.381166] [ 6341.381166] X19: 0xffff8008f2d21f80: [ 6341.386217] 1f80 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.394427] 1fa0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.402637] 1fc0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.410846] 1fe0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.419057] 2000 f7540010 ffff8008 f7540010 ffff8008 00000000 00000000 f2d22018 ffff8008 [ 6341.427285] 2020 f2d22018 ffff8008 08a06998 ffff0000 f2d29800 ffff8008 091c3650 ffff0000 [ 6341.435502] 2040 f2d63218 ffff8008 f2d63330 ffff8008 f2d64030 ffff8008 00000000 00000005 [ 6341.443720] 2060 00000000 00000000 095d0150 ffff0000 f7540010 ffff8008 f2d64100 ffff8008 [ 6341.451932] [ 6341.451932] X23: 0xffff8008f3929600: [ 6341.456986] 9600 00000001 ffff8008 00010000 00000000 74737973 615f6d65 735f7070 63697274 [ 6341.465195] 9620 646f6d74 35314065 38333636 36303837 2e353432 00747874 00000000 00000000 [ 6341.473414] 9640 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.481632] 9660 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.489842] 9680 31316235 30303030 6273752e 00000033 00000000 00000000 f3929690 ffff8008 [ 6341.498051] 96a0 00000000 00000000 00000cfe 00000000 002010df 00000000 00000000 00000000 [ 6341.506261] 96c0 00000000 00000000 00000000 00000000 00000000 00000000 25401230 ffff0000 [ 6341.514470] 96e0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.522683] [ 6341.522683] X24: 0xffff8008f05a4480: [ 6341.527737] 4480 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.535947] 44a0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.544156] 44c0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.552366] 44e0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.560575] 4500 00000000 00000000 00000000 00000000 f7a338a0 ffff8008 6e038c00 ffff8000 [ 6341.568786] 4520 ec35b6a0 ffff8008 090571f0 ffff0000 00000000 00000000 00000002 00000000 [ 6341.577026] 4540 00028001 0005801e ee468e00 ffff8008 00000000 00000000 f05a4558 ffff8008 [ 6341.585248] 4560 f05a4558 ffff8008 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.593478] [ 6341.593478] X28: 0xffff8008ee468d80: [ 6341.598531] 8d80 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.606740] 8da0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.614950] 8dc0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.623160] 8de0 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 6341.631369] 8e00 00000022 00000000 ffffffff ffffffff 00000002 00000000 00000000 00000000 [ 6341.639579] 8e20 0f1a8000 ffff0000 00000002 00404040 00000000 00000000 f7acd438 ffff8008 [ 6341.647789] 8e40 00000001 00000005 0000003d 00000000 00170a04 00000001 f2f9e200 ffff8008 [ 6341.655998] 8e60 00000005 00000001 00000078 00000078 00000078 00000000 09031d48 ffff0000 [ 6341.664209] [ 6341.665707] Process usb@1.1-service (pid: 1910, stack limit = 0xffff00000f1a8000) [ 6341.673192] Call trace: [ 6341.675644] Exception stack(0xffff00000f1abb40 to 0xffff00000f1abc80) [ 6341.682092] bb40: ffff8008f059d000 ffff8008f059d040 0000000000000000 0000000000020241 [ 6341.689927] bb60: 0000000000000000 0000000000000040 000000000000003f 0000000000000000 [ 6341.697763] bb80: ffff8008ea9efd00 0000000000000000 ffff8008eb685e68 0002820507000200 [ 6341.705599] bba0: ff02000004090002 0002010507010142 0000000430060004 0000000000000000 [ 6341.713435] bbc0: ffff00000829ecd8 0000f7c4258b17d0 0000f7c42593c000 ffff8008f2d22000 [ 6341.721271] bbe0: ffff00000f1f0000 0000000000400001 0000000000000040 ffff8008f3929680 [ 6341.729107] bc00: ffff8008f05a4500 ffff00000f1abeb0 0000000000000040 ffff000009022000 [ 6341.736943] bc20: ffff8008ee468e00 ffff00000f1abc80 ffff0000089be364 ffff00000f1abc80 [ 6341.744779] bc40: ffff0000089be374 00000000200001c5 ffff8008f36abe00 0000000000000000 [ 6341.752615] bc60: 0000ffffffffffff ffff8008f36abe00 ffff00000f1abc80 ffff0000089be374 [ 6341.760459] [] cdns3_ep0_config+0x50/0xf0 [ 6341.766041] [] cdns3_gadget_config+0x18/0xb4 [ 6341.771878] [] cdns3_gadget_udc_start+0x40/0x60 [ 6341.777978] [] udc_bind_to_driver+0xc8/0x118 [ 6341.783814] [] usb_gadget_probe_driver+0xa0/0x12c [ 6341.790087] [] gadget_dev_desc_UDC_store+0xc8/0x124 [ 6341.796536] [] configfs_write_file+0xe8/0x184 [ 6341.802457] [] vfs_write+0xb8/0x1d4 [ 6341.807513] [] SyS_write+0x50/0xb0 [ 6341.812480] Exception stack(0xffff00000f1abec0 to 0xffff00000f1ac000) [ 6341.818928] bec0: 0000000000000014 0000f7c424dff219 000000000000000d 00000000000001b6 [ 6341.826764] bee0: 0000000000000000 0000f7c424dff008 0000000000000000 0000000000000000 [ 6341.834599] bf00: 0000000000000040 0000000000000000 000000000000000d 0000f7c424dff070 [ 6341.842436] bf20: 0000f7c424dff028 0000000000000bb0 0000f7c425400000 0000000000000000 [ 6341.850272] bf40: 0000f7c425e3ac28 0000f7c4258b17d0 0000f7c42593c000 000000000000000d [ 6341.858108] bf60: 0000000000000014 0000f7c424dff219 0000000000088241 00000000000001b6 [ 6341.865944] bf80: 0000f7c424dff141 0000f7c424d02000 aaaaaaaaaaaaaaab 0000b23b75c123c8 [ 6341.873780] bfa0: 0000000000000022 0000f7c424dff060 0000f7c425e121b0 0000f7c424dff040 [ 6341.881617] bfc0: 0000f7c4258b17d8 0000000040000000 0000000000000014 0000000000000040 [ 6341.889452] bfe0: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 [ 6341.897291] [] el0_svc_naked+0x34/0x38 [ 6341.902608] Code: b4000100 f9402003 91010001 f9402402 (f9000462) [ 6341.908714] ---[ end trace b38490f7134cdbe8 ]--- [ 6341.913334] Kernel panic - not syncing: Fatal exception [ 6341.918567] SMP: stopping secondary CPUs [ 6341.922494] Kernel Offset: disabled [ 6341.925983] CPU features: 0x180200c [ 6341.929473] Memory Limit: none [ 6341.932541] Rebooting in 5 seconds.. Signed-off-by: Peter Chen --- drivers/usb/cdns3/ep0.c | 8 ++++---- drivers/usb/cdns3/gadget.c | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/ep0.c index 09ab1a87a267..ca683b459b04 100644 --- a/drivers/usb/cdns3/ep0.c +++ b/drivers/usb/cdns3/ep0.c @@ -846,6 +846,7 @@ void cdns3_ep0_config(struct cdns3_device *priv_dev) struct cdns3_usb_regs __iomem *regs; struct cdns3_endpoint *priv_ep; u32 max_packet_size = 64; + struct usb_request *request; regs = priv_dev->regs; @@ -854,10 +855,9 @@ void cdns3_ep0_config(struct cdns3_device *priv_dev) priv_ep = priv_dev->eps[0]; - if (!list_empty(&priv_ep->pending_req_list)) { - struct usb_request *request; - - request = cdns3_next_request(&priv_ep->pending_req_list); + request = cdns3_next_request(&priv_ep->pending_req_list); + if (request) { + WARN_ON(1); list_del_init(&request->list); } diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 0d944e014689..b76b8e1757fd 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -1992,6 +1992,7 @@ static int cdns3_gadget_udc_stop(struct usb_gadget *gadget) struct usb_ep *ep; unsigned long flags; int ret = 0; + struct usb_request *request; spin_lock_irqsave(&priv_dev->lock, flags); priv_dev->gadget_driver = NULL; @@ -2015,6 +2016,11 @@ static int cdns3_gadget_udc_stop(struct usb_gadget *gadget) cdns3_free_trb_pool(priv_ep); } + priv_ep = priv_dev->eps[0]; + request = cdns3_next_request(&priv_ep->pending_req_list); + if (request) + list_del_init(&request->list); + /* disable interrupt for device */ writel(0, &priv_dev->regs->usb_ien); writel(USB_CONF_DEVDS, &priv_dev->regs->usb_conf); -- 2.17.1