[edk2-devel] [PATCH 1/1] UefiCpuPkg/PiSmmCpuDxeSmm: fix format string

Michael D Kinney michael.d.kinney at intel.com
Fri Mar 24 15:35:17 UTC 2023


And from Laszlo's responses, 3 total options.

1) Keep %d and change BufferPages to type UINT32.
2) Change to %Ld and change BufferPages to type UINT64.
3) Change to %Ld and typecast BufferPages to UINT64 in DEBUG().

All 3 will work.  Best suggestion is (3) from Laszlo.

Mike

> -----Original Message-----
> From: Kinney, Michael D <michael.d.kinney at intel.com>
> Sent: Friday, March 24, 2023 8:27 AM
> To: Ni, Ray <ray.ni at intel.com>; Gerd Hoffmann <kraxel at redhat.com>; devel at edk2.groups.io
> Cc: Dong, Eric <eric.dong at intel.com>; Oliver Steffen <osteffen at redhat.com>; Kumar, Rahul R <rahul.r.kumar at intel.com>;
> Pawel Polawski <ppolawsk at redhat.com>; Laszlo Ersek <lersek at redhat.com>; Kinney, Michael D <michael.d.kinney at intel.com>
> Subject: RE: [PATCH 1/1] UefiCpuPkg/PiSmmCpuDxeSmm: fix format string
> 
> 1) Keep %d and change BufferPages to type UINT32.
> 2) Change to %Ld and change BufferPages to type UINT64.> 
> Mike
> 
> > -----Original Message-----
> > From: Ni, Ray <ray.ni at intel.com>
> > Sent: Friday, March 24, 2023 7:00 AM
> > To: Gerd Hoffmann <kraxel at redhat.com>; devel at edk2.groups.io; Kinney, Michael D <michael.d.kinney at intel.com>
> > Cc: Dong, Eric <eric.dong at intel.com>; Oliver Steffen <osteffen at redhat.com>; Kumar, Rahul R <rahul.r.kumar at intel.com>;
> > Pawel Polawski <ppolawsk at redhat.com>; Laszlo Ersek <lersek at redhat.com>
> > Subject: RE: [PATCH 1/1] UefiCpuPkg/PiSmmCpuDxeSmm: fix format string
> >
> > Gerd,
> > "%d" tells "int" type value is in the stack.
> > This actually works in both 32bit and 64bit case assuming the BufferPages is less than MAX_UINT32.
> >
> > But if using "%Lu", it tells that "uint_64" type value is in the stack.
> > This precisely describes the stack content in 64bit mode.
> > But it may print random value in the stack as high-32 bit in 32bit mode.
> >
> > @Kinney, Michael D, any comments?
> >
> > Thanks,
> > Ray
> >
> >
> > > -----Original Message-----
> > > From: Gerd Hoffmann <kraxel at redhat.com>
> > > Sent: Friday, March 24, 2023 9:42 PM
> > > To: devel at edk2.groups.io
> > > Cc: Dong, Eric <eric.dong at intel.com>; Gerd Hoffmann <kraxel at redhat.com>;
> > > Oliver Steffen <osteffen at redhat.com>; Kumar, Rahul R
> > > <rahul.r.kumar at intel.com>; Ni, Ray <ray.ni at intel.com>; Pawel Polawski
> > > <ppolawsk at redhat.com>; Laszlo Ersek <lersek at redhat.com>
> > > Subject: [PATCH 1/1] UefiCpuPkg/PiSmmCpuDxeSmm: fix format string
> > >
> > > BufferPages is UINTN, so we need "%Lu" when printing it.
> > >
> > > Fixes: 4f441d024bee ("UefiCpuPkg/PiSmmCpuDxeSmm: fix error handling")
> > > Reported-by: Laszlo Ersek <lersek at redhat.com>
> > > Signed-off-by: Gerd Hoffmann <kraxel at redhat.com>
> > > ---
> > >  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
> > > b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
> > > index cf69161caa4b..08663b1b1ab4 100644
> > > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
> > > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
> > > @@ -880,7 +880,7 @@ PiCpuSmmEntry (
> > >      BufferPages = EFI_SIZE_TO_PAGES (SIZE_32KB + TileSize *
> > > (mMaxNumberOfCpus - 1));
> > >      Buffer      = AllocateAlignedCodePages (BufferPages, SIZE_4KB);
> > >      if (Buffer == NULL) {
> > > -      DEBUG ((DEBUG_ERROR, "Failed to allocate %d pages.\n", BufferPages));
> > > +      DEBUG ((DEBUG_ERROR, "Failed to allocate %Lu pages.\n",
> > > BufferPages));
> > >        CpuDeadLoop ();
> > >        return EFI_OUT_OF_RESOURCES;
> > >      }
> > > --
> > > 2.39.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#101794): https://edk2.groups.io/g/devel/message/101794
Mute This Topic: https://groups.io/mt/97823585/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/3943202/1813853/130120423/xyzzy [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-




More information about the edk2-devel-archive mailing list