linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] audit: avoid -Wempty-body warning
@ 2021-03-22 11:45 Arnd Bergmann
  2021-03-22 14:33 ` Richard Guy Briggs
  0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2021-03-22 11:45 UTC (permalink / raw)
  To: Paul Moore, Eric Paris
  Cc: Arnd Bergmann, Richard Guy Briggs, Jules Irenge, linux-audit,
	linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

gcc warns about an empty statement when audit_remove_mark is defined to
nothing:

kernel/auditfilter.c: In function 'audit_data_to_entry':
kernel/auditfilter.c:609:51: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
  609 |                 audit_remove_mark(entry->rule.exe); /* that's the template one */
      |                                                   ^

Change the macros to use the usual "do { } while (0)" instead, and change a
few more that were (void)0, for consistency.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 kernel/audit.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/audit.h b/kernel/audit.h
index 3b9c0945225a..c39c5f3b8422 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -302,8 +302,8 @@ extern struct list_head *audit_killed_trees(void);
 
 #define audit_alloc_mark(k, p, l) (ERR_PTR(-EINVAL))
 #define audit_mark_path(m) ""
-#define audit_remove_mark(m)
-#define audit_remove_mark_rule(k)
+#define audit_remove_mark(m) do { } while (0)
+#define audit_remove_mark_rule(k) do { } while (0)
 #define audit_mark_compare(m, i, d) 0
 #define audit_exe_compare(t, m) (-EINVAL)
 #define audit_dupe_exe(n, o) (-EINVAL)
@@ -311,8 +311,8 @@ extern struct list_head *audit_killed_trees(void);
 #define audit_remove_tree_rule(rule) BUG()
 #define audit_add_tree_rule(rule) -EINVAL
 #define audit_make_tree(rule, str, op) -EINVAL
-#define audit_trim_trees() (void)0
-#define audit_put_tree(tree) (void)0
+#define audit_trim_trees() do { } while (0)
+#define audit_put_tree(tree) do { } while (0)
 #define audit_tag_tree(old, new) -EINVAL
 #define audit_tree_path(rule) ""	/* never called */
 #define audit_kill_trees(context) BUG()
-- 
2.29.2


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

* Re: [PATCH] audit: avoid -Wempty-body warning
  2021-03-22 11:45 [PATCH] audit: avoid -Wempty-body warning Arnd Bergmann
@ 2021-03-22 14:33 ` Richard Guy Briggs
  2021-03-22 16:28   ` Arnd Bergmann
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Guy Briggs @ 2021-03-22 14:33 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Paul Moore, Eric Paris, Arnd Bergmann, Jules Irenge, linux-audit,
	linux-kernel

On 2021-03-22 12:45, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
> 
> gcc warns about an empty statement when audit_remove_mark is defined to
> nothing:
> 
> kernel/auditfilter.c: In function 'audit_data_to_entry':
> kernel/auditfilter.c:609:51: error: suggest braces around empty body in an 'if' statement [-Werror=empty-body]
>   609 |                 audit_remove_mark(entry->rule.exe); /* that's the template one */
>       |                                                   ^
> 
> Change the macros to use the usual "do { } while (0)" instead, and change a
> few more that were (void)0, for consistency.

So what about audit_put_watch() and audit_get_watch() which are set to
{}?   (And all of include/linux/audit.h that uses the latter...)  Does
this only matter if they are the only action called in an if or loop?

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  kernel/audit.h | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/audit.h b/kernel/audit.h
> index 3b9c0945225a..c39c5f3b8422 100644
> --- a/kernel/audit.h
> +++ b/kernel/audit.h
> @@ -302,8 +302,8 @@ extern struct list_head *audit_killed_trees(void);
>  
>  #define audit_alloc_mark(k, p, l) (ERR_PTR(-EINVAL))
>  #define audit_mark_path(m) ""
> -#define audit_remove_mark(m)
> -#define audit_remove_mark_rule(k)
> +#define audit_remove_mark(m) do { } while (0)
> +#define audit_remove_mark_rule(k) do { } while (0)
>  #define audit_mark_compare(m, i, d) 0
>  #define audit_exe_compare(t, m) (-EINVAL)
>  #define audit_dupe_exe(n, o) (-EINVAL)
> @@ -311,8 +311,8 @@ extern struct list_head *audit_killed_trees(void);
>  #define audit_remove_tree_rule(rule) BUG()
>  #define audit_add_tree_rule(rule) -EINVAL
>  #define audit_make_tree(rule, str, op) -EINVAL
> -#define audit_trim_trees() (void)0
> -#define audit_put_tree(tree) (void)0
> +#define audit_trim_trees() do { } while (0)
> +#define audit_put_tree(tree) do { } while (0)
>  #define audit_tag_tree(old, new) -EINVAL
>  #define audit_tree_path(rule) ""	/* never called */
>  #define audit_kill_trees(context) BUG()
> -- 
> 2.29.2
> 

- RGB

--
Richard Guy Briggs <rgb@redhat.com>
Sr. S/W Engineer, Kernel Security, Base Operating Systems
Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635


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

* Re: [PATCH] audit: avoid -Wempty-body warning
  2021-03-22 14:33 ` Richard Guy Briggs
