From nobody Sun May 19 14:40:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+99340+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99340+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1675145032; cv=none; d=zohomail.com; s=zohoarc; b=RLzdm1oZllyL3dlqQqxLuzs/H4zsKhpESsDJWmuWUHCSNXeVxi6/Mz6AcFqyt+5v0DSAoMgGzJPnL30EoR5DuzTDj9W8vUQaF90HNf4P2eyqPPAk8Y29w+VB29bFkL2kr2WWQSGHwstEJ/G/2lRNJNkIFCDk0v2DO7Ugi1QDS7A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675145032; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=TwPL1lvcOssoEWxphGrwML8sfnJq9QjbFysKo9/EnJg=; b=iz9Wpc8Xp3fOS4BhVCp7f/jU3bJGYYjDK+S/X5V7Tkntv9Zb51XihFPxiXZO4wPOezkG2XsnaXfTNtq7rwc1SKQHDby6lJI+iAd0xOCFn/TFnxjdice2zZ4VMVVDFu2ZXrg9UJVvZ8zxiM+L2lpfFtVCEXKkhC9Kzon8EZkj1Zg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+99340+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 167514503234451.39307695876914; Mon, 30 Jan 2023 22:03:52 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id IBWrYY1788612xbvyX7ECrr2; Mon, 30 Jan 2023 22:03:52 -0800 X-Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) by mx.groups.io with SMTP id smtpd.web11.6425.1675145031446216091 for ; Mon, 30 Jan 2023 22:03:51 -0800 X-Received: by mail-pg1-f202.google.com with SMTP id s76-20020a632c4f000000b0049ceb0f185eso6242623pgs.7 for ; Mon, 30 Jan 2023 22:03:51 -0800 (PST) X-Gm-Message-State: 9wglnkC1dsgX0hxOJm6fwX9Ix1787277AA= X-Google-Smtp-Source: AK7set8Gd+dkcgdEBvcFUjaQVYEAf26lgZaLHNJA6EifKaI67UYI3ltA71wcwFMd6pZI+R7l6416pzQqi7g= X-Received: from yuanyu.kir.corp.google.com ([2620:15c:29:204:60e3:dc53:1e92:62f7]) (user=yuanyu job=sendgmr) by 2002:aa7:9acc:0:b0:592:d6c:9729 with SMTP id x12-20020aa79acc000000b005920d6c9729mr3019360pfp.11.1675145030705; Mon, 30 Jan 2023 22:03:50 -0800 (PST) Date: Mon, 30 Jan 2023 22:03:47 -0800 In-Reply-To: <20230131060347.99785-1-yuanyu@google.com> Mime-Version: 1.0 References: <20230131060347.99785-1-yuanyu@google.com> Message-ID: <20230131060347.99785-2-yuanyu@google.com> Subject: [edk2-devel] [PATCH v2 1/1] MdeModulePkg: ScsiBusDxe: Refactor DiscoverScsiDevice() From: "Yuan Yu via groups.io" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Liming Gao , Hao A Wu , Ray Ni , Sivaparvathi chellaiah Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,yuanyu@google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1675145032; bh=VRdmbHJeY9U0NbtOT7BiK8jiqk4eKawonJtGP5UqQLE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=GtcinKBm25qn2G41SWPWGmhJKf9IiM1YffUJX1jdYQUMffjtsZZ8vzHF1enKnAixvRZ sxzcEEHwvvx99rofdTftX4gRbIhGloWYdzgD5D2MR/Th7UAe33kcVkvtkzdranWHzknLk XyY3Vbor8fNEUSkoqJ1qkb6H/NOixFMWcY8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1675145032660100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently DiscoverScsiDevice() returns a boolean which cannot distinguish a "not found" situation from a real problem like memory allocation failures. This patch changes the return value to an EFI_STATUS so that when memory allocation fails, it will return EFI_OUT_OF_RESOURCES. Without this change, any FALSE returned by DiscoverScsiDevice() will result in EFI_OUT_OF_RESOURCES being returned by ScsiScanCreateDevice(), which will cause a while loop in SCSIBusDriverBindingStart() to abort before other possible Puns in the SCSI channel are scanned, which means good devices may not have a chance to be discovered. If this good device is the boot device, boot will fail. Cc: Ard Biesheuvel Cc: Liming Gao Cc: Hao A Wu Cc: Ray Ni Cc: Sivaparvathi chellaiah Signed-off-by: Yuan Yu Reviewed-by: Hao A Wu > Reviewed-by: Hao A Wu --- MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h | 10 ++++--- MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c | 30 ++++++++++---------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h b/MdeModulePkg/Bus/= Scsi/ScsiBusDxe/ScsiBus.h index 68c5c02a9161..35a8a46ca7a2 100644 --- a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h +++ b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h @@ -455,7 +455,8 @@ ScsiExecuteSCSICommand ( =20 @retval EFI_SUCCESS Successfully to discover the device and at= tach ScsiIoProtocol to it. - @retval EFI_OUT_OF_RESOURCES Fail to discover the device. + @retval EFI_NOT_FOUND Fail to discover the device. + @retval EFI_OUT_OF_RESOURCES Fail to allocate memory resources. =20 **/ EFI_STATUS @@ -473,11 +474,12 @@ ScsiScanCreateDevice ( =20 @param ScsiIoDevice The pointer of SCSI_IO_DEV =20 - @retval TRUE Find SCSI Device and verify it. - @retval FALSE Unable to find SCSI Device. + @retval EFI_SUCCESS Find SCSI Device and verify it. + @retval EFI_NOT_FOUND Unable to find SCSI Device. + @retval EFI_OUT_OF_RESOURCES Fail to allocate memory resources. =20 **/ -BOOLEAN +EFI_STATUS DiscoverScsiDevice ( IN OUT SCSI_IO_DEV *ScsiIoDevice ); diff --git a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c b/MdeModulePkg/Bus/= Scsi/ScsiBusDxe/ScsiBus.c index fbe14c772496..4414a65eb1e6 100644 --- a/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c +++ b/MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.c @@ -1210,8 +1210,8 @@ ScsiScanCreateDevice ( ScsiBusDev->DevicePath ); =20 - if (!DiscoverScsiDevice (ScsiIoDevice)) { - Status =3D EFI_OUT_OF_RESOURCES; + Status =3D DiscoverScsiDevice (ScsiIoDevice); + if (EFI_ERROR (Status)) { goto ErrorExit; } =20 @@ -1276,11 +1276,12 @@ ErrorExit: =20 @param ScsiIoDevice The pointer of SCSI_IO_DEV =20 - @retval TRUE Find SCSI Device and verify it. - @retval FALSE Unable to find SCSI Device. + @retval EFI_SUCCESS Find SCSI Device and verify it. + @retval EFI_NOT_FOUND Unable to find SCSI Device. + @retval EFI_OUT_OF_RESOURCES Fail to allocate memory resources. =20 **/ -BOOLEAN +EFI_STATUS DiscoverScsiDevice ( IN OUT SCSI_IO_DEV *ScsiIoDevice ) @@ -1294,7 +1295,6 @@ DiscoverScsiDevice ( EFI_SCSI_SENSE_DATA *SenseData; UINT8 MaxRetry; UINT8 Index; - BOOLEAN ScsiDeviceFound; =20 HostAdapterStatus =3D 0; TargetStatus =3D 0; @@ -1302,7 +1302,7 @@ DiscoverScsiDevice ( =20 InquiryData =3D AllocateAlignedBuffer (ScsiIoDevice, sizeof (EFI_SCSI_IN= QUIRY_DATA)); if (InquiryData =3D=3D NULL) { - ScsiDeviceFound =3D FALSE; + Status =3D EFI_OUT_OF_RESOURCES; goto Done; } =20 @@ -1311,7 +1311,7 @@ DiscoverScsiDevice ( sizeof (EFI_SCSI_SENSE_DATA) ); if (SenseData =3D=3D NULL) { - ScsiDeviceFound =3D FALSE; + Status =3D EFI_OUT_OF_RESOURCES; goto Done; } =20 @@ -1342,7 +1342,7 @@ DiscoverScsiDevice ( (SenseData->Error_Code =3D=3D 0x70) && (SenseData->Sense_Key =3D=3D EFI_SCSI_SK_ILLEGAL_REQUEST)) { - ScsiDeviceFound =3D FALSE; + Status =3D EFI_NOT_FOUND; goto Done; } =20 @@ -1353,13 +1353,13 @@ DiscoverScsiDevice ( (Status =3D=3D EFI_INVALID_PARAMETER) || (Status =3D=3D EFI_UNSUPPORTED)) { - ScsiDeviceFound =3D FALSE; + Status =3D EFI_NOT_FOUND; goto Done; } } =20 if (Index =3D=3D MaxRetry) { - ScsiDeviceFound =3D FALSE; + Status =3D EFI_NOT_FOUND; goto Done; } =20 @@ -1367,14 +1367,14 @@ DiscoverScsiDevice ( // Retrieved inquiry data successfully // if (InquiryData->Peripheral_Qualifier !=3D 0) { - ScsiDeviceFound =3D FALSE; + Status =3D EFI_NOT_FOUND; goto Done; } =20 if ((InquiryData->Peripheral_Type >=3D EFI_SCSI_TYPE_RESERVED_LOW) && (InquiryData->Peripheral_Type <=3D EFI_SCSI_TYPE_RESERVED_HIGH)) { - ScsiDeviceFound =3D FALSE; + Status =3D EFI_NOT_FOUND; goto Done; } =20 @@ -1392,13 +1392,13 @@ DiscoverScsiDevice ( ScsiIoDevice->ScsiVersion =3D (UINT8)(InquiryData->Version & 0x07); } =20 - ScsiDeviceFound =3D TRUE; + Status =3D EFI_SUCCESS; =20 Done: FreeAlignedBuffer (SenseData, sizeof (EFI_SCSI_SENSE_DATA)); FreeAlignedBuffer (InquiryData, sizeof (EFI_SCSI_INQUIRY_DATA)); =20 - return ScsiDeviceFound; + return Status; } =20 /** --=20 2.39.1.456.gfc5497dd1b-goog -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99340): https://edk2.groups.io/g/devel/message/99340 Mute This Topic: https://groups.io/mt/96647625/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-