Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1163102 > unrolled thread

Re: [PATCH V2] checkpatch: Add some <foo>_destroy functions to NEEDLESS_IF tests

Started byJulia Lawall <julia.lawall@lip6.fr>
First post2015-06-11 11:50 +0200
Last post2015-06-11 12:00 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH V2] checkpatch: Add some <foo>_destroy functions to  NEEDLESS_IF tests Julia Lawall <julia.lawall@lip6.fr> - 2015-06-11 11:50 +0200
    Re: [PATCH V2] checkpatch: Add some <foo>_destroy functions to  NEEDLESS_IF tests Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2015-06-11 12:00 +0200
      Re: [PATCH V2] checkpatch: Add some <foo>_destroy functions to  NEEDLESS_IF tests Julia Lawall <julia.lawall@lip6.fr> - 2015-06-11 12:00 +0200

#1163102 — Re: [PATCH V2] checkpatch: Add some <foo>_destroy functions to NEEDLESS_IF tests

FromJulia Lawall <julia.lawall@lip6.fr>
Date2015-06-11 11:50 +0200
SubjectRe: [PATCH V2] checkpatch: Add some <foo>_destroy functions to NEEDLESS_IF tests
Message-ID<pA7hw-1Na-19@gated-at.bofh.it>

On Tue, 9 Jun 2015, Joe Perches wrote:

> Sergey Senozhatsky has modified several destroy functions that can
> now be called with NULL values.
>
>  - kmem_cache_destroy()
>  - mempool_destroy()
>  - dma_pool_destroy()

I don't actually see any null test in the definition of dma_pool_destroy,
in the linux-next 54896f27dd5 (20150610).  So I guess it would be
premature to send patches to remove the null tests.

julia

> 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 from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1163105

FromSergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Date2015-06-11 12:00 +0200
Message-ID<pA7rc-1YG-5@gated-at.bofh.it>
In reply to#1163102
On (06/11/15 11:41), Julia Lawall wrote:
> On Tue, 9 Jun 2015, Joe Perches wrote:
> 
> > Sergey Senozhatsky has modified several destroy functions that can
> > now be called with NULL values.
> >
> >  - kmem_cache_destroy()
> >  - mempool_destroy()
> >  - dma_pool_destroy()
> 
> I don't actually see any null test in the definition of dma_pool_destroy,
> in the linux-next 54896f27dd5 (20150610).  So I guess it would be
> premature to send patches to remove the null tests.
> 

yes,

Andrew Morton:
: I'll park these patches until after 4.1 is released - it's getting to
: that time...


	-ss
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [next] | [standalone]


#1163113

FromJulia Lawall <julia.lawall@lip6.fr>
Date2015-06-11 12:00 +0200
Message-ID<pA7rd-1YG-25@gated-at.bofh.it>
In reply to#1163105

On Thu, 11 Jun 2015, Sergey Senozhatsky wrote:

> On (06/11/15 11:41), Julia Lawall wrote:
> > On Tue, 9 Jun 2015, Joe Perches wrote:
> >
> > > Sergey Senozhatsky has modified several destroy functions that can
> > > now be called with NULL values.
> > >
> > >  - kmem_cache_destroy()
> > >  - mempool_destroy()
> > >  - dma_pool_destroy()
> >
> > I don't actually see any null test in the definition of dma_pool_destroy,
> > in the linux-next 54896f27dd5 (20150610).  So I guess it would be
> > premature to send patches to remove the null tests.
> >
>
> yes,
>
> Andrew Morton:
> : I'll park these patches until after 4.1 is released - it's getting to
> : that time...

OK, thanks,

julia
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web