From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:400c:c09::229; helo=mail-wm0-x229.google.com; envelope-from=leif.lindholm@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wm0-x229.google.com (mail-wm0-x229.google.com [IPv6:2a00:1450:400c:c09::229]) (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 801E621F3884B for ; Thu, 12 Oct 2017 12:29:29 -0700 (PDT) Received: by mail-wm0-x229.google.com with SMTP id k4so16117299wmc.1 for ; Thu, 12 Oct 2017 12:33:00 -0700 (PDT) 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=gC5FoSEAkDarULUc5/IYyemZZ1c2/it2CLlH8RBxST0=; b=KG1bYAH1bl3Y25sXmdF9p/6Fz9/9CWVsgHtAxgHdnoZ7/uiWm6k71ZEuGurC2Gn0RU clcLVru/YxLOQ3FcUTsyesRBYSdeh776HnaVE3Ie7fAkjo8+RvRl8zyN/37eQUx4VUKB MWNk9lL0KlKRHWUiHl59VdOr7j7MlK6QeTeHI= 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=gC5FoSEAkDarULUc5/IYyemZZ1c2/it2CLlH8RBxST0=; b=SR+QVePEE1kHtLuglENn6MW8S7IE9Hda3l4lNiLSfnhvcXoD7CdfW73O0Q+986o/CM efAGT9u2O0rO3omdNasINJxoJkUyHEoOrvGyKqsv5CyDVeCVTIs/4ndowpZKUkS8vtSe vkLKIWx6PBUk06Sca+dTjqwxLdkPdpvkzCVVHMvfBczx8FIEMOfHsRtCM7ML2UzjhYkt 3wMcbMe+TE7MFNkUcAe35cvOeJrlqHINk3T4jVpd+0FVCIzJ93wbdZ0c17UAQ4QxRV8+ E0KHLJ8kDsB8bWzpXXalk2ncJWxoSYIkOZbLp+4ip0anojDbiVU7oT4dcB9/BAuo19sa LSRg== X-Gm-Message-State: AMCzsaUosiwVX/uXVNxWOw+3OpAYUYxsPaOcyu1kLm1x2mT6wIuhlmms 2XTPsJh1qSjAoUx2+HqKsHeo/A== X-Google-Smtp-Source: AOwi7QByVtF/Z5V8ToL0skG0GQLmnKjfWaGx3Ru4sc0JJtnarfCx7TcRpdsumS0RNsVywWI+Z8IgJQ== X-Received: by 10.28.126.196 with SMTP id z187mr2553394wmc.69.1507836778423; Thu, 12 Oct 2017 12:32:58 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id b16sm5733058wrg.95.2017.10.12.12.32.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Oct 2017 12:32:57 -0700 (PDT) Date: Thu, 12 Oct 2017 20:32:55 +0100 From: Leif Lindholm To: evan.lloyd@arm.com Cc: edk2-devel@lists.01.org Message-ID: <20171012193255.kx5w4axzempq66s4@bivouac.eciton.net> References: <20170926201529.11644-1-evan.lloyd@arm.com> <20170926201529.11644-5-evan.lloyd@arm.com> MIME-Version: 1.0 In-Reply-To: <20170926201529.11644-5-evan.lloyd@arm.com> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH 04/19] ArmPlatformPkg: LcdGraphicsOurputDxe: Add debug asserts X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Oct 2017 19:29:30 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Sep 26, 2017 at 09:15:14PM +0100, evan.lloyd@arm.com wrote: > From: Girish Pathak > > This change adds some debug assertions e.g to catch NULL pointer errors > missing in PL11Lcd and HdLcd modules. > > This change also improves related error handling code. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Girish Pathak > Signed-off-by: Evan Lloyd > --- > ArmPlatformPkg/ArmVExpressPkg/Library/HdLcdArmVExpressLib/HdLcdArmVExpress.c | 44 ++++++++++++++++++-- > ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpress.c | 43 ++++++++++++++++++- > ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/HdLcd.c | 8 ++-- > ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111Lcd.c | 8 ++-- > 4 files changed, 90 insertions(+), 13 deletions(-) > > diff --git a/ArmPlatformPkg/ArmVExpressPkg/Library/HdLcdArmVExpressLib/HdLcdArmVExpress.c b/ArmPlatformPkg/ArmVExpressPkg/Library/HdLcdArmVExpressLib/HdLcdArmVExpress.c > index b9859a56988f7e5be0adbaa49048a683fe586bfe..58dd9f0c77e1bc9af559a71d0c7cce72d71c6da5 100644 > --- a/ArmPlatformPkg/ArmVExpressPkg/Library/HdLcdArmVExpressLib/HdLcdArmVExpress.c > +++ b/ArmPlatformPkg/ArmVExpressPkg/Library/HdLcdArmVExpressLib/HdLcdArmVExpress.c > @@ -140,6 +140,7 @@ LcdPlatformInitializeDisplay ( > * buffer in bytes > * > * @retval EFI_SUCCESS Frame buffer memory allocation success. > + * @retval EFI_INVALID_PARAMETER VramBaseAddress or VramSize are NULL. > * @retval !(EFI_SUCCESS) Other errors. > **/ > EFI_STATUS > @@ -151,6 +152,13 @@ LcdPlatformGetVram ( > EFI_STATUS Status; > EFI_ALLOCATE_TYPE AllocationType; > > + // Check VramBaseAddress and VramSize are not NULL. > + if (VramBaseAddress == NULL || VramSize == NULL) { > + ASSERT (VramBaseAddress != NULL); > + ASSERT (VramSize != NULL); > + return EFI_INVALID_PARAMETER; > + } > + The above is not just a debug assertion change, it also changes behaviour for RELEASE builds. I have no objection to these changes in the same patch, but it makes the commit message misleading. Can you update that please, to say "adds debug assertions and runtime checks"? > // Set the vram size > *VramSize = LCD_VRAM_SIZE; > > @@ -169,6 +177,7 @@ LcdPlatformGetVram ( > VramBaseAddress > ); > if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > return Status; > } > > @@ -179,8 +188,8 @@ LcdPlatformGetVram ( > *VramSize, > EFI_MEMORY_WC > ); > - ASSERT_EFI_ERROR (Status); > if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); > gBS->FreePages (*VramBaseAddress, EFI_SIZE_TO_PAGES (*VramSize)); > return Status; > } > @@ -215,6 +224,7 @@ LcdPlatformSetMode ( > EFI_STATUS Status; > > if (ModeNumber >= LcdPlatformGetMaxMode ()) { > + ASSERT (ModeNumber < LcdPlatformGetMaxMode ()); Is this asserting that LcdPlatformGetMaxMode() returns the same thing if called twice? If you just always want to assert when reached, use ASSERT (FALSE). If you explicitly want the message to tell you which operation went wrong, please use a temporary variable rather than calling a function twice. > return EFI_INVALID_PARAMETER; > } > > @@ -264,6 +274,7 @@ LcdPlatformSetMode ( > * > * @retval EFI_SUCCESS Success if the requested mode is found. > * @retval EFI_INVALID_PARAMETER Requested mode not found. > + * @retval EFI_INVALID_PARAMETER Info is NULL. > **/ > EFI_STATUS > LcdPlatformQueryMode ( > @@ -271,7 +282,9 @@ LcdPlatformQueryMode ( > OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION * CONST Info > ) > { > - if (ModeNumber >= LcdPlatformGetMaxMode ()) { > + if (ModeNumber >= LcdPlatformGetMaxMode () || Info == NULL) { > + ASSERT (ModeNumber < LcdPlatformGetMaxMode ()); > + ASSERT (Info != NULL); > return EFI_INVALID_PARAMETER; > } > > @@ -334,6 +347,28 @@ LcdPlatformGetTimings ( > ) > { > if (ModeNumber >= LcdPlatformGetMaxMode ()) { > + ASSERT (ModeNumber < LcdPlatformGetMaxMode ()); ASSERT (FALSE)? Or temporary variable. > + return EFI_INVALID_PARAMETER; > + } > + > + if (HRes == NULL > + || HSync == NULL > + || HBackPorch == NULL > + || HFrontPorch == NULL > + || VRes == NULL > + || VSync == NULL > + || VBackPorch == NULL > + || VFrontPorch == NULL) > + { > + // One of the pointers is NULL > + ASSERT (HRes != NULL); > + ASSERT (HSync != NULL); > + ASSERT (HBackPorch != NULL); > + ASSERT (HFrontPorch != NULL); > + ASSERT (VRes != NULL); > + ASSERT (VSync != NULL); > + ASSERT (VBackPorch != NULL); > + ASSERT (VFrontPorch != NULL); > return EFI_INVALID_PARAMETER; > } > > @@ -356,6 +391,7 @@ LcdPlatformGetTimings ( > * > * @retval EFI_SUCCESS The requested mode is found. > * @retval EFI_INVALID_PARAMETER Requested mode not found. > + * @retval EFI_INVALID_PARAMETER Bpp is NULL. > **/ > EFI_STATUS > LcdPlatformGetBpp ( > @@ -363,7 +399,9 @@ LcdPlatformGetBpp ( > OUT LCD_BPP * CONST Bpp > ) > { > - if (ModeNumber >= LcdPlatformGetMaxMode ()) { > + if (ModeNumber >= LcdPlatformGetMaxMode () || Bpp == NULL) { > + ASSERT (ModeNumber < LcdPlatformGetMaxMode ()); > + ASSERT (Bpp != NULL); > return EFI_INVALID_PARAMETER; > } > > diff --git a/ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpress.c b/ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpress.c > index 6ae13f06d8b396ea1c67f0bcd735a9d70f476400..5a4abd4c6f9e84d3d690af7233c1cebfe1ad339b 100644 > --- a/ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpress.c > +++ b/ArmPlatformPkg/ArmVExpressPkg/Library/PL111LcdArmVExpressLib/PL111LcdArmVExpress.c > @@ -191,6 +191,7 @@ LcdPlatformInitializeDisplay ( > * buffer in bytes > * > * @retval EFI_SUCCESS Frame buffer memory allocation success. > + * @retval EFI_INVALID_PARAMETER VramBaseAddress or VramSize is NULL. > * @retval !(EFI_SUCCESS) Other errors. > **/ > EFI_STATUS > @@ -203,6 +204,13 @@ LcdPlatformGetVram ( > > Status = EFI_SUCCESS; > > + // Check VramBaseAddress and VramSize are not NULL. > + if (VramBaseAddress == NULL || VramSize == NULL) { > + ASSERT (VramBaseAddress != NULL); > + ASSERT (VramSize != NULL); > + return EFI_INVALID_PARAMETER; > + } > + > // Is it on the motherboard or on the daughterboard? > switch (PL111_CLCD_SITE) { > > @@ -223,6 +231,7 @@ LcdPlatformGetVram ( > VramBaseAddress > ); > if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); ASSERT (FALSE)? (You already know Status is an EFI_ERROR, and a console message saying ASSERT (Status) is not getting you out of looking at the source code to find out what happened.) > return Status; > } > > @@ -233,8 +242,8 @@ LcdPlatformGetVram ( > *VramSize, > EFI_MEMORY_WC > ); > - ASSERT_EFI_ERROR (Status); > if (EFI_ERROR (Status)) { > + ASSERT_EFI_ERROR (Status); ASSERT (FALSE)? > gBS->FreePages (*VramBaseAddress, EFI_SIZE_TO_PAGES (*VramSize)); > return Status; > } > @@ -293,6 +302,7 @@ LcdPlatformSetMode ( > UINT32 SysId; > > if (ModeNumber >= LcdPlatformGetMaxMode ()) { > + ASSERT (ModeNumber < LcdPlatformGetMaxMode ()); ASSERT (FALSE)? Or temporary variable? > return EFI_INVALID_PARAMETER; > } > > @@ -359,6 +369,7 @@ LcdPlatformSetMode ( > * (on success). > * > * @retval EFI_SUCCESS Success if the requested mode is found. > + * @retval EFI_INVALID_PARAMETER Info is NULL. > * @retval EFI_INVALID_PARAMETER Requested mode not found. > **/ > EFI_STATUS > @@ -367,7 +378,9 @@ LcdPlatformQueryMode ( > OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION * CONST Info > ) > { > - if (ModeNumber >= LcdPlatformGetMaxMode ()) { > + if (ModeNumber >= LcdPlatformGetMaxMode () || Info == NULL) { > + ASSERT (ModeNumber < LcdPlatformGetMaxMode ()); Temporary variable? > + ASSERT (Info != NULL); > return EFI_INVALID_PARAMETER; > } > > @@ -415,6 +428,7 @@ LcdPlatformQueryMode ( > * > * @retval EFI_SUCCESS Success if the requested mode is found. > * @retval EFI_INVALID_PARAMETER Requested mode not found. > + * @retval EFI_INVALID_PARAMETER One of the OUT parameters is NULL. > **/ > EFI_STATUS > LcdPlatformGetTimings ( > @@ -430,6 +444,28 @@ LcdPlatformGetTimings ( > ) > { > if (ModeNumber >= LcdPlatformGetMaxMode ()) { > + ASSERT (ModeNumber < LcdPlatformGetMaxMode ()); > + return EFI_INVALID_PARAMETER; > + } > + > + if (HRes == NULL > + || HSync == NULL > + || HBackPorch == NULL > + || HFrontPorch == NULL > + || VRes == NULL > + || VSync == NULL > + || VBackPorch == NULL > + || VFrontPorch == NULL) > + { > + // One of the pointers is NULL > + ASSERT (HRes != NULL); > + ASSERT (HSync != NULL); > + ASSERT (HBackPorch != NULL); > + ASSERT (HFrontPorch != NULL); > + ASSERT (VRes != NULL); > + ASSERT (VSync != NULL); > + ASSERT (VBackPorch != NULL); > + ASSERT (VFrontPorch != NULL); > return EFI_INVALID_PARAMETER; > } > > @@ -452,6 +488,7 @@ LcdPlatformGetTimings ( > * > * @retval EFI_SUCCESS The requested mode is found. > * @retval EFI_INVALID_PARAMETER Requested mode not found. > + * @retval EFI_INVALID_PARAMETER Bpp is NULL. > **/ > EFI_STATUS > LcdPlatformGetBpp ( > @@ -460,6 +497,8 @@ LcdPlatformGetBpp ( > ) > { > if (ModeNumber >= LcdPlatformGetMaxMode ()) { > + ASSERT (ModeNumber < LcdPlatformGetMaxMode ()); > + ASSERT (Bpp != NULL); > return EFI_INVALID_PARAMETER; > } > > diff --git a/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/HdLcd.c b/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/HdLcd.c > index 5f950579720fb69e0a481f697a5cc4038158b409..a266671a26f01d31e8ddb0cf7cbfe59d2f4dc49c 100644 > --- a/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/HdLcd.c > +++ b/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/HdLcd.c > @@ -109,15 +109,15 @@ LcdSetMode ( > &VBackPorch, > &VFrontPorch > ); > - ASSERT_EFI_ERROR (Status); > if (EFI_ERROR (Status)) { > - return EFI_DEVICE_ERROR; > + ASSERT_EFI_ERROR (Status); ASSERT (FALSE). > + return Status; This is a change in behaviour, since the function can now potentially return other values than it has in the past. Again, it may be fine, but deserves a mention in the commit message. > } > > Status = LcdPlatformGetBpp (ModeNumber, &LcdBpp); > - ASSERT_EFI_ERROR (Status); > if (EFI_ERROR (Status)) { > - return EFI_DEVICE_ERROR; > + ASSERT_EFI_ERROR (Status); > + return Status; Same as above. > } > > BytesPerPixel = GetBytesPerPixel (LcdBpp); > diff --git a/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111Lcd.c b/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111Lcd.c > index 386e6140a69b045f77ee7fa60c4587d8bf4e7d54..f432c8d802614e8a0e4ddab3898f6e0dbf9a1572 100644 > --- a/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111Lcd.c > +++ b/ArmPlatformPkg/Drivers/LcdGraphicsOutputDxe/PL111Lcd.c > @@ -110,15 +110,15 @@ LcdSetMode ( > &VBackPorch, > &VFrontPorch > ); > - ASSERT_EFI_ERROR (Status); > if (EFI_ERROR (Status)) { > - return EFI_DEVICE_ERROR; > + ASSERT_EFI_ERROR (Status); > + return Status; Same as above. > } > > Status = LcdPlatformGetBpp (ModeNumber, &LcdBpp); > - ASSERT_EFI_ERROR (Status); > if (EFI_ERROR (Status)) { > - return EFI_DEVICE_ERROR; > + ASSERT_EFI_ERROR (Status); > + return Status; Same as above. / Leif > } > > // Disable the CLCD_LcdEn bit > -- > Guid("CE165669-3EF3-493F-B85D-6190EE5B9759") >