diff mbox series

[XEN,2/2] xen/delay: address MISRA C:2012 Rule 5.3.

Message ID 47e2c8770e38ab064cbcdfaafa8467c5e733f11d.1691567429.git.nicola.vetrini@bugseng.com (mailing list archive)
State New, archived
Headers show
Series xen: address MISRA C:2012 Rule 5.3 | expand

Commit Message

Nicola Vetrini Aug. 9, 2023, 7:55 a.m. UTC
The variable 'msec' declared in the macro shadows the local
variable in 'ehci_dbgp_bios_handoff', but to prevent any
future clashes with other functions the macro is converted to
a static inline function.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
 xen/include/xen/delay.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Julien Grall Aug. 9, 2023, 11:10 a.m. UTC | #1
Hi Nicola,

On 09/08/2023 08:55, Nicola Vetrini wrote:
> The variable 'msec' declared in the macro shadows the local
> variable in 'ehci_dbgp_bios_handoff', but to prevent any
> future clashes with other functions the macro is converted to
> a static inline function.
> 
> No functional change.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>

Reviewed-by: Julien Grall <jgrall@amazon.com>

Cheers,
Luca Fancellu Aug. 9, 2023, 1:56 p.m. UTC | #2
> On 9 Aug 2023, at 08:55, Nicola Vetrini <nicola.vetrini@bugseng.com> wrote:
> 
> The variable 'msec' declared in the macro shadows the local
> variable in 'ehci_dbgp_bios_handoff', but to prevent any
> future clashes with other functions the macro is converted to
> a static inline function.
> 
> No functional change.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> ---
> xen/include/xen/delay.h | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/xen/include/xen/delay.h b/xen/include/xen/delay.h
> index 9d70ef035f..9150226271 100644
> --- a/xen/include/xen/delay.h
> +++ b/xen/include/xen/delay.h
> @@ -4,7 +4,11 @@
> /* Copyright (C) 1993 Linus Torvalds */
> 
> #include <asm/delay.h>
> -#define mdelay(n) (\
> - {unsigned long msec=(n); while (msec--) udelay(1000);})
> +
> +static inline void mdelay(unsigned long msec)
> +{
> +    while ( msec-- )

Does misra allows to modify the function parameters? (Truly asking because IDK)

> +        udelay(1000);
> +}
> 
> #endif /* defined(_LINUX_DELAY_H) */
> -- 
> 2.34.1
> 
>
Nicola Vetrini Aug. 9, 2023, 2:09 p.m. UTC | #3
On 09/08/2023 15:56, Luca Fancellu wrote:
>> On 9 Aug 2023, at 08:55, Nicola Vetrini <nicola.vetrini@bugseng.com> 
>> wrote:
>> 
>> The variable 'msec' declared in the macro shadows the local
>> variable in 'ehci_dbgp_bios_handoff', but to prevent any
>> future clashes with other functions the macro is converted to
>> a static inline function.
>> 
>> No functional change.
>> 
>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
>> ---
>> xen/include/xen/delay.h | 8 ++++++--
>> 1 file changed, 6 insertions(+), 2 deletions(-)
>> 
>> diff --git a/xen/include/xen/delay.h b/xen/include/xen/delay.h
>> index 9d70ef035f..9150226271 100644
>> --- a/xen/include/xen/delay.h
>> +++ b/xen/include/xen/delay.h
>> @@ -4,7 +4,11 @@
>> /* Copyright (C) 1993 Linus Torvalds */
>> 
>> #include <asm/delay.h>
>> -#define mdelay(n) (\
>> - {unsigned long msec=(n); while (msec--) udelay(1000);})
>> +
>> +static inline void mdelay(unsigned long msec)
>> +{
>> +    while ( msec-- )
> 
> Does misra allows to modify the function parameters? (Truly asking 
> because IDK)
> 

I checked: there's an advisory (R17.8) that disallows this, but since 
advisories (apart from
a couple of selected ones) are not taken into consideration for 
compliance, so it's not a big deal.
Even less so since it's not a pointer type.
diff mbox series

Patch

diff --git a/xen/include/xen/delay.h b/xen/include/xen/delay.h
index 9d70ef035f..9150226271 100644
--- a/xen/include/xen/delay.h
+++ b/xen/include/xen/delay.h
@@ -4,7 +4,11 @@ 
 /* Copyright (C) 1993 Linus Torvalds */
 
 #include <asm/delay.h>
-#define mdelay(n) (\
-	{unsigned long msec=(n); while (msec--) udelay(1000);})
+
+static inline void mdelay(unsigned long msec)
+{
+    while ( msec-- )
+        udelay(1000);
+}
 
 #endif /* defined(_LINUX_DELAY_H) */