From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::443; helo=mail-wr1-x443.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0BEBF211575F2 for ; Tue, 6 Nov 2018 04:07:36 -0800 (PST) Received: by mail-wr1-x443.google.com with SMTP id j17-v6so8056948wrq.11 for ; Tue, 06 Nov 2018 04:07:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=dQmmDDv6ILz1siqSMVftNr1+spOzS8VXlyKxvw5Q5xU=; b=MCa7thNLMtcJbJcz5awlN09YdfA0hWp/p7QWSLaWdrXLxhn9xWoniphjYZSlA4Pr+W GbFlXG5BifTp07R0tLX2auwK1lRPWi2AYALs5MLJFJKPUFwYZZQDT/vJfvIt+7hUJz/o kJvTt4if33BCzXI8yQ/u8OuE68qz/XH7xVNB0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=dQmmDDv6ILz1siqSMVftNr1+spOzS8VXlyKxvw5Q5xU=; b=hRgoEvhVcDmT9OrxLkiG0hXDhL88ewQwcHXDPp+4yVbBWJmp65FoD+WW0Yy9G/bLhJ 18llFJL9xdCJXR2p7s/G64H7MtH4Ns7dp9VB7wqU17GrwzpXIOgKMIlA0hHRmQpm5Afb JMKdKK1rG6Zl6OLLhHS0qkwClOeXwezxWDJKkDgGtguP5KrPl4ecCY4GR9L1GRAUjHBP pV+QH1hXIGNpmnQT1IjZRlDOf296YVe51LTANH/HvdIWHX6KWBHeAwfEWpBteIZp92Fm Jm2TDuRuXurO8mk/bDVLAKiHYlevkD3lQ/OGhL55TTrPbCKq2zQj0sb9pnXzeba2SVFz Cmug== X-Gm-Message-State: AGRZ1gIIxKN5Po2u+Syb+RQbvlMJ1tlUYZpd6YNYYudRUhSLr4o0TpGO Uudm4GEylxQU5szcUF7oWJF39mBRc8Y= X-Google-Smtp-Source: AJdET5fR4Mygy0uc5/rk1PnXI0Xtlas/iEhG2d2xvMcWia9knxfkX6E5IrhOebO3pH4+12PfTSm6qQ== X-Received: by 2002:adf:c550:: with SMTP id s16-v6mr22900099wrf.264.1541506055074; Tue, 06 Nov 2018 04:07:35 -0800 (PST) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id v2-v6sm16216001wru.20.2018.11.06.04.07.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 04:07:33 -0800 (PST) Date: Tue, 6 Nov 2018 12:07:32 +0000 From: Leif Lindholm To: Jian J Wang Cc: edk2-devel@lists.01.org, Ruiyu Ni , Jiewen Yao , Star Zeng Message-ID: <20181106120732.kry6j534ovmo7xlj@bivouac.eciton.net> References: <20181103064221.4764-1-jian.j.wang@intel.com> <20181103064221.4764-2-jian.j.wang@intel.com> MIME-Version: 1.0 In-Reply-To: <20181103064221.4764-2-jian.j.wang@intel.com> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH 1/2] MdeModulePkg/Core: fill logic hole in MemoryProtectionCpuArchProtocolNotify X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Nov 2018 12:07:37 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Nov 03, 2018 at 02:42:20PM +0800, Jian J Wang wrote: > At the end of of MemoryProtectionCpuArchProtocolNotify there's cleanup > code to free resource. But at line 978, 994, 1005 the function returns > directly. This patch use "goto" to replace "return" to make sure the > resource is freed before exit. > > 1029: CoreCloseEvent (Event); > 1030: return; > > Cc: Star Zeng > Cc: Jiewen Yao > Cc: Ruiyu Ni > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jian J Wang > --- > MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 42 +++++++++++++-------------- > 1 file changed, 21 insertions(+), 21 deletions(-) > > diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c > index 6298b67db1..30e5c5153c 100644 > --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c > +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c > @@ -975,7 +975,7 @@ MemoryProtectionCpuArchProtocolNotify ( > DEBUG ((DEBUG_INFO, "MemoryProtectionCpuArchProtocolNotify:\n")); > Status = CoreLocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&gCpu); > if (EFI_ERROR (Status)) { > - return; > + goto Done; > } > > // > @@ -991,7 +991,7 @@ MemoryProtectionCpuArchProtocolNotify ( > HeapGuardCpuArchProtocolNotify (); > > if (mImageProtectionPolicy == 0) { > - return; > + goto Done; > } > > Status = gBS->LocateHandleBuffer ( > @@ -1002,7 +1002,7 @@ MemoryProtectionCpuArchProtocolNotify ( > &HandleBuffer > ); > if (EFI_ERROR (Status) && (NoHandles == 0)) { > - return ; > + goto Done; > } > > for (Index = 0; Index < NoHandles; Index++) { > @@ -1026,8 +1026,8 @@ MemoryProtectionCpuArchProtocolNotify ( > ProtectUefiImage (LoadedImage, LoadedImageDevicePath); > } > > +Done: > CoreCloseEvent (Event); > - return; > } > > /** I have no comments on the bits above, but everything below here looks like it's only ruining the indentation without any functional changes at all. / Leif > @@ -1136,24 +1136,24 @@ CoreInitializeMemoryProtection ( > GetPermissionAttributeForMemoryType (EfiConventionalMemory)); > > if (mImageProtectionPolicy != 0 || PcdGet64 (PcdDxeNxMemoryProtectionPolicy) != 0) { > - Status = CoreCreateEvent ( > - EVT_NOTIFY_SIGNAL, > - TPL_CALLBACK, > - MemoryProtectionCpuArchProtocolNotify, > - NULL, > - &Event > - ); > - ASSERT_EFI_ERROR(Status); > + Status = CoreCreateEvent ( > + EVT_NOTIFY_SIGNAL, > + TPL_CALLBACK, > + MemoryProtectionCpuArchProtocolNotify, > + NULL, > + &Event > + ); > + ASSERT_EFI_ERROR(Status); > > - // > - // Register for protocol notifactions on this event > - // > - Status = CoreRegisterProtocolNotify ( > - &gEfiCpuArchProtocolGuid, > - Event, > - &Registration > - ); > - ASSERT_EFI_ERROR(Status); > + // > + // Register for protocol notifactions on this event > + // > + Status = CoreRegisterProtocolNotify ( > + &gEfiCpuArchProtocolGuid, > + Event, > + &Registration > + ); > + ASSERT_EFI_ERROR(Status); > } > > // > -- > 2.16.2.windows.1 > > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel