public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [edk2 Patch 0/1] fix compiler error due to void pointer arithmetic
@ 2024-02-06  5:23 Jayaprakash, N
  2024-02-06  5:23 ` [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: compiler error due to arithmetic operation on void pointer Jayaprakash, N
  0 siblings, 1 reply; 7+ messages in thread
From: Jayaprakash, N @ 2024-02-06  5:23 UTC (permalink / raw)
  To: devel; +Cc: Jayaprakash N

This patch fixes the compiler error generated while compiling
the EmbeddedPkg due to arithmetic operation being performed
on a void pointer.

Jayaprakash N (1):
  EmbeddedPkg: compiler error due to arithmetic operation on void
    pointer

 .../Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-- 
2.40.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115144): https://edk2.groups.io/g/devel/message/115144
Mute This Topic: https://groups.io/mt/104193284/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: compiler error due to arithmetic operation on void pointer
  2024-02-06  5:23 [edk2-devel] [edk2 Patch 0/1] fix compiler error due to void pointer arithmetic Jayaprakash, N
@ 2024-02-06  5:23 ` Jayaprakash, N
  2024-02-06 12:57   ` Ard Biesheuvel
  0 siblings, 1 reply; 7+ messages in thread
From: Jayaprakash, N @ 2024-02-06  5:23 UTC (permalink / raw)
  To: devel
  Cc: Jayaprakash N, Rebecca Cran, Michael D Kinney, Laszlo Ersek,
	Leif Lindholm, Ard Biesheuvel, Abner Chang

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4668

This commit fixes the issue reported in the BZ4668.
The EmbeddedPkg fails to compile with a compiler error
generated due to invalid/illegal arithmetic operation
on void pointers. It has been fixed by using explicit
type conversion of the void pointer to UINTN.

Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Jayaprakash N <n.jayaprakash@intel.com>
Signed-off-by: Jayaprakash N <n.jayaprakash@intel.com>
---
 .../Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
index fa81cc9d59..11566cf57f 100644
--- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
+++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
@@ -308,7 +308,7 @@ ReallocatePool (
   if (OldBuffer != NULL) {
     HandOffHob = GetHobList ();
     ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)OldBuffer >= HandOffHob->EfiMemoryBottom));
-    ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)(OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom));
+    ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)((UINTN)OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom));
   }
 
   DEBUG_CODE_END ();
-- 
2.40.0.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115145): https://edk2.groups.io/g/devel/message/115145
Mute This Topic: https://groups.io/mt/104193285/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: compiler error due to arithmetic operation on void pointer
  2024-02-06  5:23 ` [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: compiler error due to arithmetic operation on void pointer Jayaprakash, N
@ 2024-02-06 12:57   ` Ard Biesheuvel
  2024-02-06 14:36     ` Laszlo Ersek
  0 siblings, 1 reply; 7+ messages in thread
From: Ard Biesheuvel @ 2024-02-06 12:57 UTC (permalink / raw)
  To: devel, n.jayaprakash
  Cc: Rebecca Cran, Michael D Kinney, Laszlo Ersek, Leif Lindholm,
	Ard Biesheuvel, Abner Chang

On Tue, 6 Feb 2024 at 05:23, Jayaprakash, N <n.jayaprakash@intel.com> wrote:
>
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4668
>
> This commit fixes the issue reported in the BZ4668.
> The EmbeddedPkg fails to compile with a compiler error
> generated due to invalid/illegal arithmetic operation
> on void pointers. It has been fixed by using explicit
> type conversion of the void pointer to UINTN.
>
> Cc: Rebecca Cran <rebecca@bsdio.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Leif Lindholm <quic_llindhol@quicinc.com>
> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Jayaprakash N <n.jayaprakash@intel.com>
> Signed-off-by: Jayaprakash N <n.jayaprakash@intel.com>
> ---
>  .../Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c      | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
> index fa81cc9d59..11566cf57f 100644
> --- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
> +++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
> @@ -308,7 +308,7 @@ ReallocatePool (
>    if (OldBuffer != NULL) {
>      HandOffHob = GetHobList ();
>      ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)OldBuffer >= HandOffHob->EfiMemoryBottom));
> -    ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)(OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom));
> +    ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)((UINTN)OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom));


