Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3013502pxb; Mon, 1 Nov 2021 06:21:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMKVKF6lsMhjRzy5x+X08Cpt60CKJSgEZp07iZx4ylWsiHB6lab9q6RJkMbwd2uPwdP2Kq X-Received: by 2002:a05:6402:1e88:: with SMTP id f8mr41013403edf.86.1635772900129; Mon, 01 Nov 2021 06:21:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635772900; cv=none; d=google.com; s=arc-20160816; b=1E9qMQi1Rg4atZ9FNp+sqvboRlkRjtGgOE/+BTU9oxNXDAlJ7fuX+z+xC1gb1BVUwz QLViYvAWWZ+gpzJiBLdZwncWyPF6YqDf6TW7YYJExvNvggIoD5n5yAUAyILV2TMZ7HlF tQqLy3jYLzK2CCAvB8HpXHnLt30K2hy9c24KBkfVaujn3PlAUHJ6T4xaH2mGBm+xvDGj qaNHMr1mlQErNKalnpGdIetaJRZbPu24kHAZweUpxLxN3ab4lfvCVq/kaVDBSwvcX4Dz 68yGgaBnyxfwFgVJSKUwplhMCOu9G11j7Q0/kIm4DvcLbu9IuzPfhxiuW5OSdd2cn9s8 qg3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=VN50aBuQkEJo05XcjYfLxzT8qQ8HoI4ikTMhOsYfwRA=; b=T0jY67xqPsWCiVwziakCV1SKcgkvRjjyKltpSGLY/RrRNejXK2nHj3RRslEC/g3ovi 7+Adqpp4HvqX0kA6l0tRXl3EFS8Pv1NB9+NTj4ROb+dDNavhbcv9i5ra5Tp6dubn2wEu WT3DIAAfetl2Np+4lFuH/ly8saENhIeETxmoGeir/A4AtlGwhvsovDaCm5lT4sadmu+3 wET2Qu4LXLI7x8JGJdLCNid77kn9vpJBLSN9hCAmiqRchBDk/tkSa+RQJhy07VRFOBFs /IwCowZTf0GqncdXR3YK0uohChVX7YxJrwd6XTfsKAnViom6qzGAxfVIaSlwvXwz1gyi Q0oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aV8RQBnI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x5si18295473edi.557.2021.11.01.06.21.16; Mon, 01 Nov 2021 06:21:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aV8RQBnI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231964AbhKANVi (ORCPT + 99 others); Mon, 1 Nov 2021 09:21:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:49596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230417AbhKANVc (ORCPT ); Mon, 1 Nov 2021 09:21:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3859F60EE9; Mon, 1 Nov 2021 13:18:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635772739; bh=MRJJ65sLMFNXIIujuO4NjvdCus/lqQZG52E50gJmYb0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aV8RQBnIfNfBNgcXm+Px0Zvm5oHOsdzOa/rnXgLGFy+Iu5DJiookNA8ViwikTF6Ob a4x+IsWTrEtGn8JiBuFm6VydrIAuPDA3u88mTK4zGVwIdjKJdAp4ov/I9HgBAuuK6x neNS9EVyUubFDvBV42fOGBoir4XrMMIOs/SZnd3ZTlLV8Z6YjjOGxR2De4s4ZYsGkU /wqlCF/zo7LbPFHkN5qb/lITlk0B0JC5m7mVJIjlEKQlbuxPRol054QCgKrhMGFDVJ gerwtkFGgt+qy05JJM1JMRkLgSjWmgyK/KUYOXl2ugRilhxI0xX1uf+u0GLM2S51pl 3eW/eDmN+bhSg== Date: Mon, 1 Nov 2021 21:18:49 +0800 From: Peter Chen To: Qihang Hu Cc: balbi@kernel.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: gadget: composite: Fix null pointer exception Message-ID: <20211101131849.GA4126@Peter> References: <20211101015757.290350-1-huqihang@oppo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211101015757.290350-1-huqihang@oppo.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21-11-01 09:57:57, Qihang Hu wrote: > In the config_ep_by_speed_and_alt function, select the corresponding > descriptor through g->speed, but the interface driver function driver > may not > support the corresponding speed. So, we need to check whether the > interface 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 > --- > drivers/usb/gadget/composite.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c > index 72a9797dbbae..443a65af98af 100644 > --- a/drivers/usb/gadget/composite.c > +++ b/drivers/usb/gadget/composite.c > @@ -166,21 +166,21 @@ int config_ep_by_speed_and_alt(struct usb_gadget *g, > /* select desired speed */ > switch (g->speed) { > case USB_SPEED_SUPER_PLUS: > - if (gadget_is_superspeed_plus(g)) { > + if (gadget_is_superspeed_plus(g) && f->ssp_descriptors) { > speed_desc = f->ssp_descriptors; > want_comp_desc = 1; > break; > } > fallthrough; > case USB_SPEED_SUPER: > - if (gadget_is_superspeed(g)) { > + if (gadget_is_superspeed(g) && f->ss_descriptors) { > speed_desc = f->ss_descriptors; > want_comp_desc = 1; > break; > } > fallthrough; > case USB_SPEED_HIGH: > - if (gadget_is_dualspeed(g)) { > + if (gadget_is_dualspeed(g) && f->hs_descriptors) { > speed_desc = f->hs_descriptors; > break; > } > -- > 2.25.1 > Besides your fix, you may show an warning that said "the function doesn't hold the descriptors for supported speed, using the default (FS) descriptors". See below kernel doc for detail. /** * config_ep_by_speed_and_alt() - configures the given endpoint * * .... * Note: the supplied function should hold all the descriptors * for supported speeds */ What's more, you may fix android f_audio_source.c, and let it support super speed and super speed plus. -- Thanks, Peter Chen