From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web10.14189.1683855370298053228 for ; Thu, 11 May 2023 18:36:10 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=Ousc5iEb; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: hao.a.wu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683855370; x=1715391370; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=yGspeHo5yfdE3XLWLgt05xaQ146n0aw+gJL50GAuHxo=; b=Ousc5iEbi2jUWAQzM0jrPJQZascsMXrVDV1GUnl1ABlQ419Ez181mpAz PpC+bfR4Lgprm3+Z7jLWIN0KwFg1zgIFGagnqgnux6UohV+CzWlN/mmbh T006zFhYr8F14to4rimV2FJowERR1EM7aYLyrdyqE2YgqaMMUajmJbmrV Y8sSWtLBC7baP67e3NGQ1U6upRmmpFoBQNVQjx+GSN5Yd5wVOrgHJYpwt beWMmkOuivgiC8AgUuN9jBkLkCGPuQ1NkT6GtGLyL4bHhJ9HSaLjpzGrZ RrHbpQ26hyOhpPIaRLNprZ+L+R41hSLDNlNVM/fGsbrRc2QjDFqTd2gc0 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10707"; a="331040952" X-IronPort-AV: E=Sophos;i="5.99,268,1677571200"; d="scan'208";a="331040952" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 May 2023 18:35:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10707"; a="946422846" X-IronPort-AV: E=Sophos;i="5.99,269,1677571200"; d="scan'208";a="946422846" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by fmsmga006.fm.intel.com with ESMTP; 11 May 2023 18:35:48 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 11 May 2023 18:35:48 -0700 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 11 May 2023 18:35:48 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Thu, 11 May 2023 18:35:48 -0700 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (104.47.55.174) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Thu, 11 May 2023 18:35:47 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eQmQ+xx27+oVRGemlo4P2NKqTUlXAkl8KMysCEm6MSwMp/6yr9k0CWXZltKl9KRfKFXRtTKH7MhSvMQYiMbbBHD7z4Sfp50uaKIMbIHS9FqNULDofKIRbYg6sfohg587rru/b45J+ld33AuOnS5WHsLrtn+ZAYj/OOICP9J+psXj1IuhF5u1wz0MQLMIvx8XlANP9qoedq94/T+Lpmn6cLHRt32lSodeTopAwNSUauZWHsS9ATMs5pbMp871ge7sqecwZEXw3nsLCRU+QanD4bftYK2PbAE1dqlkLCO6aAtwwMf7LSP/zIRbY3QJvDq2FVTwY1FMClA/uXwEURjnFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=66TvFWT7VI6J71+tbsFVPnrfJVoWrT/z2o69FDmKeL4=; b=XggzFliTE7R+0LnTvwJXN6d3FL+7MY9iDiyrEH+H8Q4L7rmmY79q8C4F0YHQadk0AHIOIU1bzBn+AwcsCWxVgQ7HSyoe7VFkU86onFtS9k8EmNZanlX0xUvjBVmqSOoQfrNil8XwH8Pz/4H6ESbcIbkSl1Sp/i43F3IDnYZGzT7hRVFv8ZqWLw5j/8s4fF+LIiB0MsZz6RIIJ4KBvCPvIi+nLk5SKfUVzTRPTlAW0o00T3IAyInnU/O195HzSrxyUE4J9OkggCggYsihNNpi6W6xeEsxPB7PODiSoer1m4KHh4Lp9AyGRdaBDSGeK05BeUqooHyc/5sN1ybejFVMwQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MN2PR11MB4031.namprd11.prod.outlook.com (2603:10b6:208:150::18) by CY5PR11MB6137.namprd11.prod.outlook.com (2603:10b6:930:2b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.33; Fri, 12 May 2023 01:35:43 +0000 Received: from MN2PR11MB4031.namprd11.prod.outlook.com ([fe80::938:1dcf:6071:ef90]) by MN2PR11MB4031.namprd11.prod.outlook.com ([fe80::938:1dcf:6071:ef90%6]) with mapi id 15.20.6387.022; Fri, 12 May 2023 01:35:42 +0000 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "pedro.falcato@gmail.com" CC: Laszlo Ersek , "Wang, Jian J" , "Gao, Liming" , "Ni, Ray" Subject: Re: [edk2-devel] [PATCH v2 01/12] MdeModulePkg/SataControllerDxe: Clean up error handling in Start() Thread-Topic: [edk2-devel] [PATCH v2 01/12] MdeModulePkg/SataControllerDxe: Clean up error handling in Start() Thread-Index: AQHZgpPe/GTw58meLkCpHAI6Gz8kS69V2+pw Date: Fri, 12 May 2023 01:35:40 +0000 Message-ID: References: <20230509163212.291333-1-pedro.falcato@gmail.com> <20230509163212.291333-2-pedro.falcato@gmail.com> In-Reply-To: <20230509163212.291333-2-pedro.falcato@gmail.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN2PR11MB4031:EE_|CY5PR11MB6137:EE_ x-ms-office365-filtering-correlation-id: 1955ef52-d1c1-4e60-9044-08db5289335a x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: SkHZvnTSK7QiDKhm5+j3OSp9ymfJgA7v5V+1eLBiiWmGcYqE+6djQOENVX/9sUjkep2D+p1v984llsF1b48qiePteQB9ek0pO9Zf5Y24xb77ygWTW7SxuNaTOAktdlS02h/shwez5mjQvWgldGU/ylMgRbX2WT+HhLWukFJOKK4YhS3gMpyfGAx9THan/yIN6fc8XXCEWT+SnSOJ9VnJYa/jUaT+RWb8Kfquwu8L9ZD1p9KUsvT+3uTZ3IZWX9FYtDqttDnGbCxFvkkcMDVuQ0YsbE/DdP6nE+fY0aKYsY/uDZBwEYEjGENkbfItE6vQRZNGWsh6qQvdJ47V8P+xGZvpzcNBV319JYeJEBtKo8uwOntfzIW21XxJ4fMGsCDk04sB4h6YKJj/r4s2ssI4JMHLciUtorELQz7uX1jd6yNzTqg/Pr5LhlR114szGOzDsXwO+iKq6hqLPIW+05mv1OcbOnKg2g3/VfzMophfCBLhMhHh3thKhmUxjvv3Kduunc6O8ocaJvdHMM3IeSvtGbZZURpoWm2TNM3GpMHvDcVH+0lY8uvs+SxdZQpnayWhnq0iJaW5zZXEQ8/ZLxcX/NJRRkjBW6Zes/BGLmc603Fo3TWABkNdHfWMOg+c060TNFy38M19u0sOwDqVPtI0Qg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR11MB4031.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(346002)(136003)(376002)(396003)(366004)(39860400002)(451199021)(4326008)(54906003)(86362001)(66946007)(64756008)(66476007)(66556008)(55016003)(76116006)(66446008)(7696005)(8676002)(9686003)(41300700001)(33656002)(38100700002)(53546011)(6506007)(107886003)(186003)(2906002)(8936002)(52536014)(966005)(478600001)(38070700005)(71200400001)(5660300002)(316002)(82960400001)(83380400001)(122000001)(110136005)(66899021);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?i5ZjKow5FqguJZYe7VqAVi5DJVnPjvMqekRh/3Ztm6vivDOk3F49onBAzvSL?= =?us-ascii?Q?2ny3Fn0KtvtLwprtl0wN1XjBmK8ELQNEDch6QjldCirZWxk5h86pffUDeAH7?= =?us-ascii?Q?1WJdy9Imb6jL+K+8VuEQsmLCUEGO5QZPso4qJ9OgnFC5u+f2mCp/voJAny8P?= =?us-ascii?Q?W4aktB2Dchv40/nj7AfXL+VMh7X2aLzQ4eN53PLTnHvoQrUwzPWIqHI9RNJb?= =?us-ascii?Q?fWWHxs2qudbVRoRrBSu3mD5/wilJBlSj5KtUnm1eJ3JttFJ75sahABWq0sWy?= =?us-ascii?Q?DkCRHT6he2bK1HqjuNsk/hNX3TFp6mWqhFgA+6cf3yS2CpbLtk7ZNLJll+So?= =?us-ascii?Q?7ioSzpjJJjWw3UXEtxIt5EqzRmJCveDxlJ+IPbiFJzcnouH+lcse6XrPbbsh?= =?us-ascii?Q?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UFATIGqWb9gbgzlTeDnrI?= =?us-ascii?Q?UZrxXlvXGoggc7hwoduaZSDVh8rJSAe9kAZtytPtZcrsYATQ+afocCzfhgZt?= =?us-ascii?Q?pwMWlL4B2QML/1ii5Y34l3BXNLNclyzLRYJ7OQ6AK+OOrt/2RUmqLqqpzRPn?= =?us-ascii?Q?uZS67QdijJRIJUxuTIdpkZur7Gj39B5gBc9RTDqGhetMJWU2AjglbLDml60U?= =?us-ascii?Q?oseUFatKbE9xJrtQlWo0rDmx5g+WdLvXahuIGFf9psouajSrKIeNPfRAPg?= =?us-ascii?Q?=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN2PR11MB4031.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1955ef52-d1c1-4e60-9044-08db5289335a X-MS-Exchange-CrossTenant-originalarrivaltime: 12 May 2023 01:35:40.8919 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: G31vDC4ZrLxAxzIRkzMov1eMfq8Jn6tGEmqMulXomXpPmisMDaOm0huDgDlWpM03Qp/6A23UY4aWuPY3yL/zZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR11MB6137 Return-Path: hao.a.wu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Hao A Wu Best Regards, Hao Wu > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Pedro > Falcato > Sent: Wednesday, May 10, 2023 12:32 AM > To: devel@edk2.groups.io > Cc: Laszlo Ersek ; Pedro Falcato > ; Wang, Jian J ; Gao, > Liming ; Wu, Hao A ; Ni, > Ray > Subject: [edk2-devel] [PATCH v2 01/12] MdeModulePkg/SataControllerDxe: > Clean up error handling in Start() >=20 > Clean up error handling using cascading labels + goto. >=20 > (port of commit 379b179 + bcab714) >=20 > 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(-) >=20 > 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 =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_COLLECTIVE_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)) * Tota= lCount); > 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- > >DriverBindingHandle, Controller); > +Bail: > + DEBUG ((DEBUG_ERROR, "SataControllerStart error return status =3D %r\n= ", > Status)); > + return Status; > } >=20 > /** > -- > 2.40.1 >=20 >=20 >=20 >=20 >=20