Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp583108pxh; Tue, 9 Nov 2021 15:40:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHFGtGMcDqL1LXAsv394gIUo2sR/WxuZ9OylHYg+lwkMFR0iTwRBpg7xfzXkKGDXsG2dQn X-Received: by 2002:a02:b790:: with SMTP id f16mr8988032jam.2.1636501204954; Tue, 09 Nov 2021 15:40:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636501204; cv=none; d=google.com; s=arc-20160816; b=ym7J37BzZHZ58/y2iKAGjOWZ4nZoJYtxMYirC+AMiJjlLTp+ti8iyQ6y0L75MhEi7T RuuT43xMCt0n8Tc8BIFAJoAS+0k0qRmwYwN0v6YhYlzy+N7xOt8Sd3qy2lHp+SdBbrWT I858+GRHX5Te4kkiEbehKxuyFkGM3QVs4j1HKDv08A/a423AuNfAvtMVvO1n+DhGjBh1 G/m5t0/etIf70O2Mycb4LxUuWDOAl4GtwZjWSHe3fUIOLsueK1Gq4eHp0pfK3vI9fiIU HxhddTgHGX/iSJYMRUUKjW81SzyhxHe2IzPD5tVNul16ugv23Y16KA6r1DapNHMXsWdV mv8Q== 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=yoxSZheD4NQsvNZx6/uFWKCxONcwyki7h3aihCKtuGg=; b=nQBn3AiIp8GD1uQaRH57g2jNZLrw9nNp2ea490JRCGe+VVdPG3if2lrosTsnmfn4+2 orySvxNH8dyc9R0uDFw+1aDeKR6/oGM9G7QS481xR3TmhPdAv8s3HfyWSK5mvTO3Ms7g Z/8xGjSLvU9nMTQ1WV+yFZoI+H4+tYpQVKfZfknuDHcLm/B6dETpmhEzG0rYqe+ki7cj u9y/MYvIl4dqni33s5r5kNrBNaDQ4H62LjYoWY6xtVm9x/FhHPU1hY3gYESfZIygK/wI Hbo0RWwAvgoLgzWLk/frSbomEIqnNIsoiof9DQ5uLeYzQC5Vap0ICq3JrFPSPDV3HOac cQPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lUGj36gv; 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 y5si44833229ill.62.2021.11.09.15.39.53; Tue, 09 Nov 2021 15:40:04 -0800 (PST) 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=lUGj36gv; 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 S242527AbhKIMee (ORCPT + 97 others); Tue, 9 Nov 2021 07:34:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:47312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241539AbhKIMed (ORCPT ); Tue, 9 Nov 2021 07:34:33 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id A5A8761051; Tue, 9 Nov 2021 12:31:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636461107; bh=S+e5iTV5+Bs/5vsYLLwsUEdlQ/kxNOz+WH4f2I2y4qc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lUGj36gvga6j3IfS8HCJXIrDBSy5v3ZccWpqUKD0snvVZh+ss5GUvorDKHh7wNZzV 0d/e+sWcM6e1cf8mbPMQAtDPuRDlruWExtRJiifU4rl8NTMk22LEupndeEpuJzL2Q8 Jhyj7SbQ5lNacDNKLdE9pznpcXxAFDmoUQG3XeOb1NmVaYNfLz/MaX3p4CnBa+mqo8 bGv5u+w/GYbJCIBG0erySFHKZkbH/khRIeOC3uQgqO93SiqKbYSPDYyjMR6qwgDGMN OizaZFBIoAw1UAyw0eHa5NIgY/2Bm1+BGcadXQ882IVFDTmPiB908zZNvrcpgwcjLR El1OFTkWNgLeg== Date: Tue, 9 Nov 2021 20:31:40 +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 v3] usb: gadget: composite: Show warning if function driver's descriptors are incomplete. Message-ID: <20211109123140.GA5208@Peter> References: <20211109101936.397503-1-huqihang@oppo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211109101936.397503-1-huqihang@oppo.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21-11-09 18:19:36, Qihang Hu wrote: > In the config_ep_by_speed_and_alt function, select the corresponding > descriptor through g->speed. But some unsound function drivers may But some 'legacy or not well designed' function drivers > not support the corresponding speed. So, we can directly display > warnings instead of panicking the kernel. instead of 'causing kernel panic' > At the same time, it > indicates a problem with the function in the warning message. It indicates the reasons in warning message. > > Signed-off-by: Qihang Hu > --- > Changes in v2: > -Add warning message > > Changes in v3: > -Change commit log > -Delete extra blank lines > -Modify 'incomplete_desc' to bool type The latest changelog should be showed at the first. > --- > drivers/usb/gadget/composite.c | 39 ++++++++++++++++++++++------------ > 1 file changed, 26 insertions(+), 13 deletions(-) > > diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c > index 72a9797dbbae..cb9c7edf9bbf 100644 > --- a/drivers/usb/gadget/composite.c > +++ b/drivers/usb/gadget/composite.c > @@ -159,6 +159,8 @@ int config_ep_by_speed_and_alt(struct usb_gadget *g, > int want_comp_desc = 0; > > struct usb_descriptor_header **d_spd; /* cursor for speed desc */ > + struct usb_composite_dev *cdev; > + bool incomplete_desc = false; > > if (!g || !f || !_ep) > return -EIO; > @@ -167,28 +169,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 = true; > } > 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 = true; > } > 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 = true; > } > fallthrough; > default: > speed_desc = f->fs_descriptors; > } > > + cdev = get_gadget_data(g); > + if (incomplete_desc) > + 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 +261,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 > Except the typo issues, other things are ok for me. It shows an warning message for not well designed function driver, instead of panic the kernel. It depends on Greg that whether it should be panic directly or show warning message to indicate the issue. -- Thanks, Peter Chen