All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Julia Lawall <julia.lawall@lip6.fr>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Minchan Kim <minchan@kernel.org>,
	Christoph Lameter <cl@linux.com>,
	Pekka Enberg <penberg@kernel.org>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Michal Hocko <mhocko@suse.cz>,
	David Rientjes <rientjes@google.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	sergey.senozhatsky.work@gmail.com
Subject: [PATCH V2] checkpatch: Add some <foo>_destroy functions to NEEDLESS_IF tests
Date: Tue, 09 Jun 2015 22:52:29 -0700	[thread overview]
Message-ID: <1433915549.2730.107.camel@perches.com> (raw)
In-Reply-To: <1433911166.2730.98.camel@perches.com>

Sergey Senozhatsky has modified several destroy functions that can
now be called with NULL values.

 - kmem_cache_destroy()
 - mempool_destroy()
 - dma_pool_destroy()

Update checkpatch to warn when those functions are preceded by an if.

Update checkpatch to --fix all the calls too only when the code style
form is using leading tabs.

from:
	if (foo)
		<func>(foo);
to:
	<func>(foo);

Signed-off-by: Joe Perches <joe@perches.com>
---
V2: Remove useless debugging print messages and multiple quotemetas

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

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 69c4716..87d3bf1aa 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4800,10 +4800,34 @@ sub process {
 
 # check for needless "if (<foo>) fn(<foo>)" uses
 		if ($prevline =~ /\bif\s*\(\s*($Lval)\s*\)/) {
-			my $expr = '\s*\(\s*' . quotemeta($1) . '\s*\)\s*;';
-			if ($line =~ /\b(kfree|usb_free_urb|debugfs_remove(?:_recursive)?)$expr/) {
-				WARN('NEEDLESS_IF',
-				     "$1(NULL) is safe and this check is probably not required\n" . $hereprev);
+			my $tested = quotemeta($1);
+			my $expr = '\s*\(\s*' . $tested . '\s*\)\s*;';
+			if ($line =~ /\b(kfree|usb_free_urb|debugfs_remove(?:_recursive)?|(?:kmem_cache|mempool|dma_pool)_destroy)$expr/) {
+				my $func = $1;
+				if (WARN('NEEDLESS_IF',
+					 "$func(NULL) is safe and this check is probably not required\n" . $hereprev) &&
+				    $fix) {
+					my $do_fix = 1;
+					my $leading_tabs = "";
+					my $new_leading_tabs = "";
+					if ($lines[$linenr - 2] =~ /^\+(\t*)if\s*\(\s*$tested\s*\)\s*$/) {
+						$leading_tabs = $1;
+					} else {
+						$do_fix = 0;
+					}
+					if ($lines[$linenr - 1] =~ /^\+(\t+)$func\s*\(\s*$tested\s*\)\s*;\s*$/) {
+						$new_leading_tabs = $1;
+						if (length($leading_tabs) + 1 ne length($new_leading_tabs)) {
+							$do_fix = 0;
+						}
+					} else {
+						$do_fix = 0;
+					}
+					if ($do_fix) {
+						fix_delete_line($fixlinenr - 1, $prevrawline);
+						$fixed[$fixlinenr] =~ s/^\+$new_leading_tabs/\+$leading_tabs/;
+					}
+				}
 			}
 		}
 


--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

WARNING: multiple messages have this Message-ID (diff)
From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Julia Lawall <julia.lawall@lip6.fr>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Minchan Kim <minchan@kernel.org>,
	Christoph Lameter <cl@linux.com>,
	Pekka Enberg <penberg@kernel.org>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Michal Hocko <mhocko@suse.cz>,
	David Rientjes <rientjes@google.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	sergey.senozhatsky.work@gmail.com
Subject: [PATCH V2] checkpatch: Add some <foo>_destroy functions to NEEDLESS_IF tests
Date: Tue, 09 Jun 2015 22:52:29 -0700	[thread overview]
Message-ID: <1433915549.2730.107.camel@perches.com> (raw)
In-Reply-To: <1433911166.2730.98.camel@perches.com>

Sergey Senozhatsky has modified several destroy functions that can
now be called with NULL values.

 - kmem_cache_destroy()
 - mempool_destroy()
 - dma_pool_destroy()

Update checkpatch to warn when those functions are preceded by an if.

Update checkpatch to --fix all the calls too only when the code style
form is using leading tabs.

from:
	if (foo)
		<func>(foo);
to:
	<func>(foo);

Signed-off-by: Joe Perches <joe@perches.com>
---
V2: Remove useless debugging print messages and multiple quotemetas

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

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 69c4716..87d3bf1aa 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4800,10 +4800,34 @@ sub process {
 
 # check for needless "if (<foo>) fn(<foo>)" uses
 		if ($prevline =~ /\bif\s*\(\s*($Lval)\s*\)/) {
-			my $expr = '\s*\(\s*' . quotemeta($1) . '\s*\)\s*;';
-			if ($line =~ /\b(kfree|usb_free_urb|debugfs_remove(?:_recursive)?)$expr/) {
-				WARN('NEEDLESS_IF',
-				     "$1(NULL) is safe and this check is probably not required\n" . $hereprev);
+			my $tested = quotemeta($1);
+			my $expr = '\s*\(\s*' . $tested . '\s*\)\s*;';
+			if ($line =~ /\b(kfree|usb_free_urb|debugfs_remove(?:_recursive)?|(?:kmem_cache|mempool|dma_pool)_destroy)$expr/) {
+				my $func = $1;
+				if (WARN('NEEDLESS_IF',
+					 "$func(NULL) is safe and this check is probably not required\n" . $hereprev) &&
+				    $fix) {
+					my $do_fix = 1;
+					my $leading_tabs = "";
+					my $new_leading_tabs = "";
+					if ($lines[$linenr - 2] =~ /^\+(\t*)if\s*\(\s*$tested\s*\)\s*$/) {
+						$leading_tabs = $1;
+					} else {
+						$do_fix = 0;
+					}
+					if ($lines[$linenr - 1] =~ /^\+(\t+)$func\s*\(\s*$tested\s*\)\s*;\s*$/) {
+						$new_leading_tabs = $1;
+						if (length($leading_tabs) + 1 ne length($new_leading_tabs)) {
+							$do_fix = 0;
+						}
+					} else {
+						$do_fix = 0;
+					}
+					if ($do_fix) {
+						fix_delete_line($fixlinenr - 1, $prevrawline);
+						$fixed[$fixlinenr] =~ s/^\+$new_leading_tabs/\+$leading_tabs/;
+					}
+				}
 			}
 		}
 



  reply	other threads:[~2015-06-10  5:52 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-09 12:04 [RFC][PATCH 0/5] do not dereference NULL pools in pools' destroy() functions Sergey Senozhatsky
2015-06-09 12:04 ` Sergey Senozhatsky
2015-06-09 12:04 ` [RFC][PATCH 1/5] mm/slab_common: allow NULL cache pointer in kmem_cache_destroy() Sergey Senozhatsky
2015-06-09 12:04   ` Sergey Senozhatsky
2015-06-17 23:14   ` David Rientjes
2015-06-17 23:14     ` David Rientjes
2015-06-17 23:52     ` Sergey Senozhatsky
2015-06-17 23:52       ` Sergey Senozhatsky
2015-06-19 15:50       ` Julia Lawall
2015-06-19 15:50         ` Julia Lawall
2015-08-06 14:21         ` Sergey Senozhatsky
2015-08-06 14:21           ` Sergey Senozhatsky
2015-08-06 14:27           ` Julia Lawall
2015-08-06 14:27             ` Julia Lawall
2015-08-06 14:29             ` Sergey Senozhatsky
2015-08-06 14:29               ` Sergey Senozhatsky
2015-06-20 16:25       ` Julia Lawall
2015-06-20 16:25         ` Julia Lawall
2015-07-16  8:26         ` Sergey Senozhatsky
2015-07-16  8:26           ` Sergey Senozhatsky
2015-06-09 12:04 ` [RFC][PATCH 2/5] mm/mempool: allow NULL `pool' pointer in mempool_destroy() Sergey Senozhatsky
2015-06-09 12:04   ` Sergey Senozhatsky
2015-06-17 23:21   ` David Rientjes
2015-06-17 23:21     ` David Rientjes
2015-06-17 23:54     ` Sergey Senozhatsky
2015-06-17 23:54       ` Sergey Senozhatsky
2015-06-09 12:04 ` [RFC][PATCH 3/5] mm/dmapool: allow NULL `pool' pointer in dma_pool_destroy() Sergey Senozhatsky
2015-06-09 12:04   ` Sergey Senozhatsky
2015-06-17 23:22   ` David Rientjes
2015-06-17 23:22     ` David Rientjes
2015-06-09 12:04 ` [RFC][PATCH 4/5] mm/zpool: allow NULL `zpool' pointer in zpool_destroy_pool() Sergey Senozhatsky
2015-06-09 12:04   ` Sergey Senozhatsky
2015-06-10 20:59   ` Dan Streetman
2015-06-10 20:59     ` Dan Streetman
2015-06-10 23:58     ` Sergey Senozhatsky
2015-06-10 23:58       ` Sergey Senozhatsky
2015-06-11  0:48       ` Joe Perches
2015-06-11  0:48         ` Joe Perches
2015-06-11  0:59         ` Sergey Senozhatsky
2015-06-11  0:59           ` Sergey Senozhatsky
2015-06-11  1:01           ` Dan Streetman
2015-06-11  1:01             ` Dan Streetman
2015-06-09 12:04 ` [RFC][PATCH 5/5] mm/zsmalloc: allow NULL `pool' pointer in zs_destroy_pool() Sergey Senozhatsky
2015-06-09 12:04   ` Sergey Senozhatsky
2015-06-09 21:25 ` [RFC][PATCH 0/5] do not dereference NULL pools in pools' destroy() functions Andrew Morton
2015-06-09 21:25   ` Andrew Morton
2015-06-10  0:06   ` Joe Perches
2015-06-10  0:06     ` Joe Perches
2015-06-10  4:39     ` [PATCH] checkpatch: Add some <foo>_destroy functions to NEEDLESS_IF tests Joe Perches
2015-06-10  4:39       ` Joe Perches
2015-06-10  5:52       ` Joe Perches [this message]
2015-06-10  5:52         ` [PATCH V2] " Joe Perches
2015-06-10 10:18         ` Sergey Senozhatsky
2015-06-10 10:18           ` Sergey Senozhatsky
2015-06-11  9:41         ` Julia Lawall
2015-06-11  9:41           ` Julia Lawall
2015-06-11  9:51           ` Sergey Senozhatsky
2015-06-11  9:51             ` Sergey Senozhatsky
2015-06-11  9:55             ` Julia Lawall
2015-06-11  9:55               ` Julia Lawall
2015-07-14 23:03         ` Andrew Morton
2015-07-14 23:03           ` Andrew Morton
2015-07-15  0:27           ` Sergey Senozhatsky
2015-07-15  0:27             ` Sergey Senozhatsky
2015-06-10  5:46     ` [RFC][PATCH 0/5] do not dereference NULL pools in pools' destroy() functions Julia Lawall
2015-06-10  5:46       ` Julia Lawall
2015-06-10  6:41       ` Sergey Senozhatsky
2015-06-10  6:41         ` Sergey Senozhatsky
2015-06-10  6:44         ` Julia Lawall
2015-06-10  6:44           ` Julia Lawall
2015-06-10  6:52           ` Sergey Senozhatsky
2015-06-10  6:52             ` Sergey Senozhatsky
2015-06-10  1:11   ` Christoph Lameter
2015-06-10  1:11     ` Christoph Lameter
2015-06-10  1:51     ` Andrew Morton
2015-06-10  1:51       ` Andrew Morton
2015-06-10  2:00       ` Christoph Lameter
2015-06-10  2:00         ` Christoph Lameter
2015-06-10  2:17         ` Andrew Morton
2015-06-10  2:17           ` Andrew Morton
2015-06-10  4:47           ` Joe Perches
2015-06-10  4:47             ` Joe Perches
2015-06-11 17:26           ` Christoph Lameter
2015-06-11 17:26             ` Christoph Lameter
2015-06-11 17:40             ` Andrew Morton
2015-06-11 17:40               ` Andrew Morton
2015-06-10  2:04     ` Sergey Senozhatsky
2015-06-10  2:04       ` Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1433915549.2730.107.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=julia.lawall@lip6.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.cz \
    --cc=minchan@kernel.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=sergey.senozhatsky@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.