Do we really need two UINTN casts here?


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115158): https://edk2.groups.io/g/devel/message/115158
Mute This Topic: https://groups.io/mt/104193285/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: compiler error due to arithmetic operation on void pointer
  2024-02-06 12:57   ` Ard Biesheuvel
@ 2024-02-06 14:36     ` Laszlo Ersek
  2024-02-06 15:55       ` Jayaprakash, N
  0 siblings, 1 reply; 7+ messages in thread
From: Laszlo Ersek @ 2024-02-06 14:36 UTC (permalink / raw)
  To: Ard Biesheuvel, devel, n.jayaprakash
  Cc: Rebecca Cran, Michael D Kinney, Leif Lindholm, Ard Biesheuvel,
	Abner Chang

On 2/6/24 13:57, Ard Biesheuvel wrote:
> On Tue, 6 Feb 2024 at 05:23, Jayaprakash, N <n.jayaprakash@intel.com> wrote:
>>
>> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4668
>>
>> This commit fixes the issue reported in the BZ4668.
>> The EmbeddedPkg fails to compile with a compiler error
>> generated due to invalid/illegal arithmetic operation
>> on void pointers. It has been fixed by using explicit
>> type conversion of the void pointer to UINTN.
>>
>> Cc: Rebecca Cran <rebecca@bsdio.com>
>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
>> Cc: Laszlo Ersek <lersek@redhat.com>
>> Cc: Leif Lindholm <quic_llindhol@quicinc.com>
>> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
>> Cc: Abner Chang <abner.chang@amd.com>
>> Cc: Jayaprakash N <n.jayaprakash@intel.com>
>> Signed-off-by: Jayaprakash N <n.jayaprakash@intel.com>
>> ---
>>  .../Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c      | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
>> index fa81cc9d59..11566cf57f 100644
>> --- a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
>> +++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
>> @@ -308,7 +308,7 @@ ReallocatePool (
>>    if (OldBuffer != NULL) {
>>      HandOffHob = GetHobList ();
>>      ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)OldBuffer >= HandOffHob->EfiMemoryBottom));
>> -    ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)(OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom));
>> +    ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)((UINTN)OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom));
> 
> 
> Do we really need two UINTN casts here?
> 

No, that should not be necessary. In
<https://edk2.groups.io/g/devel/message/115050> (msgid
<01296486-5b14-4b73-b9dc-777a723548cf@redhat.com>), I recommended:

--------------
We should replace (UINTN)(OldBuffer + OldSize) with ((UINTN)OldBuffer +
OldSize).
--------------

Note that the text to remove includes the original (UINTN) cast.

Laszlo



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115167): https://edk2.groups.io/g/devel/message/115167
Mute This Topic: https://groups.io/mt/104193285/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: compiler error due to arithmetic operation on void pointer
  2024-02-06 14:36     ` Laszlo Ersek
@ 2024-02-06 15:55       ` Jayaprakash, N
  2024-02-07 14:21         ` Laszlo Ersek
  0 siblings, 1 reply; 7+ messages in thread
From: Jayaprakash, N @ 2024-02-06 15:55 UTC (permalink / raw)
  To: Laszlo Ersek, Ard Biesheuvel, devel@edk2.groups.io
  Cc: Rebecca Cran, Kinney, Michael D, Leif Lindholm, Ard Biesheuvel,
	Abner Chang

Thank you Laszlo and Ard Biesheuvel for your inputs.
2 type cast operations are not needed. 
Shall I send an updated patch for review and merger?

Regards,
JP 

