mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Valentin Schneider <valentin.schneider@arm.com>,
	Peter Zijlstra <peterz@infradead.org>,
	"Gustavo A. R. Silva" <gustavo@embeddedor.com>
Cc: Ingo Molnar <mingo@redhat.com>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sched/fair: Replace zero-length array with flexible-array member
Date: Thu, 13 Feb 2020 18:05:13 -0800	[thread overview]
Message-ID: <cb37f342635b045639d877034c9f6d175b5d80cd.camel@perches.com> (raw)
In-Reply-To: <1d420ee4-7078-26d9-83ad-eb5f12106116@arm.com>

On Fri, 2020-02-14 at 00:25 +0000, Valentin Schneider wrote:
> On 13/02/2020 22:02, Joe Perches wrote:
> > That might be a somewhat difficult thing to add to checkpatch
> > as it is effectively a per-line scanner:
> > 
> > Try something like:
> > 
> > $ git grep -P -A1 '^\s*(?!return)(\w+\s+){1,3}\w+\[0\];' -- '*.[ch]'
> > 
> > and look at the results.
> > 
> > In checkpatch that could be something like:
> > 
> > 	if ($line =~ /^.\s*$Type\s+$Ident\s*\[\s*0\s*\]\s*;/) {
> > 		warn...
> > 	}
> > 
> 
> So FWIW I felt like doing some coccinelle and ended up with this:
> 
> This patches up valid ZLAs:
>   $ spatch -D patch zero_length_array.cocci kernel/sched/fair.c
> 
> This prints out the location of invalid ZLAs:
>   $ spatch -D report zero_length_array.cocci kernel/sched/fair.c
> 
> ---
> virtual patch
> virtual report
> 
> @valid_zla depends on patch@
> identifier struct_name;
> type T;
> identifier zla;
> position pos;
> @@
> struct struct_name {
>        ...
>        T zla@pos
> - [0];
> + [];
> };
> 
> @invalid_zla depends on report@
> identifier struct_name;
> type T1;
> identifier zla;
> type T2;
> identifier tail;
> position pos;
> @@
> struct struct_name {
>        ...
>        T1 zla[0]@pos;
>        T2 tail;
>        ...
> };
> 
> @script:python depends on invalid_zla@
> pos << invalid_zla.pos;
> @@
> coccilib.report.print_report(pos[0], "Invalid ZLA!");
> ---

Nice.
It would miss a few forms like:

	typedef struct tagfoo {
		...
		type t[0];
	} foo;

and

	struct {
		...
		type t[0];
	} foo;

and

	struct foo {
		...
		type t[0];
	} *foo;

etc...



  reply	other threads:[~2020-02-14  2:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-13 15:19 Gustavo A. R. Silva
2020-02-13 16:45 ` Peter Zijlstra
2020-02-13 16:58   ` Gustavo A. R. Silva
2020-02-13 17:06     ` Peter Zijlstra
2020-02-13 22:02       ` Joe Perches
2020-02-14  0:25         ` Valentin Schneider
2020-02-14  2:05           ` Joe Perches [this message]
2020-02-16 23:38             ` Valentin Schneider

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=cb37f342635b045639d877034c9f6d175b5d80cd.camel@perches.com \
    --to=joe@perches.com \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=gustavo@embeddedor.com \
    --cc=juri.lelli@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=valentin.schneider@arm.com \
    --cc=vincent.guittot@linaro.org \
    /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

all inboxes | Powered by JetHome®