Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755525AbbESI5r (ORCPT ); Tue, 19 May 2015 04:57:47 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:22532 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753146AbbESI5o (ORCPT ); Tue, 19 May 2015 04:57:44 -0400 X-IronPort-AV: E=Sophos;i="5.13,457,1427752800"; d="scan'208";a="151563942" Date: Tue, 19 May 2015 10:57:40 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Daniel Granat cc: Julia.Lawall@lip6.fr, cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org, Gilles.Muller@lip6.fr, nicolas.palix@imag.fr Subject: Re: [PATCH v2] Add coccinelle script that makes sure that tables are NULL terminated In-Reply-To: <1431948540-8202-1-git-send-email-d.granat@samsung.com> Message-ID: References: <1425043313-15844-1-git-send-email-d.granat@samsung.com> <1431948540-8202-1-git-send-email-d.granat@samsung.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2188 Lines: 98 There is already a rule misc/of_table.cocci for the of_device_id case. I think it would be better to extend that. Also, rather than making an identifier name, it would be more efficient to put struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = ... The Coccinelle will only work on files that contain those identifiers. julia On Mon, 18 May 2015, Daniel Granat wrote: > Signed-off-by: Daniel Granat > --- > scripts/coccinelle/misc/of_platform.cocci | 65 +++++++++++++++++++++++++++++++ > 1 file changed, 65 insertions(+) > create mode 100644 scripts/coccinelle/misc/of_platform.cocci > > diff --git a/scripts/coccinelle/misc/of_platform.cocci b/scripts/coccinelle/misc/of_platform.cocci > new file mode 100644 > index 0000000..02c6195 > --- /dev/null > +++ b/scripts/coccinelle/misc/of_platform.cocci > @@ -0,0 +1,65 @@ > +/// Make sure that tables are NULL terminated > +// > +// Keywords: _device_id > +// Confidence: Medium > +// Options: --include-headers > + > +virtual report > +virtual patch > + > +@r depends on report@ > +position p1; > +identifier var, arr; > +identifier name = {of_device_id, i2c_device_id, platform_device_id}; > +expression E; > +@@ > + > +( > +struct name arr[] = { > + ..., > + { > + .var = E, > + } > + @p1 > +}; > +| > +struct name arr[] = { > + ..., > + { ..., var, ... }, > + @p1 > +}; > +) > + > +@script:python depends on report@ > +p1 << r.p1; > +arr << r.arr; > +@@ > + > +msg = "%s is not NULL terminated at line %s" % (arr, p1[0].line) > +coccilib.report.print_report(p1[0],msg) > + > +@p depends on patch@ > +position p1; > +identifier var, arr; > +identifier name = {of_device_id, i2c_device_id, platform_device_id}; > +expression E; > +@@ > + > +( > +struct name arr[] = { > + ..., > + { > + .var = E, > +- } > + @p1 > ++ }, > ++ {}, > +}; > +| > +struct name arr[] = { > + ..., > + { ..., var, ... }, > + @p1 > ++ {}, > +}; > +) > -- > 1.9.1 > > -- 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/