From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.132.183.28, mailfrom: lersek@redhat.com) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by groups.io with SMTP; Wed, 31 Jul 2019 04:37:23 -0700 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7AE2B3082120; Wed, 31 Jul 2019 11:37:22 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-110.ams2.redhat.com [10.36.116.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82E65600CC; Wed, 31 Jul 2019 11:37:20 +0000 (UTC) Subject: Re: [PATCH] MdeModulePkg/UsbBusDxe: Return error when the device is not present To: Marcin Wojtas , devel@edk2.groups.io Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, jsd@semihalf.com, jaz@semihalf.com, feng.tian@intel.com, michael.d.kinney@intel.com, liming.gao@intel.com References: <1564554319-26810-1-git-send-email-mw@semihalf.com> From: "Laszlo Ersek" Message-ID: <8885da65-2d0f-ac2b-00c1-8ba6230ca9a8@redhat.com> Date: Wed, 31 Jul 2019 13:37:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <1564554319-26810-1-git-send-email-mw@semihalf.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 31 Jul 2019 11:37:22 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 07/31/19 08:25, Marcin Wojtas wrote: > Until now, during the USB device enumeration when its PortState > USB_PORT_STAT_CONNECTION bit was not set, the stack was not informed > that the device is not present. Fix that by returning appropriate > error code. > > Change-Id: I588f82b987993e9755f64ce76cde9eb690ef1d54 > Signed-off-by: Marcin Wojtas > --- > MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c > index be9d9bd..ab1db15 100644 > --- a/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c > +++ b/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbEnumer.c > @@ -719,6 +719,7 @@ UsbEnumerateNewDev ( > > if (!USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_CONNECTION)) { > DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: No device present at port %d\n", Port)); > + Status = EFI_NOT_FOUND; > goto ON_ERROR; > } else if (USB_BIT_IS_SET (PortState.PortStatus, USB_PORT_STAT_SUPER_SPEED)){ > Child->Speed = EFI_USB_SPEED_SUPER; > I think the patch is correct, based on a quite superficial analysis (i.e. without actual knowledge of USB specifics on my part). The reason is that Status is EFI_SUCCESS when the "goto" statement is reached, due to the preceding context Status = HubApi->GetPortStatus (HubIf, Port, &PortState); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "UsbEnumerateNewDev: failed to get speed of port %d\n", Port)); goto ON_ERROR; } And, the ON_ERROR label is documented as: ON_ERROR: // // If reach here, it means the enumeration process on a given port is interrupted due to error. // [...] // return Status; We shouldn't report success when there is no device present on the port. I think EFI_NOT_FOUND is a suitable error code; while it is not listed explicitly in the leading comment on the function, it does fit under @retval Others Failed to enumerate the device. Marcin, can you please remove the "Change-Id" tag from the commit message? (Or the MdeModulePkg maintainers could do that, just before they push the patch.) With "Change-Id" removed: Reviewed-by: Laszlo Ersek Thanks Laszlo