cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Tom Rix <trix@redhat.com>, Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, cocci <cocci@systeme.lip6.fr>
Subject: Re: [Cocci] [PATCH] checkpatch: Allow --fix removal of unnecessary break statements
Date: Mon, 19 Oct 2020 08:16:47 -0700	[thread overview]
Message-ID: <b4a74066be2ff9bff703e72c15296c49b6dc39ee.camel@perches.com> (raw)
In-Reply-To: <c02aed9b-ab6c-1054-1e8a-4006f2a75f94@redhat.com>

On Mon, 2020-10-19 at 05:55 -0700, Tom Rix wrote:
> On 10/18/20 1:19 PM, Joe Perches wrote:
> > On Sun, 2020-10-18 at 13:07 -0700, Tom Rix wrote:
> > > I like!
> > []
> > > could add a '|break' here to catch the couple
> > []
> > > break;
> > > 
> > > break;
> > Unfortunately, checkpatch is really stupid and it
> > wouldn't catch those
> > cases as there are blank lines
> > between the existing consecutive break
> > statements.
> > 
> > It would catch
> > 
> > 	break;
> > 	break;
> > 
> > but there aren't any of those so it seems unlikely
> > to be a very useful addition.
> 
> Unusual, but there are a couple of these.
> 
> Here's one from my rfc diff
> 
> diff --git a/sound/soc/codecs/wcd-clsh-v2.c b/sound/soc/codecs/wcd-clsh-v2.c
> index 1be82113c59a..817d8259758c 100644
> --- a/sound/soc/codecs/wcd-clsh-v2.c
> +++ b/sound/soc/codecs/wcd-clsh-v2.c
> @@ -478,11 +478,10 @@ static int _wcd_clsh_ctrl_set_state(struct wcd_clsh_ctrl *ctrl, int req_state,
>          wcd_clsh_state_hph_l(ctrl, req_state, is_enable, mode);
>          break;
>      case WCD_CLSH_STATE_HPHR:
>          wcd_clsh_state_hph_r(ctrl, req_state, is_enable, mode);
>          break;
> -        break;
>      case WCD_CLSH_STATE_LO:
>          wcd_clsh_state_lo(ctrl, req_state, is_enable, mode);
>          break;
>      default:
>          break;

Thanks, I guess my grep skilz ain't good enough.

I used:
.
$ git grep -A1 -n "break;" | grep -B1 -P '\-\d+\-.*break;'

but that doesn't work because the line after the
first break is also break then that line also matches
break; too so the second grep expecting to match the
'-<line#>- break;' doesn't work.  That line also
matches the first pattern so it's ':<line#>:'

Duh...

This seems to work though:

$ git grep -n -P '^\s*break;\s*$' | \
  awk -F: '{if ($1==o1 && $2==o2+1) {print $0;} o1=$1; o2=$2;}'
drivers/gpu/drm/amd/display/dc/dce/dce_transform.c:1333:			break;
drivers/media/usb/gspca/sn9c20x.c:1864:		break;
drivers/video/fbdev/pm2fb.c:479:		break;
drivers/video/fbdev/pm2fb.c:501:		break;
sound/soc/codecs/wcd-clsh-v2.c:483:		break;

Anyway it doesn't hurt to add it.

cheers, Joe

_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

  reply	other threads:[~2020-10-19 15:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20201017160928.12698-1-trix@redhat.com>
2020-10-17 16:24 ` [Cocci] [RFC] treewide: cleanup unreachable breaks Joe Perches
2020-10-17 18:21   ` Julia Lawall
2020-10-17 19:00     ` Joe Perches
2020-10-18 19:49     ` [Cocci] [PATCH] checkpatch: Allow --fix removal of unnecessary break statements Joe Perches
2020-10-18 20:07       ` Tom Rix
2020-10-18 20:19         ` Joe Perches
2020-10-19 12:55           ` Tom Rix
2020-10-19 15:16             ` Joe Perches [this message]
2020-10-19 15:36     ` [Cocci] [PATCH V2] " Joe Perches

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=b4a74066be2ff9bff703e72c15296c49b6dc39ee.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=cocci@systeme.lip6.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=trix@redhat.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 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).