mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* do not initialise globals to 0 or NULL\n
@ 2015-05-29  3:41 Bandan Das
  2015-05-29  9:12 ` [PATCH] checkpatch: Fix "GLOBAL_INITIALISERS" test Joe Perches
  0 siblings, 1 reply; 2+ messages in thread
From: Bandan Das @ 2015-05-29  3:41 UTC (permalink / raw)
  To: joe; +Cc: linux-kernel

Hi Joe,

Sorry, I am very Perl illiterate but I was deliberately trying to hit the
"do not initialize globals" message from checkpatch.pl and can't seem to.

Looking at the corresponding regexp, it seems the correct pattern should be:

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 89b1df4..d076d39 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3169,7 +3169,7 @@ sub process {
                }
 
 # check for global initialisers.
-               if ($line =~ /^\+(\s*$Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/) {
+               if ($line =~ /^\+(\s*$Type\s*$Ident\s*(?:\s+$Modifier)*)\s*=\s*(0|NULL|false)\s*;/) {
                        if (ERROR("GLOBAL_INITIALISERS",
                                  "do not initialise globals to 0 or NULL\n" .
                                      $herecurr) &&

which matches zero or more of $Modifier followed by zero or more of a space.
Or am I missing something ?

Thanks,
Bandan

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

* [PATCH] checkpatch: Fix "GLOBAL_INITIALISERS" test
  2015-05-29  3:41 do not initialise globals to 0 or NULL\n Bandan Das
@ 2015-05-29  9:12 ` Joe Perches
  0 siblings, 0 replies; 2+ messages in thread
From: Joe Perches @ 2015-05-29  9:12 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Bandan Das, Andy Whitcroft, linux-kernel

commit d5e616fc1c1d ("checkpatch: add a few more --fix corrections")
broke the GLOBAL_INITIALISERS test with bad parentheses and optional
leading spaces.

Fix it.

Reported-by: Bandan Das <bsd@makefile.in>
Signed-off-by: Joe Perches <joe@perches.com>
---
On Thu, 2015-05-28 at 23:41 -0400, Bandan Das wrote:
> Hi Joe,

Hi Bandan.

> Sorry, I am very Perl illiterate but I was deliberately trying to hit the
> "do not initialize globals" message from checkpatch.pl and can't seem to.
> 
> Looking at the corresponding regexp, it seems the correct pattern should be:
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -3169,7 +3169,7 @@ sub process {
>                 }
>  
>  # check for global initialisers.
> -               if ($line =~ /^\+(\s*$Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/) {
> +               if ($line =~ /^\+(\s*$Type\s*$Ident\s*(?:\s+$Modifier)*)\s*=\s*(0|NULL|false)\s*;/) {
>                         if (ERROR("GLOBAL_INITIALISERS",
>                                   "do not initialise globals to 0 or NULL\n" .
>                                       $herecurr) &&
> 
> which matches zero or more of $Modifier followed by zero or more of a space.
> Or am I missing something ?

No, you're right, thanks, but the proper fix is a bit more
than that and it's below.

 scripts/checkpatch.pl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4650c04..e46414d 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3176,12 +3176,12 @@ sub process {
 		}
 
 # check for global initialisers.
-		if ($line =~ /^\+(\s*$Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/) {
+		if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*(?:0|NULL|false)\s*;/) {
 			if (ERROR("GLOBAL_INITIALISERS",
 				  "do not initialise globals to 0 or NULL\n" .
 				      $herecurr) &&
 			    $fix) {
-				$fixed[$fixlinenr] =~ s/($Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/$1;/;
+				$fixed[$fixlinenr] =~ s/(^.$Type\s*$Ident(?:\s+$Modifier)*)\s*=\s*(0|NULL|false)\s*;/$1;/;
 			}
 		}
 # check for static initialisers.




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

end of thread, other threads:[~2015-05-29  9:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-29  3:41 do not initialise globals to 0 or NULL\n Bandan Das
2015-05-29  9:12 ` [PATCH] checkpatch: Fix "GLOBAL_INITIALISERS" test Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®