-----Original Message-----
From: Laszlo Ersek <lersek@redhat.com> 
Sent: Tuesday, February 6, 2024 8:07 PM
To: Ard Biesheuvel <ardb@kernel.org>; devel@edk2.groups.io; Jayaprakash, N <n.jayaprakash@intel.com>
Cc: Rebecca Cran <rebecca@bsdio.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Leif Lindholm <quic_llindhol@quicinc.com>; Ard Biesheuvel <ardb+tianocore@kernel.org>; Abner Chang <abner.chang@amd.com>
Subject: Re: [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: compiler error due to arithmetic operation on void pointer

On 2/6/24 13:57, Ard Biesheuvel wrote:
> On Tue, 6 Feb 2024 at 05:23, Jayaprakash, N <n.jayaprakash@intel.com> wrote:
>>
>> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4668
>>
>> This commit fixes the issue reported in the BZ4668.
>> The EmbeddedPkg fails to compile with a compiler error generated due 
>> to invalid/illegal arithmetic operation on void pointers. It has been 
>> fixed by using explicit type conversion of the void pointer to UINTN.
>>
>> Cc: Rebecca Cran <rebecca@bsdio.com>
>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
>> Cc: Laszlo Ersek <lersek@redhat.com>
>> Cc: Leif Lindholm <quic_llindhol@quicinc.com>
>> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
>> Cc: Abner Chang <abner.chang@amd.com>
>> Cc: Jayaprakash N <n.jayaprakash@intel.com>
>> Signed-off-by: Jayaprakash N <n.jayaprakash@intel.com>
>> ---
>>  .../Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c      | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git 
>> a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c 
>> b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
>> index fa81cc9d59..11566cf57f 100644
>> --- 
>> a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
>> +++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLi
>> +++ b.c
>> @@ -308,7 +308,7 @@ ReallocatePool (
>>    if (OldBuffer != NULL) {
>>      HandOffHob = GetHobList ();
>>      ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)OldBuffer >= HandOffHob->EfiMemoryBottom));
>> -    ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)(OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom));
>> +    ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)((UINTN)OldBuffer + 
>> + OldSize) <= HandOffHob->EfiFreeMemoryBottom));
> 
> 
> Do we really need two UINTN casts here?
> 

No, that should not be necessary. In
<https://edk2.groups.io/g/devel/message/115050> (msgid <01296486-5b14-4b73-b9dc-777a723548cf@redhat.com>), I recommended:

--------------
We should replace (UINTN)(OldBuffer + OldSize) with ((UINTN)OldBuffer + OldSize).
--------------

Note that the text to remove includes the original (UINTN) cast.