@ 2021-03-22 16:28   ` Arnd Bergmann
  2021-03-22 17:58     ` Richard Guy Briggs
  0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2021-03-22 16:28 UTC (permalink / raw)
  To: Richard Guy Briggs
  Cc: Paul Moore, Eric Paris, Jules Irenge, linux-audit,
	Linux Kernel Mailing List

On Mon, Mar 22, 2021 at 3:33 PM Richard Guy Briggs <rgb@redhat.com> wrote:

> > Change the macros to use the usual "do { } while (0)" instead, and change a
> > few more that were (void)0, for consistency.
>
> So what about audit_put_watch() and audit_get_watch() which are set to
> {}?   (And all of include/linux/audit.h that uses the latter...)  Does
> this only matter if they are the only action called in an if or loop?
>

I missed those, thanks for pointing it out. I sent a v2 patch now.

         Arnd

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

* Re: [PATCH] audit: avoid -Wempty-body warning
  2021-03-22 16:28   ` Arnd Bergmann
@ 2021-03-22 17:58     ` Richard Guy Briggs
  2021-03-22 18:24       ` Arnd Bergmann
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Guy Briggs @ 2021-03-22 17:58 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Paul Moore, Eric Paris, Jules Irenge, linux-audit,
	Linux Kernel Mailing List

On 2021-03-22 17:28, Arnd Bergmann wrote:
> On Mon, Mar 22, 2021 at 3:33 PM Richard Guy Briggs <rgb@redhat.com> wrote:
> > > Change the macros to use the usual "do { } while (0)" instead, and change a
> > > few more that were (void)0, for consistency.
> >
> > So what about audit_put_watch() and audit_get_watch() which are set to
> > {}?   (And all of include/linux/audit.h that uses the latter...)  Does
> > this only matter if they are the only action called in an if or loop?
> 
> I missed those, thanks for pointing it out. I sent a v2 patch now.

Ok, cool, that looks more consistent.  Can you answer my question about
include/linux/audit.h and exactly what conditions require
"do { } while (0)" over "{ }"?

>          Arnd

- RGB

--
Richard Guy Briggs <rgb@redhat.com>
Sr. S/W Engineer, Kernel Security, Base Operating Systems
Remote, Ottawa, Red Hat Canada
IRC: rgb, SunRaycer
Voice: +1.647.777.2635, Internal: (81) 32635


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

* Re: [PATCH] audit: avoid -Wempty-body warning
  2021-03-22 17:58     ` Richard Guy Briggs
@ 2021-03-22 18:24       ` Arnd Bergmann
  0 siblings, 0 replies; 5+ messages in thread
From: Arnd Bergmann @ 2021-03-22 18:24 UTC (permalink / raw)
  To: Richard Guy Briggs
  Cc: Paul Moore, Eric Paris, Jules Irenge, linux-audit,
	Linux Kernel Mailing List

On Mon, Mar 22, 2021 at 6:58 PM Richard Guy Briggs <rgb@redhat.com> wrote:
>
> On 2021-03-22 17:28, Arnd Bergmann wrote:
> > On Mon, Mar 22, 2021 at 3:33 PM Richard Guy Briggs <rgb@redhat.com> wrote:
> > > > Change the macros to use the usual "do { } while (0)" instead, and change a
> > > > few more that were (void)0, for consistency.
> > >
> > > So what about audit_put_watch() and audit_get_watch() which are set to
> > > {}?   (And all of include/linux/audit.h that uses the latter...)  Does
> > > this only matter if they are the only action called in an if or loop?
> >
> > I missed those, thanks for pointing it out. I sent a v2 patch now.
>
> Ok, cool, that looks more consistent.  Can you answer my question about
> include/linux/audit.h and exactly what conditions require
> "do { } while (0)" over "{ }"?

This is the usual way of constructing a C expression that can be used
e.g. in

   if (x)
          foo();
   else
          bar();

If foo() is defined as '{}', this causes a syntax error.

         Arnd

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

end of thread, other threads:[~2021-03-22 18:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22 11:45 [PATCH] audit: avoid -Wempty-body warning Arnd Bergmann
2021-03-22 14:33 ` Richard Guy Briggs
2021-03-22 16:28   ` Arnd Bergmann
2021-03-22 17:58     ` Richard Guy Briggs
2021-03-22 18:24       ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).