Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp48264rwo; Fri, 21 Jul 2023 08:20:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlFUzbTjyZq1gRgYxdv/fKMRfsG7aR2b5XTCQsyA6kvhwNDfq5WNkwNtn2cjDCUsXJPEkTE1 X-Received: by 2002:a05:6a20:2d5:b0:132:a85f:b2e7 with SMTP id 21-20020a056a2002d500b00132a85fb2e7mr2053817pzb.53.1689952824006; Fri, 21 Jul 2023 08:20:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689952823; cv=none; d=google.com; s=arc-20160816; b=S5cvsxJVGEVHkT/chzEldjesoGq4PmDG4MqLpEylGyGgK9hWoBUJ7fYPgXfo2R1mYf 9n/VWEiLwWTC/7/DiSOy/giFF8EvQXSxhmnXsXa96gyvNCkZ8BeEAwKyisocFoAOecXH qgBID0A7g6nXBWDHn2sAlBBAO5vstavOxV8SIvqgx/3pZKUoBcD3S/gZTg91HD5PlMLp kN0Pmsb8nMTNwKUuV7C28YFhDFaNR/nOK7mMFQazWkcu0tCFtx/mqz5bUytV2YLRVuPX Xj8tvIKPF7hE8go37jaKnKHjrcobzR+de6OnSQ2EDDbnYgpKdSUF2QhKF2NibbOlqOpC vHEw== 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; bh=CIkQohqkmikI1yRApQCfvFMuzd/MJB58pKsHYCC9Q4o=; fh=G/SBPjMfZxXxejgWhTJVYox/NKCVH6eYBRSCpYJNInA=; b=Lwefj3JemD8U06CHA2z97Wo9vzWbQhldFF1bReY5DVoPOmKZF9QdPBurVksqM3osEl JJeeWqSP9+eO0hD81hX58/X9nVuHqf7DHEZ3Jz8gK0vlW+/rQJ3LWRuF1ouG5/QXFUjo u0oD6xacvo+UXK0IpZBpzGJV0O6b1qeKfHzsqHygPvl/j3uGwrH7CVVCfo3QQm8g6hPR SYODjG//H6iaST/RQ9RZtmZ07Q9W8RlYJWKX3wiP7sr00fYf7EKbuz//uKg9xtE8lMeJ nqT9Zp2T0q5tWdVn1qMBgZ1BvxmjUDu6/ywkQ+VXMk6UBBYkRg4bqMEpYFzwd1qiwkrL RiHA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fd13-20020a056a002e8d00b0068632b6bc90si3435511pfb.114.2023.07.21.08.20.11; Fri, 21 Jul 2023 08:20:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231529AbjGUO5a (ORCPT + 99 others); Fri, 21 Jul 2023 10:57:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230447AbjGUO53 (ORCPT ); Fri, 21 Jul 2023 10:57:29 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 1609C30C8 for ; Fri, 21 Jul 2023 07:57:24 -0700 (PDT) Received: (qmail 1757634 invoked by uid 1000); 21 Jul 2023 10:57:24 -0400 Date: Fri, 21 Jul 2023 10:57:24 -0400 From: Alan Stern To: liulongfang Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] USB:bugfix a controller halt error Message-ID: References: <20230721100015.27124-1-liulongfang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230721100015.27124-1-liulongfang@huawei.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 21, 2023 at 06:00:15PM +0800, liulongfang wrote: > On systems that use ECC memory. The ECC error of the memory will > cause the USB controller to halt. It causes the usb_control_msg() > operation to fail. How often does this happen in real life? (Besides, it seems to me that if your system is getting a bunch of ECC memory errors then you've got much worse problems than a simple USB failure!) And why do you worry about ECC memory failures in particular? Can't _any_ kind of failure cause the usb_control_msg() operation to fail? > At this point, the returned buffer data is an abnormal value, and > continuing to use it will lead to incorrect results. The driver already contains code to check for abnormal values. The check is not perfect, but it should prevent things from going too badly wrong. > Therefore, it is necessary to judge the return value and exit. > > Signed-off-by: liulongfang There is a flaw in your reasoning. The operation carried out here is deliberately unsafe (for full-speed devices). It is made before we know the actual maxpacket size for ep0, and as a result it might return an error code even when it works okay. This shouldn't happen, but a lot of USB hardware is unreliable. Therefore we must not ignore the result merely because r < 0. If we do that, the kernel might stop working with some devices. Alan Stern > --- > drivers/usb/core/hub.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c > index a739403a9e45..6a43198be263 100644 > --- a/drivers/usb/core/hub.c > +++ b/drivers/usb/core/hub.c > @@ -4891,6 +4891,16 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1, > USB_DT_DEVICE << 8, 0, > buf, GET_DESCRIPTOR_BUFSIZE, > initial_descriptor_timeout); > + /* On systems that use ECC memory, ECC errors can > + * cause the USB controller to halt. > + * It causes this operation to fail. At this time, > + * the buf data is an abnormal value and needs to be exited. > + */ > + if (r < 0) { > + kfree(buf); > + goto fail; > + } > + > switch (buf->bMaxPacketSize0) { > case 8: case 16: case 32: case 64: case 255: > if (buf->bDescriptorType == > -- > 2.24.0 >