[PATCH] xen/decompress: resolve MISRA R5.5 identifier/macro name conflicts

Dmytro Prokopchuk1 posted 1 patch 1 day, 23 hours ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/69ef81a2f85b35e6231ae389bf271cad2bbd7dfc.1779394622.git.dmytro._5Fprokopchuk1@epam.com
xen/common/decompress.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] xen/decompress: resolve MISRA R5.5 identifier/macro name conflicts
Posted by Dmytro Prokopchuk1 1 day, 23 hours ago
Convert 'malloc' and 'free' macros in 'decompress.h' from object-like
to function-like form.

The object-like macros '#define free xfree' perform unconditional text
replacement, causing conflicts with struct field 'free' in 'page_info'
unions. Function-like macros only match when followed by parentheses,
allowing 'free' to be used both as a macro and as a struct field without
conflicts.

Applying function-like form to both 'malloc' and 'free' ensures consistent
macro style.

Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
---
 xen/common/decompress.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/xen/common/decompress.h b/xen/common/decompress.h
index 034c833665..df9fb9234f 100644
--- a/xen/common/decompress.h
+++ b/xen/common/decompress.h
@@ -9,8 +9,8 @@
 #include <xen/types.h>
 #include <xen/xmalloc.h>
 
-#define malloc xmalloc_bytes
-#define free xfree
+#define malloc(a) xmalloc_bytes(a)
+#define free(a) xfree(a)
 
 #define large_malloc xmalloc_bytes
 #define large_free xfree
-- 
2.43.0
Re: [PATCH] xen/decompress: resolve MISRA R5.5 identifier/macro name conflicts
Posted by Jan Beulich 1 day, 14 hours ago
On 21.05.2026 22:18, Dmytro Prokopchuk1 wrote:
> Convert 'malloc' and 'free' macros in 'decompress.h' from object-like
> to function-like form.
> 
> The object-like macros '#define free xfree' perform unconditional text
> replacement, causing conflicts with struct field 'free' in 'page_info'
> unions. Function-like macros only match when followed by parentheses,
> allowing 'free' to be used both as a macro and as a struct field without
> conflicts.

At the same time function-like macros cannot be used to e.g. pass the
(underlying) function pointer to a function. Likely there aren't any
such uses here, but imo this aspect needs covering in patches like
this one.

> Applying function-like form to both 'malloc' and 'free' ensures consistent
> macro style.

Not quite, seeing ...

> --- a/xen/common/decompress.h
> +++ b/xen/common/decompress.h
> @@ -9,8 +9,8 @@
>  #include <xen/types.h>
>  #include <xen/xmalloc.h>
>  
> -#define malloc xmalloc_bytes
> -#define free xfree
> +#define malloc(a) xmalloc_bytes(a)
> +#define free(a) xfree(a)
>  
>  #define large_malloc xmalloc_bytes
>  #define large_free xfree

... these two in context? IOW if you mean to achieve consistency,
convert these (and whatever else, if anything) as well?

Jan
Re: [PATCH] xen/decompress: resolve MISRA R5.5 identifier/macro name conflicts
Posted by Dmytro Prokopchuk1 1 day ago
Hello Jan,

On 5/22/26 09:10, Jan Beulich wrote:
> On 21.05.2026 22:18, Dmytro Prokopchuk1 wrote:
>> Convert 'malloc' and 'free' macros in 'decompress.h' from object-like
>> to function-like form.
>>
>> The object-like macros '#define free xfree' perform unconditional text
>> replacement, causing conflicts with struct field 'free' in 'page_info'
>> unions. Function-like macros only match when followed by parentheses,
>> allowing 'free' to be used both as a macro and as a struct field without
>> conflicts.
> 
> At the same time function-like macros cannot be used to e.g. pass the
> (underlying) function pointer to a function. Likely there aren't any
> such uses here, but imo this aspect needs covering in patches like
> this one.
I will search through the Xen codebase these macros.
> 
>> Applying function-like form to both 'malloc' and 'free' ensures consistent
>> macro style.
> 
> Not quite, seeing ...
> 
>> --- a/xen/common/decompress.h
>> +++ b/xen/common/decompress.h
>> @@ -9,8 +9,8 @@
>>   #include <xen/types.h>
>>   #include <xen/xmalloc.h>
>>   
>> -#define malloc xmalloc_bytes
>> -#define free xfree
>> +#define malloc(a) xmalloc_bytes(a)
>> +#define free(a) xfree(a)
>>   
>>   #define large_malloc xmalloc_bytes
>>   #define large_free xfree
> 
> ... these two in context? IOW if you mean to achieve consistency,
> convert these (and whatever else, if anything) as well?
> 
Yes, this makes sense as well.
> Jan

BR, Dmytro.