From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@gmail.com header.s=20221208 header.b=W9RFddWa; spf=pass (domain: gmail.com, ip: 209.85.128.52, mailfrom: pedro.falcato@gmail.com) Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-3f195b164c4so40564965e9.1 for ; Tue, 09 May 2023 09:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683649945; x=1686241945; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zYJJ+ptXjIaAdasd8Pk7411yHryCinFyGJ5/BkURyMo=; b=W9RFddWa/ts6Kxj96rkFjV6AeguosYOuc79e2EZaIRZWwTyCe38/ukLImnNfSdhD6D YHT3YTedkIoTdhhhqhFQH/Ipxq0mypjHFDUr+i9Pk6JQG2PDyZHV5SgvOI2si5r/KqQI L4/Rs1onnEbDREmnEJNKZqBUSwQ2evqksDptJVaCnBWfDpL3RQhzJg3rziqTz2v2oXIT TZ0cnuBe1Mkrecdd5CvgaECCvbJ8yh9HXGQxFzpGA9bTW0zvOLqpb+EKsNZu1wfj5xLz uJz2mjQ0E++4bJzp5SRcAzS3tvGdC202LR2zqFWG2ntFPh5Rs8WY75nIwB+AqPz7LkLb nm+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683649945; x=1686241945; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zYJJ+ptXjIaAdasd8Pk7411yHryCinFyGJ5/BkURyMo=; b=YIgKAcMSOt58LEOKUPbXNdXaIG9rg3JbKNiqL1t+UPf7a8rO6pmvS+4tXJdzHaxDes GAGbDF+RU3J5FAgQaywvoVWUTX7PqFeOrgaLRf9B0oHrq8nfSh7EBLu0iviYpXSIonps qq+OJaQZWpPzCAm/+K68+TgQcE0hsupZMSwkz5rMlw2RcshakZC3xIRPzeVCs5zvcAWU 9N0TjzqmAcmOnboDWRE884i5c/T938/nGxJVGMIbGjhz3kRPurkrZdaO/q/1Lw7IYJxq JPE4oAnSYBtep8/OGcZs2ev02Zii2aTVOD0MObVupswfBTxyPv2PXY0Fuuzk9D6ohKmK JHdA== X-Gm-Message-State: AC+VfDwDvnPti5A7eAp5MY4Rc9whONUVxcKKv+G2k6AxKI7SInOco4S7 HYhmftb+cd5ln0QjWJRSgnkWC1i68zL9ex5T 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230509163212.291333-1-pedro.falcato@gmail.com> References: <20230509163212.291333-1-pedro.falcato@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- .../Pci/SataControllerDxe/SataController.c | 80 ++++++++----------- 1 file changed, 35 insertions(+), 45 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/SataControllerDxe/SataController.c b/MdeModulePkg/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 = %r\n", Status)); - return Status; + goto Bail; } // @@ -385,7 +384,7 @@ SataControllerStart ( Private = AllocateZeroPool (sizeof (EFI_SATA_CONTROLLER_PRIVATE_DATA)); if (Private == NULL) { Status = EFI_OUT_OF_RESOURCES; - goto Done; + goto ClosePciIo; } // @@ -412,7 +411,7 @@ SataControllerStart ( &Private->OriginalPciAttributes ); if (EFI_ERROR (Status)) { - goto Done; + goto FreeSataPrivate; } DEBUG (( @@ -428,7 +427,7 @@ SataControllerStart ( &Supports ); if (EFI_ERROR (Status)) { - goto Done; + goto FreeSataPrivate; } DEBUG ((DEBUG_INFO, "Supported PCI Attributes = 0x%llx\n", Supports)); @@ -441,7 +440,7 @@ SataControllerStart ( NULL ); if (EFI_ERROR (Status)) { - goto Done; + goto FreeSataPrivate; } DEBUG ((DEBUG_INFO, "Enabled PCI Attributes = 0x%llx\n", Supports)); @@ -456,7 +455,7 @@ SataControllerStart ( ); if (EFI_ERROR (Status)) { ASSERT (FALSE); - goto Done; + goto RestorePciAttributes; } if (IS_PCI_IDE (&PciData)) { @@ -470,7 +469,7 @@ SataControllerStart ( DEBUG ((DEBUG_INFO, "Ports Implemented(PI) = 0x%x\n", Data32)); if (Data32 == 0) { Status = EFI_UNSUPPORTED; - goto Done; + goto RestorePciAttributes; } MaxPortNumber = 31; @@ -502,19 +501,19 @@ SataControllerStart ( Private->DisqualifiedModes = AllocateZeroPool ((sizeof (EFI_ATA_COLLECTIVE_MODE)) * TotalCount); if (Private->DisqualifiedModes == NULL) { Status = EFI_OUT_OF_RESOURCES; - goto Done; + goto RestorePciAttributes; } Private->IdentifyData = AllocateZeroPool ((sizeof (EFI_IDENTIFY_DATA)) * TotalCount); if (Private->IdentifyData == NULL) { Status = EFI_OUT_OF_RESOURCES; - goto Done; + goto FreeDisqualifiedModes; } Private->IdentifyValid = AllocateZeroPool ((sizeof (BOOLEAN)) * TotalCount); if (Private->IdentifyValid == NULL) { Status = EFI_OUT_OF_RESOURCES; - goto Done; + goto FreeIdentifyData; } // @@ -527,46 +526,37 @@ SataControllerStart ( NULL ); -Done: if (EFI_ERROR (Status)) { - gBS->CloseProtocol ( - Controller, - &gEfiPciIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); - if (Private != NULL) { - if (Private->DisqualifiedModes != NULL) { - FreePool (Private->DisqualifiedModes); - } - - if (Private->IdentifyData != NULL) { - FreePool (Private->IdentifyData); - } - - if (Private->IdentifyValid != NULL) { - FreePool (Private->IdentifyValid); - } - - if (Private->PciAttributesChanged) { - // - // Restore original PCI attributes - // - PciIo->Attributes ( - PciIo, - EfiPciIoAttributeOperationSet, - Private->OriginalPciAttributes, - NULL - ); - } - - FreePool (Private); - } + goto FreeIdentifyValid; } DEBUG ((DEBUG_INFO, "SataControllerStart end with %r\n", Status)); 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->DriverBindingHandle, Controller); +Bail: + DEBUG ((DEBUG_ERROR, "SataControllerStart error return status = %r\n", Status)); + return Status; } /** -- 2.40.1