[RFC PATCH 2/3] misra: address rule 5.5 gnttab

Dmytro Prokopchuk1 posted 3 patches 3 months ago
[RFC PATCH 2/3] misra: address rule 5.5 gnttab
Posted by Dmytro Prokopchuk1 3 months ago
Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
---
 xen/common/grant_table.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
index cf131c43a1..9b8f0d87d3 100644
--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -127,8 +127,8 @@ static void __init cf_check max_maptrack_frames_init(struct param_hypfs *par)
                       opt_max_maptrack_frames_val);
 }
 #else
-#define update_gnttab_par(v, unused1, unused2)     update_gnttab_par(v)
-#define parse_gnttab_limit(a, v, unused1, unused2) parse_gnttab_limit(a, v)
+#define UPDATE_GNTTAB_PAR(v, unused1, unused2)     update_gnttab_par(v)
+#define PARSE_GNTTAB_LIMIT(a, v, unused1, unused2) parse_gnttab_limit(a, v)
 
 static void update_gnttab_par(unsigned int val, struct param_hypfs *par,
                               char *parval)
@@ -150,7 +150,7 @@ static int parse_gnttab_limit(const char *arg, unsigned int *valp,
         return -ERANGE;
 
     *valp = val;
-    update_gnttab_par(val, par, parval);
+    UPDATE_GNTTAB_PAR(val, par, parval);
 
     return 0;
 }
@@ -161,7 +161,7 @@ custom_runtime_param("gnttab_max_frames", parse_gnttab_max_frames,
 
 static int cf_check parse_gnttab_max_frames(const char *arg)
 {
-    return parse_gnttab_limit(arg, &opt_max_grant_frames,
+    return PARSE_GNTTAB_LIMIT(arg, &opt_max_grant_frames,
                               param_2_parfs(parse_gnttab_max_frames),
                               opt_max_grant_frames_val);
 }
@@ -173,7 +173,7 @@ custom_runtime_param("gnttab_max_maptrack_frames",
 
 static int cf_check parse_gnttab_max_maptrack_frames(const char *arg)
 {
-    return parse_gnttab_limit(arg, &opt_max_maptrack_frames,
+    return PARSE_GNTTAB_LIMIT(arg, &opt_max_maptrack_frames,
                               param_2_parfs(parse_gnttab_max_maptrack_frames),
                               opt_max_maptrack_frames_val);
 }
-- 
2.43.0
Re: [RFC PATCH 2/3] misra: address rule 5.5 gnttab
Posted by Andrew Cooper 3 months ago
On 29/07/2025 10:24 pm, Dmytro Prokopchuk1 wrote:
> Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
> ---
>  xen/common/grant_table.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c
> index cf131c43a1..9b8f0d87d3 100644
> --- a/xen/common/grant_table.c
> +++ b/xen/common/grant_table.c
> @@ -127,8 +127,8 @@ static void __init cf_check max_maptrack_frames_init(struct param_hypfs *par)
>                        opt_max_maptrack_frames_val);
>  }
>  #else
> -#define update_gnttab_par(v, unused1, unused2)     update_gnttab_par(v)
> -#define parse_gnttab_limit(a, v, unused1, unused2) parse_gnttab_limit(a, v)
> +#define UPDATE_GNTTAB_PAR(v, unused1, unused2)     update_gnttab_par(v)
> +#define PARSE_GNTTAB_LIMIT(a, v, unused1, unused2) parse_gnttab_limit(a, v)

I'm afraid this doesn't compile, and cannot be taken in this form. 
CONFIG_HYPFS very intentionally uses this macro alias to discard the 2nd
and 3rd parameters.

Also, it's really not just gnttab which suffers from this.  All
subsystems with mutable parameters follow the same pattern.

I don't have a good suggestion, and it's extra awkward that the MISRA
violation only occurs in the !CONFIG_HYPFS case which is trying to stub
out the logic with minimal #ifdef-ary.  It is definitely weird and
unergonomic for par and parval to not even be evaluated, but that's
necessary for things to compile.

~Andrew