Laszlo



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115177): https://edk2.groups.io/g/devel/message/115177
Mute This Topic: https://groups.io/mt/104193285/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: compiler error due to arithmetic operation on void pointer
  2024-02-06 15:55       ` Jayaprakash, N
@ 2024-02-07 14:21         ` Laszlo Ersek
  2024-02-07 14:40           ` Jayaprakash, N
  0 siblings, 1 reply; 7+ messages in thread
From: Laszlo Ersek @ 2024-02-07 14:21 UTC (permalink / raw)
  To: Jayaprakash, N, Ard Biesheuvel, devel@edk2.groups.io
  Cc: Rebecca Cran, Kinney, Michael D, Leif Lindholm, Ard Biesheuvel,
	Abner Chang

On 2/6/24 16:55, Jayaprakash, N wrote:
> Thank you Laszlo and Ard Biesheuvel for your inputs.
> 2 type cast operations are not needed. 
> Shall I send an updated patch for review and merger?

Yes, please send a new version. It's a build error fix with low
regression risk, so it should qualify for merging during the hard freeze
even, IMO.

BTW, do you have an idea why this issue has popped up only now? The code
comes from commit 0d39caefb95e ("EmbeddedPkg/PrePiMemoryAllocationLib:
Add ReallocatePool", 2024-01-03), so it's a month old. Is this perhaps
the first time that the new ReallocatePool() function has been built
with MSVC? (I suspect that because the compiler error message in BZ 4668
seems to come from MSVC.)

Laszlo

> 
> Regards,
> JP 
> 
> -----Original Message-----
> From: Laszlo Ersek <lersek@redhat.com> 
> Sent: Tuesday, February 6, 2024 8:07 PM
> To: Ard Biesheuvel <ardb@kernel.org>; devel@edk2.groups.io; Jayaprakash, N <n.jayaprakash@intel.com>
> Cc: Rebecca Cran <rebecca@bsdio.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Leif Lindholm <quic_llindhol@quicinc.com>; Ard Biesheuvel <ardb+tianocore@kernel.org>; Abner Chang <abner.chang@amd.com>
> Subject: Re: [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: compiler error due to arithmetic operation on void pointer
> 
> On 2/6/24 13:57, Ard Biesheuvel wrote:
>> On Tue, 6 Feb 2024 at 05:23, Jayaprakash, N <n.jayaprakash@intel.com> wrote:
>>>
>>> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4668
>>>
>>> This commit fixes the issue reported in the BZ4668.
>>> The EmbeddedPkg fails to compile with a compiler error generated due 
>>> to invalid/illegal arithmetic operation on void pointers. It has been 
>>> fixed by using explicit type conversion of the void pointer to UINTN.
>>>
>>> Cc: Rebecca Cran <rebecca@bsdio.com>
>>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
>>> Cc: Laszlo Ersek <lersek@redhat.com>
>>> Cc: Leif Lindholm <quic_llindhol@quicinc.com>
>>> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
>>> Cc: Abner Chang <abner.chang@amd.com>
>>> Cc: Jayaprakash N <n.jayaprakash@intel.com>
>>> Signed-off-by: Jayaprakash N <n.jayaprakash@intel.com>
>>> ---
>>>  .../Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c      | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git 
>>> a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c 
>>> b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
>>> index fa81cc9d59..11566cf57f 100644
>>> --- 
>>> a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
>>> +++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLi
>>> +++ b.c
>>> @@ -308,7 +308,7 @@ ReallocatePool (
>>>    if (OldBuffer != NULL) {
>>>      HandOffHob = GetHobList ();
>>>      ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)OldBuffer >= HandOffHob->EfiMemoryBottom));
>>> -    ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)(OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom));
>>> +    ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)((UINTN)OldBuffer + 
>>> + OldSize) <= HandOffHob->EfiFreeMemoryBottom));
>>
>>
>> Do we really need two UINTN casts here?
>>
> 
> No, that should not be necessary. In
> <https://edk2.groups.io/g/devel/message/115050> (msgid <01296486-5b14-4b73-b9dc-777a723548cf@redhat.com>), I recommended:
> 
> --------------
> We should replace (UINTN)(OldBuffer + OldSize) with ((UINTN)OldBuffer + OldSize).
> --------------
> 
> Note that the text to remove includes the original (UINTN) cast.
> 
> Laszlo
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115235): https://edk2.groups.io/g/devel/message/115235
Mute This Topic: https://groups.io/mt/104193285/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: compiler error due to arithmetic operation on void pointer
  2024-02-07 14:21         ` Laszlo Ersek
