From nobody Wed Feb 11 03:02:40 2026 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+104406+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+104406+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1683649947; cv=none; d=zohomail.com; s=zohoarc; b=Ap3ZPs0eAd2T8UrJK2JPvwAFkwF6qRXoosQj8D/0O7g8sdMwIM1p8t7wtROI5VIs9k13smQ1RinWwEFCPuLXXkKHUjPObPW/wyLHoCNFk7loX/3MiRrUa2sg/3qSz91v88jAwG8ZmW2PDEKJOHkAzW+YeQVVOiVGTLSpnahYS4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683649947; h=Content-Transfer-Encoding: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=rbRZvXKyRZ5YRnFBTquBFJAiSbW3/59plU83MtMrVi8=; b=nVH+klgM7oYIHWoSDceRrQnTyCphNYp1vt0mevA52ygrVmJadAoMN8wyXfMi2M1nkGfypJFp6sL92dGtQ4n7MOOtmBP+O1Ot/Jm9AUdeRk4BaaA+pV0Q0sdBqQkBzNLgfixZHEWJTO+XCzRr9nbXc7QaSD0bMXGZpIiiW+wsrLE= 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+104406+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1683649947905578.4127392107687; Tue, 9 May 2023 09:32:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id IrHGYY1788612xJRtqAF5uTm; Tue, 09 May 2023 09:32:27 -0700 X-Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by mx.groups.io with SMTP id smtpd.web10.37758.1683649946743736632 for ; Tue, 09 May 2023 09:32:27 -0700 X-Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-3f195b164c4so40564965e9.1 for ; Tue, 09 May 2023 09:32:26 -0700 (PDT) X-Gm-Message-State: fhyki4i0IcirSkrNh2neUI88x1787277AA= X-Google-Smtp-Source: ACHHUZ5r/Mm1yXym0FzI4sqfa/oqWOdh3SYlaIikYYt04Ma0Hm9mjXR53KDG848gzBccVZ4j0kv5nw== X-Received: by 2002:a1c:e906:0:b0:3f4:298b:d925 with SMTP id q6-20020a1ce906000000b003f4298bd925mr2636749wmc.41.1683649944885; Tue, 09 May 2023 09:32:24 -0700 (PDT) X-Received: from PC-PEDRO-ARCH.lan ([2001:8a0:7280:5801:9441:3dce:686c:bfc7]) by smtp.gmail.com with ESMTPSA id p1-20020a05600c204100b003f0a6a1f969sm20363938wmg.46.2023.05.09.09.32.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 09:32:24 -0700 (PDT) From: "Pedro Falcato" To: devel@edk2.groups.io Cc: Laszlo Ersek , Pedro Falcato , Jian J Wang , Liming Gao , Hao A Wu , Ray Ni Subject: [edk2-devel] [PATCH v2 01/12] MdeModulePkg/SataControllerDxe: Clean up error handling in Start() Date: Tue, 9 May 2023 17:32:01 +0100 Message-Id: <20230509163212.291333-2-pedro.falcato@gmail.com> In-Reply-To: <20230509163212.291333-1-pedro.falcato@gmail.com> References: <20230509163212.291333-1-pedro.falcato@gmail.com> MIME-Version: 1.0 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,pedro.falcato@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1683649947; bh=cdzamIz4CwaMdS6so+Sn9XnbvglKuQ4NL5rFXgFJlm0=; h=Cc:Date:From:Reply-To:Subject:To; b=nL9u0B/Ju+CPza2LovRmbrXspEyWxYwGcSTDQilFXF4TXKkmZfgm4snLPAKzKuOGAyl hlSZPbzRvAKC5q0uWv9yeVZI9yNLdJ3TI9ukVu/X0ylMrMptaIDtQumQLQuDtoxM3FgXz Lc37HwICTTSkOG/94/rQLMm0DczLi0PHf04= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1683649949158100005 Content-Type: text/plain; charset="utf-8" Clean up error handling using cascading labels + goto. (port of commit 379b179 + bcab714) Cc: Jian J Wang Cc: Liming Gao Cc: Hao A Wu Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Pedro Falcato Reviewed-by: Hao A Wu Reviewed-by: Laszlo Ersek --- .../Pci/SataControllerDxe/SataController.c | 80 ++++++++----------- 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c b/MdeM= odulePkg/Bus/Pci/SataControllerDxe/SataController.c index f661efaec7e9..d67a3e69f649 100644 --- a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c +++ b/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c @@ -375,8 +375,7 @@ SataControllerStart ( EFI_OPEN_PROTOCOL_BY_DRIVER ); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "SataControllerStart error. return status =3D %r\= n", Status)); - return Status; + goto Bail; } =20 // @@ -385,7 +384,7 @@ SataControllerStart ( Private =3D AllocateZeroPool (sizeof (EFI_SATA_CONTROLLER_PRIVATE_DATA)); if (Private =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; - goto Done; + goto ClosePciIo; } =20 // @@ -412,7 +411,7 @@ SataControllerStart ( &Private->OriginalPciAttributes ); if (EFI_ERROR (Status)) { - goto Done; + goto FreeSataPrivate; } =20 DEBUG (( @@ -428,7 +427,7 @@ SataControllerStart ( &Supports ); if (EFI_ERROR (Status)) { - goto Done; + goto FreeSataPrivate; } =20 DEBUG ((DEBUG_INFO, "Supported PCI Attributes =3D 0x%llx\n", Supports)); @@ -441,7 +440,7 @@ SataControllerStart ( NULL ); if (EFI_ERROR (Status)) { - goto Done; + goto FreeSataPrivate; } =20 DEBUG ((DEBUG_INFO, "Enabled PCI Attributes =3D 0x%llx\n", Supports)); @@ -456,7 +455,7 @@ SataControllerStart ( ); if (EFI_ERROR (Status)) { ASSERT (FALSE); - goto Done; + goto RestorePciAttributes; } =20 if (IS_PCI_IDE (&PciData)) { @@ -470,7 +469,7 @@ SataControllerStart ( DEBUG ((DEBUG_INFO, "Ports Implemented(PI) =3D 0x%x\n", Data32)); if (Data32 =3D=3D 0) { Status =3D EFI_UNSUPPORTED; - goto Done; + goto RestorePciAttributes; } =20 MaxPortNumber =3D 31; @@ -502,19 +501,19 @@ SataControllerStart ( Private->DisqualifiedModes =3D AllocateZeroPool ((sizeof (EFI_ATA_COLLEC= TIVE_MODE)) * TotalCount); if (Private->DisqualifiedModes =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; - goto Done; + goto RestorePciAttributes; } =20 Private->IdentifyData =3D AllocateZeroPool ((sizeof (EFI_IDENTIFY_DATA))= * TotalCount); if (Private->IdentifyData =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; - goto Done; + goto FreeDisqualifiedModes; } =20 Private->IdentifyValid =3D AllocateZeroPool ((sizeof (BOOLEAN)) * TotalC= ount); if (Private->IdentifyValid =3D=3D NULL) { Status =3D EFI_OUT_OF_RESOURCES; - goto Done; + goto FreeIdentifyData; } =20 // @@ -527,46 +526,37 @@ SataControllerStart ( NULL ); =20 -Done: if (EFI_ERROR (Status)) { - gBS->CloseProtocol ( - Controller, - &gEfiPciIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); - if (Private !=3D NULL) { - if (Private->DisqualifiedModes !=3D NULL) { - FreePool (Private->DisqualifiedModes); - } - - if (Private->IdentifyData !=3D NULL) { - FreePool (Private->IdentifyData); - } - - if (Private->IdentifyValid !=3D NULL) { - FreePool (Private->IdentifyValid); - } - - if (Private->PciAttributesChanged) { - // - // Restore original PCI attributes - // - PciIo->Attributes ( - PciIo, - EfiPciIoAttributeOperationSet, - Private->OriginalPciAttributes, - NULL - ); - } - - FreePool (Private); - } + goto FreeIdentifyValid; } =20 DEBUG ((DEBUG_INFO, "SataControllerStart end with %r\n", Status)); =20 return Status; + +FreeIdentifyValid: + FreePool (Private->IdentifyValid); +FreeIdentifyData: + FreePool (Private->IdentifyData); +FreeDisqualifiedModes: + FreePool (Private->DisqualifiedModes); +RestorePciAttributes: + // + // Restore original PCI attributes + // + Private->PciIo->Attributes ( + Private->PciIo, + EfiPciIoAttributeOperationSet, + Private->OriginalPciAttributes, + NULL + ); +FreeSataPrivate: + FreePool (Private); +ClosePciIo: + gBS->CloseProtocol (Controller, &gEfiPciIoProtocolGuid, This->DriverBind= ingHandle, Controller); +Bail: + DEBUG ((DEBUG_ERROR, "SataControllerStart error return status =3D %r\n",= Status)); + return Status; } =20 /** --=20 2.40.1 -=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 (#104406): https://edk2.groups.io/g/devel/message/104406 Mute This Topic: https://groups.io/mt/98787854/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-