From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by mx.groups.io with SMTP id smtpd.web11.644.1685640484136160635 for ; Thu, 01 Jun 2023 10:28:04 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@gmail.com header.s=20221208 header.b=er/SyKA7; spf=pass (domain: gmail.com, ip: 209.85.128.48, mailfrom: pedro.falcato@gmail.com) Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-3f6d01d390bso11755735e9.2 for ; Thu, 01 Jun 2023 10:28:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685640482; x=1688232482; 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=XEit+sIXe5KU/uPBGKL3iezUwc0kBXk/3F+pJOycnxw=; b=er/SyKA7XlA/OqCOoVUSCP8jXCv2twkmKdiuZ7SmKtGg77cYbXbkRuyc960RRbBFsY JBkMLfiLZruhL12Y1I8aqObAvLHzBXzUAuXkPoVsNOJg3i6j/EPj3rotFMrk7KOLgWPr Vq/kuIb1MUWloCbEhDZSwq49ELhEfjjpq6JeRLPLP7zDfyyRYb5S7qVI8THxefmntELu mRp20OOrPLxAyJ93PAnRVRyPeaqgK6q60tyDQvRaExGQgaGNNHPUtgMQK3t7Kt33dJv4 JDabU713HjxLEgnwAtng02EFguUQhuOvWnwynAlnSlf9RAKTZ5fT1pqioq/fR+jIRI/o 6xgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685640482; x=1688232482; 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=XEit+sIXe5KU/uPBGKL3iezUwc0kBXk/3F+pJOycnxw=; b=DuS5vpnOzNm9nzHA2sReJpHkiB2lgBMp+iZyjwFndrJ3j6iC0i1bwHjSJrWmAJ+/Sm UYGm5infm6Q9hFArnBkyV//ZDASXIvw50U7xLY+FgW9zKUjXDC8WtzUheKDne47W20rL mdOppCnkNlcXaWn8vzIIhyXBc2Uby4d+TsX4Xf7o+lejvVQbKUPxa7DmSyaiZ/HywAFM T+Vr/PtJ9T5JYMuIDiCbdNVVAJ4By8k26MsBjDZD+bbm41s54ek8Juv4ZcO7ORUDiKFQ wI2cZlz5n+OI6ANhff3x8fk2VoxhpWWrdNVEwdRw490QduTctlVaLDOIb1EcieBHKkxe pJsw== X-Gm-Message-State: AC+VfDzG/laipr0AUTKCpVBaVVy2hfjWomHN531pT/ka1hfdSe1uPTp2 wVCVj5pg+sBDbQDcrDIDdi5KZ6tboZjJqQ== X-Google-Smtp-Source: ACHHUZ4RHdWIQlphArvqWBh9uYAM8fTJ1+0xFwxmCKIGzHleD68GwGuFa5obRJ06k8yrDZBZPPH96g== X-Received: by 2002:a1c:f709:0:b0:3f6:143:7c4b with SMTP id v9-20020a1cf709000000b003f601437c4bmr124854wmh.6.1685640482072; Thu, 01 Jun 2023 10:28:02 -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 n11-20020a7bcbcb000000b003f60d0eef36sm2970511wmi.48.2023.06.01.10.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 10:28:01 -0700 (PDT) From: "Pedro Falcato" To: devel@edk2.groups.io Cc: Pedro Falcato , Jian J Wang , Liming Gao , Hao A Wu , Ray Ni , Laszlo Ersek Subject: [PATCH v3 01/12] MdeModulePkg/SataControllerDxe: Clean up error handling in Start() Date: Thu, 1 Jun 2023 18:27:29 +0100 Message-Id: <20230601172740.9165-2-pedro.falcato@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230601172740.9165-1-pedro.falcato@gmail.com> References: <20230601172740.9165-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 Reviewed-by: Laszlo Ersek Reviewed-by: Hao A Wu --- .../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