Message ID | 15d6e4fb5c873e7ea42cfcee2faa0bf33c10d101.1709219010.git.nicola.vetrini@bugseng.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | address some violations of MISRA C Rule 20.7 | expand |
On 29/02/2024 3:27 pm, Nicola Vetrini wrote: > diff --git a/xen/include/xen/kconfig.h b/xen/include/xen/kconfig.h > index c25dc0f6c2a9..b7e70289737b 100644 > --- a/xen/include/xen/kconfig.h > +++ b/xen/include/xen/kconfig.h > @@ -25,7 +25,7 @@ > #define __ARG_PLACEHOLDER_1 0, > #define config_enabled(cfg) _config_enabled(cfg) > #define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value) > -#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0) > +#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk (1), (0)) > #define ___config_enabled(__ignored, val, ...) val This one hunk I suggest we deviate rather than adjust. You've subtly broken it, and it's extreme preprocessor magic in the first place to turn an absent symbol into a 0. ~Andrew
On 2024-02-29 17:10, Andrew Cooper wrote: > On 29/02/2024 3:27 pm, Nicola Vetrini wrote: >> diff --git a/xen/include/xen/kconfig.h b/xen/include/xen/kconfig.h >> index c25dc0f6c2a9..b7e70289737b 100644 >> --- a/xen/include/xen/kconfig.h >> +++ b/xen/include/xen/kconfig.h >> @@ -25,7 +25,7 @@ >> #define __ARG_PLACEHOLDER_1 0, >> #define config_enabled(cfg) _config_enabled(cfg) >> #define _config_enabled(value) >> __config_enabled(__ARG_PLACEHOLDER_##value) >> -#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk >> 1, 0) >> +#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk >> (1), (0)) >> #define ___config_enabled(__ignored, val, ...) val > > This one hunk I suggest we deviate rather than adjust. You've subtly > broken it, and it's extreme preprocessor magic in the first place to > turn an absent symbol into a 0. > How so? I did test this because I was very wary of it, but it seemed to expand fine (either if ((0)) or if ((1)) ). I may of course be wrong, and it could be deviated regardless.
On 29.02.2024 16:27, Nicola Vetrini wrote: > --- a/xen/include/xen/kconfig.h > +++ b/xen/include/xen/kconfig.h > @@ -25,7 +25,7 @@ > #define __ARG_PLACEHOLDER_1 0, > #define config_enabled(cfg) _config_enabled(cfg) > #define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value) > -#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0) > +#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk (1), (0)) > #define ___config_enabled(__ignored, val, ...) val In addition to what Andrew said, would you mind clarifying what exactly the violation is here? I find it questionable that numeric literals need parenthesizing; they don't normally need to, aynwhere. > --- a/xen/include/xen/list.h > +++ b/xen/include/xen/list.h > @@ -490,9 +490,9 @@ static inline void list_splice_init(struct list_head *list, > * @member: the name of the list_struct within the struct. > */ > #define list_for_each_entry(pos, head, member) \ > - for (pos = list_entry((head)->next, typeof(*pos), member); \ > - &pos->member != (head); \ > - pos = list_entry(pos->member.next, typeof(*pos), member)) > + for (pos = list_entry((head)->next, typeof(*(pos)), member); \ > + &(pos)->member != (head); \ > + pos = list_entry((pos)->member.next, typeof(*(pos)), member)) this ends up inconsistent, which I think isn't nice: Some uses of "pos" are now parenthesized, while others aren't. Applies further down as well. You may also want to take this as a strong suggestion to split dissimilar changes, so uncontroversial parts can go in. > @@ -977,4 +977,3 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev, > pos = pos->next) > > #endif /* __XEN_LIST_H__ */ > - Unrelated change? > --- a/xen/include/xen/spinlock.h > +++ b/xen/include/xen/spinlock.h > @@ -94,7 +94,7 @@ struct lock_profile_qhead { > int32_t idx; /* index for printout */ > }; > > -#define _LOCK_PROFILE(lockname) { .name = #lockname, .lock = &lockname, } > +#define _LOCK_PROFILE(lockname) { .name = #lockname, .lock = &(lockname), } This also may be viewed as falling in the same category, but is less problematic because the other use is stringification, when in principle some kind of expression would be passed in (albeit in practice I don't expect anyone would do that). Jan
On 2024-02-29 17:25, Jan Beulich wrote: > On 29.02.2024 16:27, Nicola Vetrini wrote: >> --- a/xen/include/xen/kconfig.h >> +++ b/xen/include/xen/kconfig.h >> @@ -25,7 +25,7 @@ >> #define __ARG_PLACEHOLDER_1 0, >> #define config_enabled(cfg) _config_enabled(cfg) >> #define _config_enabled(value) >> __config_enabled(__ARG_PLACEHOLDER_##value) >> -#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk >> 1, 0) >> +#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk >> (1), (0)) >> #define ___config_enabled(__ignored, val, ...) val > > In addition to what Andrew said, would you mind clarifying what exactly > the > violation is here? I find it questionable that numeric literals need > parenthesizing; they don't normally need to, aynwhere. > This one's a little special. I couldn't parenthesize val further down, because then it would break the build: In file included from ././include/xen/config.h:14, from <command-line>: ./include/xen/kconfig.h:29:52: error: expected identifier or ‘(’ before ‘)’ token 29 | #define ___config_enabled(__ignored, val, ...) (val) | ^ ./include/xen/kconfig.h:39:34: note: in expansion of macro ‘___config_enabled’ 39 | #define _static_if(arg1_or_junk) ___config_enabled(arg1_or_junk static,) | ^~~~~~~~~~~~~~~~~ ./include/xen/kconfig.h:38:26: note: in expansion of macro ‘_static_if’ 38 | #define static_if(value) _static_if(__ARG_PLACEHOLDER_##value) | ^~~~~~~~~~ ./include/xen/kconfig.h:41:27: note: in expansion of macro ‘static_if’ 41 | #define STATIC_IF(option) static_if(option) | ^~~~~~~~~ common/page_alloc.c:260:1: note: in expansion of macro ‘STATIC_IF’ 260 | STATIC_IF(CONFIG_NUMA) mfn_t first_valid_mfn = INVALID_MFN_INITIALIZER; | ^~~~~~~~~ make[2]: *** [Rules.mk:249: common/page_alloc.o] Error 1 >> --- a/xen/include/xen/list.h >> +++ b/xen/include/xen/list.h >> @@ -490,9 +490,9 @@ static inline void list_splice_init(struct >> list_head *list, >> * @member: the name of the list_struct within the struct. >> */ >> #define list_for_each_entry(pos, head, member) >> \ >> - for (pos = list_entry((head)->next, typeof(*pos), member); >> \ >> - &pos->member != (head); >> \ >> - pos = list_entry(pos->member.next, typeof(*pos), member)) >> + for (pos = list_entry((head)->next, typeof(*(pos)), member); >> \ >> + &(pos)->member != (head); >> \ >> + pos = list_entry((pos)->member.next, typeof(*(pos)), >> member)) > > this ends up inconsistent, which I think isn't nice: Some uses of "pos" > are now parenthesized, while others aren't. Applies further down as > well. > Yeah, the inconsistency is due to the fact that a non-parenthesized parameter as lhs is already deviated. To keep it consistent here I can add parentheses, but then the deviation would be kind of pointless, wouldn't it? > You may also want to take this as a strong suggestion to split > dissimilar > changes, so uncontroversial parts can go in. > Ok, that was an oversight. >> @@ -977,4 +977,3 @@ static inline void hlist_add_after_rcu(struct >> hlist_node *prev, >> pos = pos->next) >> >> #endif /* __XEN_LIST_H__ */ >> - > > Unrelated change? > Oh, yes. Will drop it. >> --- a/xen/include/xen/spinlock.h >> +++ b/xen/include/xen/spinlock.h >> @@ -94,7 +94,7 @@ struct lock_profile_qhead { >> int32_t idx; /* index for printout */ >> }; >> >> -#define _LOCK_PROFILE(lockname) { .name = #lockname, .lock = >> &lockname, } >> +#define _LOCK_PROFILE(lockname) { .name = #lockname, .lock = >> &(lockname), } > > This also may be viewed as falling in the same category, but is less > problematic because the other use is stringification, when in principle > some kind of expression would be passed in (albeit in practice I don't > expect anyone would do that). >
On 29.02.2024 17:40, Nicola Vetrini wrote: > On 2024-02-29 17:25, Jan Beulich wrote: >> On 29.02.2024 16:27, Nicola Vetrini wrote: >>> --- a/xen/include/xen/kconfig.h >>> +++ b/xen/include/xen/kconfig.h >>> @@ -25,7 +25,7 @@ >>> #define __ARG_PLACEHOLDER_1 0, >>> #define config_enabled(cfg) _config_enabled(cfg) >>> #define _config_enabled(value) >>> __config_enabled(__ARG_PLACEHOLDER_##value) >>> -#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk >>> 1, 0) >>> +#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk >>> (1), (0)) >>> #define ___config_enabled(__ignored, val, ...) val >> >> In addition to what Andrew said, would you mind clarifying what exactly >> the >> violation is here? I find it questionable that numeric literals need >> parenthesizing; they don't normally need to, aynwhere. >> > > This one's a little special. I couldn't parenthesize val further down, > because then it would break the build: > > In file included from ././include/xen/config.h:14, > from <command-line>: > ./include/xen/kconfig.h:29:52: error: expected identifier or ‘(’ before > ‘)’ token > 29 | #define ___config_enabled(__ignored, val, ...) (val) > | ^ > ./include/xen/kconfig.h:39:34: note: in expansion of macro > ‘___config_enabled’ > 39 | #define _static_if(arg1_or_junk) ___config_enabled(arg1_or_junk > static,) > | ^~~~~~~~~~~~~~~~~ > ./include/xen/kconfig.h:38:26: note: in expansion of macro ‘_static_if’ > 38 | #define static_if(value) _static_if(__ARG_PLACEHOLDER_##value) > | ^~~~~~~~~~ > ./include/xen/kconfig.h:41:27: note: in expansion of macro ‘static_if’ > 41 | #define STATIC_IF(option) static_if(option) > | ^~~~~~~~~ > common/page_alloc.c:260:1: note: in expansion of macro ‘STATIC_IF’ > 260 | STATIC_IF(CONFIG_NUMA) mfn_t first_valid_mfn = > INVALID_MFN_INITIALIZER; > | ^~~~~~~~~ > make[2]: *** [Rules.mk:249: common/page_alloc.o] Error 1 So if we're not gong to deviate the construct, then this change needs to come entirely on its own, with a really good description. >>> --- a/xen/include/xen/list.h >>> +++ b/xen/include/xen/list.h >>> @@ -490,9 +490,9 @@ static inline void list_splice_init(struct >>> list_head *list, >>> * @member: the name of the list_struct within the struct. >>> */ >>> #define list_for_each_entry(pos, head, member) >>> \ >>> - for (pos = list_entry((head)->next, typeof(*pos), member); >>> \ >>> - &pos->member != (head); >>> \ >>> - pos = list_entry(pos->member.next, typeof(*pos), member)) >>> + for (pos = list_entry((head)->next, typeof(*(pos)), member); >>> \ >>> + &(pos)->member != (head); >>> \ >>> + pos = list_entry((pos)->member.next, typeof(*(pos)), >>> member)) >> >> this ends up inconsistent, which I think isn't nice: Some uses of "pos" >> are now parenthesized, while others aren't. Applies further down as >> well. >> > > Yeah, the inconsistency is due to the fact that a non-parenthesized > parameter as lhs is already deviated. To keep it consistent here I can > add parentheses, but then the deviation would be kind of pointless, > wouldn't it? I don't think so: It would still be useful for cases where a macro parameter is used solely as the lhs of some kind of assignment operator. But yes, before making adjustments you will want to wait for possible further comments, especially from e.g. Julien, who iirc was primarily against this kind of parenthesization. Jan
On 29/02/2024 4:21 pm, Nicola Vetrini wrote: > On 2024-02-29 17:10, Andrew Cooper wrote: >> On 29/02/2024 3:27 pm, Nicola Vetrini wrote: >>> diff --git a/xen/include/xen/kconfig.h b/xen/include/xen/kconfig.h >>> index c25dc0f6c2a9..b7e70289737b 100644 >>> --- a/xen/include/xen/kconfig.h >>> +++ b/xen/include/xen/kconfig.h >>> @@ -25,7 +25,7 @@ >>> #define __ARG_PLACEHOLDER_1 0, >>> #define config_enabled(cfg) _config_enabled(cfg) >>> #define _config_enabled(value) >>> __config_enabled(__ARG_PLACEHOLDER_##value) >>> -#define __config_enabled(arg1_or_junk) >>> ___config_enabled(arg1_or_junk 1, 0) >>> +#define __config_enabled(arg1_or_junk) >>> ___config_enabled(arg1_or_junk (1), (0)) >>> #define ___config_enabled(__ignored, val, ...) val >> >> This one hunk I suggest we deviate rather than adjust. You've subtly >> broken it, and it's extreme preprocessor magic in the first place to >> turn an absent symbol into a 0. >> > > How so? I did test this because I was very wary of it, but it seemed > to expand fine (either if ((0)) or if ((1)) ). I may of course be > wrong, and it could be deviated regardless. > arg1_or_junk(1) can now be a function or macro expansion depending on context, where previously it couldn't be. ~Andrew
On 2024-02-29 17:47, Andrew Cooper wrote: > On 29/02/2024 4:21 pm, Nicola Vetrini wrote: >> On 2024-02-29 17:10, Andrew Cooper wrote: >>> On 29/02/2024 3:27 pm, Nicola Vetrini wrote: >>>> diff --git a/xen/include/xen/kconfig.h b/xen/include/xen/kconfig.h >>>> index c25dc0f6c2a9..b7e70289737b 100644 >>>> --- a/xen/include/xen/kconfig.h >>>> +++ b/xen/include/xen/kconfig.h >>>> @@ -25,7 +25,7 @@ >>>> #define __ARG_PLACEHOLDER_1 0, >>>> #define config_enabled(cfg) _config_enabled(cfg) >>>> #define _config_enabled(value) >>>> __config_enabled(__ARG_PLACEHOLDER_##value) >>>> -#define __config_enabled(arg1_or_junk) >>>> ___config_enabled(arg1_or_junk 1, 0) >>>> +#define __config_enabled(arg1_or_junk) >>>> ___config_enabled(arg1_or_junk (1), (0)) >>>> #define ___config_enabled(__ignored, val, ...) val >>> >>> This one hunk I suggest we deviate rather than adjust. You've subtly >>> broken it, and it's extreme preprocessor magic in the first place to >>> turn an absent symbol into a 0. >>> >> >> How so? I did test this because I was very wary of it, but it seemed >> to expand fine (either if ((0)) or if ((1)) ). I may of course be >> wrong, and it could be deviated regardless. >> > > arg1_or_junk(1) can now be a function or macro expansion depending on > context, where previously it couldn't be. > I see, that would be a latent bug. I do agree on deviating then.
diff --git a/xen/include/xen/bug.h b/xen/include/xen/bug.h index 2c45c462fc63..77fe1e1ba840 100644 --- a/xen/include/xen/bug.h +++ b/xen/include/xen/bug.h @@ -80,7 +80,7 @@ struct bug_frame { [bf_type] "i" (type), \ [bf_ptr] "i" (ptr), \ [bf_msg] "i" (msg), \ - [bf_line_lo] "i" ((line & ((1 << BUG_LINE_LO_WIDTH) - 1)) \ + [bf_line_lo] "i" (((line) & ((1 << BUG_LINE_LO_WIDTH) - 1)) \ << BUG_DISP_WIDTH), \ [bf_line_hi] "i" (((line) >> BUG_LINE_LO_WIDTH) << BUG_DISP_WIDTH) diff --git a/xen/include/xen/init.h b/xen/include/xen/init.h index 1d7c0216bc80..0a4223833755 100644 --- a/xen/include/xen/init.h +++ b/xen/include/xen/init.h @@ -63,9 +63,9 @@ typedef int (*initcall_t)(void); typedef void (*exitcall_t)(void); #define presmp_initcall(fn) \ - const static initcall_t __initcall_##fn __init_call("presmp") = fn + const static initcall_t __initcall_##fn __init_call("presmp") = (fn) #define __initcall(fn) \ - const static initcall_t __initcall_##fn __init_call("1") = fn + const static initcall_t __initcall_##fn __init_call("1") = (fn) #define __exitcall(fn) \ static exitcall_t __exitcall_##fn __exit_call = fn diff --git a/xen/include/xen/kconfig.h b/xen/include/xen/kconfig.h index c25dc0f6c2a9..b7e70289737b 100644 --- a/xen/include/xen/kconfig.h +++ b/xen/include/xen/kconfig.h @@ -25,7 +25,7 @@ #define __ARG_PLACEHOLDER_1 0, #define config_enabled(cfg) _config_enabled(cfg) #define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value) -#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0) +#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk (1), (0)) #define ___config_enabled(__ignored, val, ...) val /* diff --git a/xen/include/xen/list.h b/xen/include/xen/list.h index b5eab3a1eb6c..d803e7848cad 100644 --- a/xen/include/xen/list.h +++ b/xen/include/xen/list.h @@ -490,9 +490,9 @@ static inline void list_splice_init(struct list_head *list, * @member: the name of the list_struct within the struct. */ #define list_for_each_entry(pos, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = list_entry(pos->member.next, typeof(*pos), member)) + for (pos = list_entry((head)->next, typeof(*(pos)), member); \ + &(pos)->member != (head); \ + pos = list_entry((pos)->member.next, typeof(*(pos)), member)) /** * list_for_each_entry_reverse - iterate backwards over list of given type. @@ -501,9 +501,9 @@ static inline void list_splice_init(struct list_head *list, * @member: the name of the list_struct within the struct. */ #define list_for_each_entry_reverse(pos, head, member) \ - for (pos = list_entry((head)->prev, typeof(*pos), member); \ - &pos->member != (head); \ - pos = list_entry(pos->member.prev, typeof(*pos), member)) + for (pos = list_entry((head)->prev, typeof(*(pos)), member); \ + &(pos)->member != (head); \ + pos = list_entry((pos)->member.prev, typeof(*(pos)), member)) /** * list_prepare_entry - prepare a pos entry for use in @@ -516,7 +516,7 @@ static inline void list_splice_init(struct list_head *list, * list_for_each_entry_continue. */ #define list_prepare_entry(pos, head, member) \ - ((pos) ? : list_entry(head, typeof(*pos), member)) + ((pos) ? : list_entry(head, typeof(*(pos)), member)) /** * list_for_each_entry_continue - continue iteration over list of given type @@ -528,9 +528,9 @@ static inline void list_splice_init(struct list_head *list, * the current position. */ #define list_for_each_entry_continue(pos, head, member) \ - for (pos = list_entry(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = list_entry(pos->member.next, typeof(*pos), member)) + for (pos = list_entry((pos)->member.next, typeof(*(pos)), member); \ + &(pos)->member != (head); \ + pos = list_entry((pos)->member.next, typeof(*(pos)), member)) /** * list_for_each_entry_from - iterate over list of given type from the @@ -542,8 +542,8 @@ static inline void list_splice_init(struct list_head *list, * Iterate over list of given type, continuing from current position. */ #define list_for_each_entry_from(pos, head, member) \ - for (; &pos->member != (head); \ - pos = list_entry(pos->member.next, typeof(*pos), member)) + for (; &(pos)->member != (head); \ + pos = list_entry((pos)->member.next, typeof(*(pos)), member)) /** * list_for_each_entry_safe - iterate over list of given type safe @@ -554,10 +554,10 @@ static inline void list_splice_init(struct list_head *list, * @member: the name of the list_struct within the struct. */ #define list_for_each_entry_safe(pos, n, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member), \ - n = list_entry(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = n, n = list_entry(n->member.next, typeof(*n), member)) + for (pos = list_entry((head)->next, typeof(*(pos)), member), \ + n = list_entry((pos)->member.next, typeof(*(pos)), member); \ + &(pos)->member != (head); \ + pos = (n), n = list_entry((n)->member.next, typeof(*(n)), member)) /** * list_for_each_entry_safe_continue @@ -570,10 +570,10 @@ static inline void list_splice_init(struct list_head *list, * safe against removal of list entry. */ #define list_for_each_entry_safe_continue(pos, n, head, member) \ - for (pos = list_entry(pos->member.next, typeof(*pos), member), \ - n = list_entry(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = n, n = list_entry(n->member.next, typeof(*n), member)) + for (pos = list_entry((pos)->member.next, typeof(*(pos)), member), \ + n = list_entry((pos)->member.next, typeof(*(pos)), member); \ + &(pos)->member != (head); \ + pos = (n), n = list_entry((n)->member.next, typeof(*(n)), member)) /** * list_for_each_entry_safe_from @@ -586,9 +586,9 @@ static inline void list_splice_init(struct list_head *list, * removal of list entry. */ #define list_for_each_entry_safe_from(pos, n, head, member) \ - for (n = list_entry(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = n, n = list_entry(n->member.next, typeof(*n), member)) + for (n = list_entry((pos)->member.next, typeof(*(pos)), member); \ + &(pos)->member != (head); \ + pos = (n), n = list_entry((n)->member.next, typeof(*(n)), member)) /** * list_for_each_entry_safe_reverse @@ -601,10 +601,10 @@ static inline void list_splice_init(struct list_head *list, * of list entry. */ #define list_for_each_entry_safe_reverse(pos, n, head, member) \ - for (pos = list_entry((head)->prev, typeof(*pos), member), \ - n = list_entry(pos->member.prev, typeof(*pos), member); \ - &pos->member != (head); \ - pos = n, n = list_entry(n->member.prev, typeof(*n), member)) + for (pos = list_entry((head)->prev, typeof(*(pos)), member), \ + n = list_entry((pos)->member.prev, typeof(*(pos)), member); \ + &(pos)->member != (head); \ + pos = (n), n = list_entry((n)->member.prev, typeof(*(n)), member)) /** * list_for_each_rcu - iterate over an rcu-protected list @@ -653,9 +653,9 @@ static inline void list_splice_init(struct list_head *list, * as long as the traversal is guarded by rcu_read_lock(). */ #define list_for_each_entry_rcu(pos, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member); \ + for (pos = list_entry((head)->next, typeof(*(pos)), member); \ &rcu_dereference(pos)->member != (head); \ - pos = list_entry(pos->member.next, typeof(*pos), member)) + pos = list_entry((pos)->member.next, typeof(*(pos)), member)) /** * list_for_each_continue_rcu @@ -977,4 +977,3 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev, pos = pos->next) #endif /* __XEN_LIST_H__ */ - diff --git a/xen/include/xen/param.h b/xen/include/xen/param.h index 13607e0e50e0..1bdbab34ab1f 100644 --- a/xen/include/xen/param.h +++ b/xen/include/xen/param.h @@ -45,42 +45,42 @@ extern const struct kernel_param __setup_start[], __setup_end[]; #define TEMP_NAME(base) _TEMP_NAME(base, __LINE__) #define custom_param(_name, _var) \ - __setup_str __setup_str_##_var[] = _name; \ + __setup_str __setup_str_##_var[] = (_name); \ __kparam __setup_##_var = \ { .name = __setup_str_##_var, \ .type = OPT_CUSTOM, \ - .par.func = _var } + .par.func = (_var) } #define boolean_param(_name, _var) \ - __setup_str __setup_str_##_var[] = _name; \ + __setup_str __setup_str_##_var[] = (_name); \ __kparam __setup_##_var = \ { .name = __setup_str_##_var, \ .type = OPT_BOOL, \ .len = sizeof(_var) + \ BUILD_BUG_ON_ZERO(sizeof(_var) != sizeof(bool)), \ - .par.var = &_var } + .par.var = &(_var) } #define integer_param(_name, _var) \ - __setup_str __setup_str_##_var[] = _name; \ + __setup_str __setup_str_##_var[] = (_name); \ __kparam __setup_##_var = \ { .name = __setup_str_##_var, \ .type = OPT_UINT, \ .len = sizeof(_var), \ - .par.var = &_var } + .par.var = &(_var) } #define size_param(_name, _var) \ - __setup_str __setup_str_##_var[] = _name; \ + __setup_str __setup_str_##_var[] = (_name); \ __kparam __setup_##_var = \ { .name = __setup_str_##_var, \ .type = OPT_SIZE, \ .len = sizeof(_var), \ - .par.var = &_var } + .par.var = &(_var) } #define string_param(_name, _var) \ - __setup_str __setup_str_##_var[] = _name; \ + __setup_str __setup_str_##_var[] = (_name); \ __kparam __setup_##_var = \ { .name = __setup_str_##_var, \ .type = OPT_STR, \ .len = sizeof(_var), \ - .par.var = &_var } + .par.var = &(_var) } #define ignore_param(_name) \ - __setup_str TEMP_NAME(__setup_str_ign)[] = _name; \ + __setup_str TEMP_NAME(__setup_str_ign)[] = (_name); \ __kparam TEMP_NAME(__setup_ign) = \ { .name = TEMP_NAME(__setup_str_ign), \ .type = OPT_IGNORE } diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 1cd9120eac7a..0e6a083dfb9e 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -94,7 +94,7 @@ struct lock_profile_qhead { int32_t idx; /* index for printout */ }; -#define _LOCK_PROFILE(lockname) { .name = #lockname, .lock = &lockname, } +#define _LOCK_PROFILE(lockname) { .name = #lockname, .lock = &(lockname), } #define _LOCK_PROFILE_PTR(name) \ static struct lock_profile * const __lock_profile_##name \ __used_section(".lockprofile.data") = \
MISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses". Therefore, some macro definitions should gain additional parentheses to ensure that all current and future users will be safe with respect to expansions that can possibly alter the semantics of the passed-in macro parameter. No functional change. Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com> --- xen/include/xen/bug.h | 2 +- xen/include/xen/init.h | 4 +-- xen/include/xen/kconfig.h | 2 +- xen/include/xen/list.h | 59 +++++++++++++++++++------------------- xen/include/xen/param.h | 22 +++++++------- xen/include/xen/spinlock.h | 2 +- 6 files changed, 45 insertions(+), 46 deletions(-)