@ 2024-02-07 14:40           ` Jayaprakash, N
  0 siblings, 0 replies; 7+ messages in thread
From: Jayaprakash, N @ 2024-02-07 14:40 UTC (permalink / raw)
  To: Laszlo Ersek, Ard Biesheuvel, devel@edk2.groups.io
  Cc: Rebecca Cran, Kinney, Michael D, Leif Lindholm, Ard Biesheuvel,
	Abner Chang

Thanks Laszlo.

I have already sent an updated patch v2.

I just happen to notice this issue when I tried building the EmbeddedPkg with MSVC.
I am not a regular user of this package. 

Regards,
JP
-----Original Message-----
From: Laszlo Ersek <lersek@redhat.com> 
Sent: Wednesday, February 7, 2024 7:52 PM
To: Jayaprakash, N <n.jayaprakash@intel.com>; Ard Biesheuvel <ardb@kernel.org>; devel@edk2.groups.io
Cc: Rebecca Cran <rebecca@bsdio.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Leif Lindholm <quic_llindhol@quicinc.com>; Ard Biesheuvel <ardb+tianocore@kernel.org>; Abner Chang <abner.chang@amd.com>
Subject: Re: [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: compiler error due to arithmetic operation on void pointer

On 2/6/24 16:55, Jayaprakash, N wrote:
> Thank you Laszlo and Ard Biesheuvel for your inputs.
> 2 type cast operations are not needed. 
> Shall I send an updated patch for review and merger?

Yes, please send a new version. It's a build error fix with low regression risk, so it should qualify for merging during the hard freeze even, IMO.

BTW, do you have an idea why this issue has popped up only now? The code comes from commit 0d39caefb95e ("EmbeddedPkg/PrePiMemoryAllocationLib:
Add ReallocatePool", 2024-01-03), so it's a month old. Is this perhaps the first time that the new ReallocatePool() function has been built with MSVC? (I suspect that because the compiler error message in BZ 4668 seems to come from MSVC.)

Laszlo

> 
> Regards,
> JP
> 
> -----Original Message-----
> From: Laszlo Ersek <lersek@redhat.com>
> Sent: Tuesday, February 6, 2024 8:07 PM
> To: Ard Biesheuvel <ardb@kernel.org>; devel@edk2.groups.io; 
> Jayaprakash, N <n.jayaprakash@intel.com>
> Cc: Rebecca Cran <rebecca@bsdio.com>; Kinney, Michael D 
> <michael.d.kinney@intel.com>; Leif Lindholm 
> <quic_llindhol@quicinc.com>; Ard Biesheuvel 
> <ardb+tianocore@kernel.org>; Abner Chang <abner.chang@amd.com>
> Subject: Re: [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: compiler error 
> due to arithmetic operation on void pointer
> 
> On 2/6/24 13:57, Ard Biesheuvel wrote:
>> On Tue, 6 Feb 2024 at 05:23, Jayaprakash, N <n.jayaprakash@intel.com> wrote:
>>>
>>> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4668
>>>
>>> This commit fixes the issue reported in the BZ4668.
>>> The EmbeddedPkg fails to compile with a compiler error generated due 
>>> to invalid/illegal arithmetic operation on void pointers. It has 
>>> been fixed by using explicit type conversion of the void pointer to UINTN.
>>>
>>> Cc: Rebecca Cran <rebecca@bsdio.com>
>>> Cc: Michael D Kinney <michael.d.kinney@intel.com>
>>> Cc: Laszlo Ersek <lersek@redhat.com>
>>> Cc: Leif Lindholm <quic_llindhol@quicinc.com>
>>> Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
>>> Cc: Abner Chang <abner.chang@amd.com>
>>> Cc: Jayaprakash N <n.jayaprakash@intel.com>
>>> Signed-off-by: Jayaprakash N <n.jayaprakash@intel.com>
>>> ---
>>>  .../Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c      | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git
>>> a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
>>> b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
>>> index fa81cc9d59..11566cf57f 100644
>>> ---
>>> a/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationLib.c
>>> +++ b/EmbeddedPkg/Library/PrePiMemoryAllocationLib/MemoryAllocationL
>>> +++ i
>>> +++ b.c
>>> @@ -308,7 +308,7 @@ ReallocatePool (
>>>    if (OldBuffer != NULL) {
>>>      HandOffHob = GetHobList ();
>>>      ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)OldBuffer >= HandOffHob->EfiMemoryBottom));
>>> -    ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)(OldBuffer + OldSize) <= HandOffHob->EfiFreeMemoryBottom));
>>> +    ASSERT (((EFI_PHYSICAL_ADDRESS)(UINTN)((UINTN)OldBuffer +
>>> + OldSize) <= HandOffHob->EfiFreeMemoryBottom));
>>
>>
>> Do we really need two UINTN casts here?
>>
> 
> No, that should not be necessary. In
> <https://edk2.groups.io/g/devel/message/115050> (msgid <01296486-5b14-4b73-b9dc-777a723548cf@redhat.com>), I recommended:
> 
> --------------
> We should replace (UINTN)(OldBuffer + OldSize) with ((UINTN)OldBuffer + OldSize).
> --------------
> 
> Note that the text to remove includes the original (UINTN) cast.
> 
> Laszlo
> 



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115237): https://edk2.groups.io/g/devel/message/115237
Mute This Topic: https://groups.io/mt/104193285/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-02-07 14:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-06  5:23 [edk2-devel] [edk2 Patch 0/1] fix compiler error due to void pointer arithmetic Jayaprakash, N
2024-02-06  5:23 ` [edk2-devel] [edk2 Patch 1/1] EmbeddedPkg: compiler error due to arithmetic operation on void pointer Jayaprakash, N
2024-02-06 12:57   ` Ard Biesheuvel
2024-02-06 14:36     ` Laszlo Ersek
2024-02-06 15:55       ` Jayaprakash, N
2024-02-07 14:21         ` Laszlo Ersek
2024-02-07 14:40           ` Jayaprakash, N

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox