[PATCH] audit: remove redundant initialization of static variables to 0

Ricardo Robaina posted 1 patch 1 month, 1 week ago
kernel/audit.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] audit: remove redundant initialization of static variables to 0
Posted by Ricardo Robaina 1 month, 1 week ago
Static variables are automatically initialized to 0 by the compiler.
Remove the redundant explicit assignments in kernel/audit.c to clean
up the code, align with standard kernel coding style, and fix the
following checkpatch.pl errors:

 ./scripts/checkpatch.pl kernel/audit.c | grep -A2 ERROR:
 ERROR: do not initialise statics to 0
 +	static unsigned long	last_check = 0;
 --
 ERROR: do not initialise statics to 0
 +	static int		messages   = 0;
 --
 ERROR: do not initialise statics to 0
 +	static unsigned long	last_msg = 0;

Signed-off-by: Ricardo Robaina <rrobaina@redhat.com>
---
 kernel/audit.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/audit.c b/kernel/audit.c
index 5a0216056524..08793e71b975 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -355,8 +355,8 @@ void audit_panic(const char *message)
 
 static inline int audit_rate_check(void)
 {
-	static unsigned long	last_check = 0;
-	static int		messages   = 0;
+	static unsigned long	last_check;
+	static int		messages;
 	static DEFINE_SPINLOCK(lock);
 	unsigned long		flags;
 	unsigned long		now;
@@ -391,7 +391,7 @@ static inline int audit_rate_check(void)
 */
 void audit_log_lost(const char *message)
 {
-	static unsigned long	last_msg = 0;
+	static unsigned long	last_msg;
 	static DEFINE_SPINLOCK(lock);
 	unsigned long		flags;
 	unsigned long		now;
-- 
2.53.0
Re: [PATCH] audit: remove redundant initialization of static variables to 0
Posted by Paul Moore 1 month ago
On Feb 26, 2026 Ricardo Robaina <rrobaina@redhat.com> wrote:
> 
> Static variables are automatically initialized to 0 by the compiler.
> Remove the redundant explicit assignments in kernel/audit.c to clean
> up the code, align with standard kernel coding style, and fix the
> following checkpatch.pl errors:
> 
>  ./scripts/checkpatch.pl kernel/audit.c | grep -A2 ERROR:
>  ERROR: do not initialise statics to 0
>  +	static unsigned long	last_check = 0;
>  --
>  ERROR: do not initialise statics to 0
>  +	static int		messages   = 0;
>  --
>  ERROR: do not initialise statics to 0
>  +	static unsigned long	last_msg = 0;
> 
> Signed-off-by: Ricardo Robaina <rrobaina@redhat.com>
> ---
>  kernel/audit.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Merged into audit/dev, thanks.

--
paul-moore.com
Re: [PATCH] audit: remove redundant initialization of static variables to 0
Posted by Ricardo Robaina 1 month ago
On Mon, Mar 2, 2026 at 6:40 PM Paul Moore <paul@paul-moore.com> wrote:
>
> On Feb 26, 2026 Ricardo Robaina <rrobaina@redhat.com> wrote:
> >
> > Static variables are automatically initialized to 0 by the compiler.
> > Remove the redundant explicit assignments in kernel/audit.c to clean
> > up the code, align with standard kernel coding style, and fix the
> > following checkpatch.pl errors:
> >
> >  ./scripts/checkpatch.pl kernel/audit.c | grep -A2 ERROR:
> >  ERROR: do not initialise statics to 0
> >  +    static unsigned long    last_check = 0;
> >  --
> >  ERROR: do not initialise statics to 0
> >  +    static int              messages   = 0;
> >  --
> >  ERROR: do not initialise statics to 0
> >  +    static unsigned long    last_msg = 0;
> >
> > Signed-off-by: Ricardo Robaina <rrobaina@redhat.com>
> > ---
> >  kernel/audit.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
>
> Merged into audit/dev, thanks.
>
> --
> paul-moore.com
>

Thanks, Paul!