From: Qihang Hu <huqihang@oppo.com>
To: balbi@kernel.org, gregkh@linuxfoundation.org, peter.chen@kernel.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Qihang Hu <huqihang@oppo.com>
Subject: [PATCH v2] usb: gadget: composite: Fix null pointer exception
Date: Fri, 5 Nov 2021 18:48:40 +0800 [thread overview]
Message-ID: <20211105104840.159533-1-huqihang@oppo.com> (raw)
In the config_ep_by_speed_and_alt function, select the corresponding
descriptor through g->speed, but the function driver may not
support the corresponding speed. So, we need to check whether the
function driver provides the corresponding speed descriptor when
selecting the descriptor.
[ 237.708146] android_work: sent uevent USB_STATE=CONNECTED
[ 237.712464] kconfigfs-gadget gadget: super-speed config #1: b
[ 237.712487] kUnable to handle kernel NULL pointer dereference at virtual address 0000000000000000
[ 237.712493] kMem abort info:
[ 237.712498] k ESR = 0x96000006
[ 237.712504] k EC = 0x25: DABT (current EL), IL = 32 bits
[ 237.712510] k SET = 0, FnV = 0
[ 237.712515] k EA = 0, S1PTW = 0
[ 237.712520] kData abort info:
[ 237.712525] k ISV = 0, ISS = 0x00000006
[ 237.712530] k CM = 0, WnR = 0
[ 237.712536] kuser pgtable: 4k pages, 39-bit VAs, pgdp=000000020ef29000
[ 237.712541] k[0000000000000000] pgd=000000020ef2a003, pud=000000020ef2a003, pmd=0000000000000000
[ 237.712554] kInternal error: Oops: 96000006 [#1] PREEMPT SMP
[ 237.722067] kSkip md ftrace buffer dump for: 0x1609e0
[ 237.787037] kWorkqueue: dwc_wq dwc3_bh_work.cfi_jt
[ 237.854922] kpstate: 60c00085 (nZCv daIf +PAN +UAO)
[ 237.863165] kpc : config_ep_by_speed_and_alt+0x90/0x308
[ 237.871766] klr : audio_set_alt+0x54/0x78
[ 237.879108] ksp : ffffffc0104839e0
Signed-off-by: Qihang Hu <huqihang@oppo.com>
---
Changes in v2:
-Add warning message
---
drivers/usb/gadget/composite.c | 40 +++++++++++++++++++++++-----------
1 file changed, 27 insertions(+), 13 deletions(-)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 72a9797dbbae..746b34cf0310 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -160,6 +160,9 @@ int config_ep_by_speed_and_alt(struct usb_gadget *g,
struct usb_descriptor_header **d_spd; /* cursor for speed desc */
+ struct usb_composite_dev *cdev;
+ int incomplete_desc = 0;
+
if (!g || !f || !_ep)
return -EIO;
@@ -167,28 +170,43 @@ int config_ep_by_speed_and_alt(struct usb_gadget *g,
switch (g->speed) {
case USB_SPEED_SUPER_PLUS:
if (gadget_is_superspeed_plus(g)) {
- speed_desc = f->ssp_descriptors;
- want_comp_desc = 1;
- break;
+ if (f->ssp_descriptors) {
+ speed_desc = f->ssp_descriptors;
+ want_comp_desc = 1;
+ break;
+ }
+ incomplete_desc = 1;
}
fallthrough;
case USB_SPEED_SUPER:
if (gadget_is_superspeed(g)) {
- speed_desc = f->ss_descriptors;
- want_comp_desc = 1;
- break;
+ if (f->ss_descriptors) {
+ speed_desc = f->ss_descriptors;
+ want_comp_desc = 1;
+ break;
+ }
+ incomplete_desc = 1;
}
fallthrough;
case USB_SPEED_HIGH:
if (gadget_is_dualspeed(g)) {
- speed_desc = f->hs_descriptors;
- break;
+ if (f->hs_descriptors) {
+ speed_desc = f->hs_descriptors;
+ break;
+ }
+ incomplete_desc = 1;
}
fallthrough;
default:
speed_desc = f->fs_descriptors;
}
+ cdev = get_gadget_data(g);
+ if (incomplete_desc != 0)
+ WARNING(cdev,
+ "%s doesn't hold the descriptors for current speed\n",
+ f->name);
+
/* find correct alternate setting descriptor */
for_each_desc(speed_desc, d_spd, USB_DT_INTERFACE) {
int_desc = (struct usb_interface_descriptor *)*d_spd;
@@ -244,12 +262,8 @@ int config_ep_by_speed_and_alt(struct usb_gadget *g,
_ep->maxburst = comp_desc->bMaxBurst + 1;
break;
default:
- if (comp_desc->bMaxBurst != 0) {
- struct usb_composite_dev *cdev;
-
- cdev = get_gadget_data(g);
+ if (comp_desc->bMaxBurst != 0)
ERROR(cdev, "ep0 bMaxBurst must be 0\n");
- }
_ep->maxburst = 1;
break;
}
--
2.25.1
next reply other threads:[~2021-11-05 10:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-05 10:48 Qihang Hu [this message]
2021-11-05 12:44 ` Greg KH
2021-11-08 12:42 ` 胡启航(Nick Hu)
2021-11-08 12:55 ` Greg KH
2021-11-08 13:10 ` 胡启航(Nick Hu)
2021-11-08 13:41 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211105104840.159533-1-huqihang@oppo.com \
--to=huqihang@oppo.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=peter.chen@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®