2015-02-27 13:22:11

by Daniel Granat

[permalink] [raw]
Subject: [PATCH] Add coccinelle script that makes sure that tables are NULL terminated

Signed-off-by: Daniel Granat <[email protected]>
---
scripts/coccinelle/misc/device_id_tables.cocci | 95 ++++++++++++++++++++++++++
1 file changed, 95 insertions(+)
create mode 100644 scripts/coccinelle/misc/device_id_tables.cocci

diff --git a/scripts/coccinelle/misc/device_id_tables.cocci b/scripts/coccinelle/misc/device_id_tables.cocci
new file mode 100644
index 0000000..5968984
--- /dev/null
+++ b/scripts/coccinelle/misc/device_id_tables.cocci
@@ -0,0 +1,95 @@
+/// Make sure '*_device_id$' tables are NULL terminated
+//
+// Keywords: device_id
+// Confidence: Medium
+// Options: --include-headers
+
+virtual org
+virtual report
+virtual patch
+
+@initialize:python@
+@@
+import re
+
+postfix = '_device_id$'
+prefix_list = ['platform', 'of', 'i2c']
+
+@r1 depends on patch || org || report@
+position p1;
+identifier var, arr;
+identifier struct_name;
+expression E;
+@@
+
+(
+struct struct_name arr[] = {
+ ...,
+ {
+ .var = E,
+ }
+ @p1
+};
+|
+struct struct_name arr[] = {
+ ...,
+ { ..., var, ... },
+ @p1
+};
+)
+
+@script:python depends on report@
+struct_name << r1.struct_name;
+p1 << r1.p1;
+arr << r1.arr;
+pattern;
+@@
+
+for i in prefix_list:
+ pattern = str(i)+postfix
+ if re.match(pattern, struct_name) != None:
+ print "\nCOCCI: \"%s\" matchs required pattern \"%s\"" % (struct_name, pattern)
+ msg = "\"%s\" is not NULL terminated at line %s" % (arr, p1[0].line)
+ coccilib.report.print_report(p1[0],msg)
+ break
+
+@script:python match depends on patch@
+struct_name << r1.struct_name;
+matched_name;
+pattern;
+@@
+
+coccinelle.matched_name = ''
+
+for i in prefix_list:
+ pattern = str(i)+postfix
+ if re.match(pattern, struct_name) != None:
+ coccinelle.matched_name = struct_name
+ break
+
+@r2 depends on patch@
+position r1.p1;
+identifier var, arr;
+identifier match.matched_name;
+expression E;
+@@
+
+(
+struct matched_name arr[] = {
+ ...,
+ {
+ .var = E,
+- }
+ @p1
++ },
++ {},
+};
+|
+struct matched_name arr[] = {
+ ...,
+ { ..., var, ... },
+ @p1
++ {},
+};
+)
+
--
1.9.1


2015-04-22 11:08:31

by Krzysztof Kozłowski

[permalink] [raw]
Subject: Re: [PATCH] Add coccinelle script that makes sure that tables are NULL terminated

W dniu 27.02.2015 o 22:21, Daniel Granat pisze:
> Signed-off-by: Daniel Granat <[email protected]>
> ---
> scripts/coccinelle/misc/device_id_tables.cocci | 95 ++++++++++++++++++++++++++
> 1 file changed, 95 insertions(+)
> create mode 100644 scripts/coccinelle/misc/device_id_tables.cocci

I like the idea and I think it is useful.
Tested-by: Krzysztof Kozlowski <[email protected]>

However applying the patch gave some warnings:

Applying: Add coccinelle script that makes sure that tables are NULL terminated
/home/dev/linux/linux/.git/rebase-apply/patch:64: space before tab in indent.
coccilib.report.print_report(p1[0],msg)
/home/dev/linux/linux/.git/rebase-apply/patch:89: trailing whitespace.
struct matched_name arr[] = {
/home/dev/linux/linux/.git/rebase-apply/patch:99: trailing whitespace.
struct matched_name arr[] = {
/home/dev/linux/linux/.git/rebase-apply/patch:106: new blank line at EOF.
+
warning: 4 lines add whitespace errors.

Best regards,
Krzysztof

2015-04-22 11:16:58

by Daniel Granat

[permalink] [raw]
Subject: Re: [PATCH] Add coccinelle script that makes sure that tables are NULL terminated

Ok, but I'm going to improve the script. New coccinelle release give my
opportunity to simplify this a lot, so I'll send next version of my
patch soon.

Best regards,
--
Daniel Granat
Junior Software Engineer
Samsung R&D Institute Poland (SRPOL)
Al. Armii Ludowej 14, 00-638 Warszawa, Poland

On 04/22/2015 01:08 PM, Krzysztof Kozlowski wrote:
> W dniu 27.02.2015 o 22:21, Daniel Granat pisze:
>> Signed-off-by: Daniel Granat <[email protected]>
>> ---
>> scripts/coccinelle/misc/device_id_tables.cocci | 95 ++++++++++++++++++++++++++
>> 1 file changed, 95 insertions(+)
>> create mode 100644 scripts/coccinelle/misc/device_id_tables.cocci
>
> I like the idea and I think it is useful.
> Tested-by: Krzysztof Kozlowski <[email protected]>
>
> However applying the patch gave some warnings:
>
> Applying: Add coccinelle script that makes sure that tables are NULL terminated
> /home/dev/linux/linux/.git/rebase-apply/patch:64: space before tab in indent.
> coccilib.report.print_report(p1[0],msg)
> /home/dev/linux/linux/.git/rebase-apply/patch:89: trailing whitespace.
> struct matched_name arr[] = {
> /home/dev/linux/linux/.git/rebase-apply/patch:99: trailing whitespace.
> struct matched_name arr[] = {
> /home/dev/linux/linux/.git/rebase-apply/patch:106: new blank line at EOF.
> +
> warning: 4 lines add whitespace errors.
>
> Best regards,
> Krzysztof
>

2015-05-18 11:29:52

by Daniel Granat

[permalink] [raw]
Subject: [PATCH v2] Add coccinelle script that makes sure that tables are NULL terminated

Signed-off-by: Daniel Granat <[email protected]>
---
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

2015-05-19 08:57:47

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH v2] Add coccinelle script that makes sure that tables are NULL terminated

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 <[email protected]>
> ---
> 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
>
>

2015-05-19 11:59:05

by Daniel Granat

[permalink] [raw]
Subject: [PATCH v3] Added tables i2c_device_id and platform_device_id for checking. Extend checking on tables containing structures which are initialized without specifying member name.

Signed-off-by: Daniel Granat <[email protected]>
---
scripts/coccinelle/misc/of_table.cocci | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/scripts/coccinelle/misc/of_table.cocci b/scripts/coccinelle/misc/of_table.cocci
index 3c93404..74f7dbb 100644
--- a/scripts/coccinelle/misc/of_table.cocci
+++ b/scripts/coccinelle/misc/of_table.cocci
@@ -1,6 +1,6 @@
-/// Make sure of_device_id tables are NULL terminated
+/// Make sure (of_device_id | i2c_device_id | platform_device_id) tables are NULL terminated
//
-// Keywords: of_table
+// Keywords: of_table i2c_table platform_table
// Confidence: Medium
// Options: --include-headers

@@ -13,7 +13,7 @@ virtual report
identifier var, arr;
expression E;
@@
-struct of_device_id arr[] = {
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
...,
{
.var = E,
@@ -24,7 +24,8 @@ struct of_device_id arr[] = {
identifier var, arr;
expression E;
@@
-struct of_device_id arr[] = {
+(
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
...,
{
.var = E,
@@ -32,19 +33,34 @@ struct of_device_id arr[] = {
+ },
+ { }
};
+|
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
+ ...,
+ { ..., E, ... },
++ { },
+};
+)

@r depends on org || report@
position p1;
identifier var, arr;
expression E;
@@
-struct of_device_id arr[] = {
+(
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
...,
{
.var = E,
}
@p1
};
+|
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
+ ...,
+ { ..., E, ... },
+ @p1
+};
+)

@script:python depends on org@
p1 << r.p1;
--
1.9.1

2015-05-25 20:19:23

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH v3] Added tables i2c_device_id and platform_device_id for checking. Extend checking on tables containing structures which are initialized without specifying member name.



On Tue, 19 May 2015, Daniel Granat wrote:

> Signed-off-by: Daniel Granat <[email protected]>
> ---
> scripts/coccinelle/misc/of_table.cocci | 26 +++++++++++++++++++++-----
> 1 file changed, 21 insertions(+), 5 deletions(-)
>
> diff --git a/scripts/coccinelle/misc/of_table.cocci b/scripts/coccinelle/misc/of_table.cocci
> index 3c93404..74f7dbb 100644
> --- a/scripts/coccinelle/misc/of_table.cocci
> +++ b/scripts/coccinelle/misc/of_table.cocci
> @@ -1,6 +1,6 @@
> -/// Make sure of_device_id tables are NULL terminated
> +/// Make sure (of_device_id | i2c_device_id | platform_device_id) tables are NULL terminated
> //
> -// Keywords: of_table
> +// Keywords: of_table i2c_table platform_table
> // Confidence: Medium
> // Options: --include-headers
>
> @@ -13,7 +13,7 @@ virtual report
> identifier var, arr;
> expression E;
> @@
> -struct of_device_id arr[] = {
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> ...,
> {
> .var = E,

This case (the context case) needs a ..., E, ... case like the patch rule
has.


> @@ -24,7 +24,8 @@ struct of_device_id arr[] = {
> identifier var, arr;
> expression E;
> @@
> -struct of_device_id arr[] = {
> +(
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> ...,
> {
> .var = E,
> @@ -32,19 +33,34 @@ struct of_device_id arr[] = {
> + },
> + { }
> };
> +|
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> + ...,
> + { ..., E, ... },
> ++ { },
> +};
> +)
>
> @r depends on org || report@
> position p1;
> identifier var, arr;
> expression E;
> @@
> -struct of_device_id arr[] = {
> +(
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> ...,
> {
> .var = E,
> }
> @p1
> };
> +|
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> + ...,
> + { ..., E, ... },
> + @p1

It is not a good idea to put the @p1 on the comma. The comma might not be
there, and if it is not there Coccinelle seems to crash. A more graceful
behavior would be for the rule simply not to match, since a comma that
isn't there doesn't have a position. In any case, if you put the @p1 on
the }, things are better.

I made the following test case, if you want to make a quick check of the
rule. All four options should give four results.

static const struct platform_device_id ab85xx_rtc_ids[] = {
{ "ab8500-rtc", (kernel_ulong_t)&ab8500_rtc_ops, },
{ "ab8540-rtc", (kernel_ulong_t)&ab8540_rtc_ops, },
};
static const struct platform_device_id ab85xx_rtc_ids[] = {
{ "ab8500-rtc", (kernel_ulong_t)&ab8500_rtc_ops, },
{ "ab8540-rtc", (kernel_ulong_t)&ab8540_rtc_ops, }
};
static const struct platform_device_id ab85xx_rtc_ids[] = {
{ .a = "ab8500-rtc", .b = (kernel_ulong_t)&ab8500_rtc_ops, },
{ .a = "ab8540-rtc", .b = (kernel_ulong_t)&ab8540_rtc_ops, },
};
static const struct platform_device_id ab85xx_rtc_ids[] = {
{ .a = "ab8500-rtc", .b = (kernel_ulong_t)&ab8500_rtc_ops, },
{ .a = "ab8540-rtc", .b = (kernel_ulong_t)&ab8540_rtc_ops, }
};

julia

> +};
> +)
>
> @script:python depends on org@
> p1 << r.p1;
> --
> 1.9.1
>
>

2015-06-02 16:11:14

by Daniel Granat

[permalink] [raw]
Subject: [PATCH v4] Added tables i2c_device_id and platform_device_id for

Thank you for advices. I submit new patch with changes you suggested but I don't know why in "context" rule I get only two results instead of four.

2015-06-02 16:11:45

by Daniel Granat

[permalink] [raw]
Subject: [PATCH v4] Added tables i2c_device_id and platform_device_id for checking. Extend checking on tables containing structures which are initialized without specifying member name.

Signed-off-by: Daniel Granat <[email protected]>
---
scripts/coccinelle/misc/of_table.cocci | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/scripts/coccinelle/misc/of_table.cocci b/scripts/coccinelle/misc/of_table.cocci
index 3c93404..bc3c944 100644
--- a/scripts/coccinelle/misc/of_table.cocci
+++ b/scripts/coccinelle/misc/of_table.cocci
@@ -1,6 +1,6 @@
-/// Make sure of_device_id tables are NULL terminated
+/// Make sure (of_device_id | i2c_device_id | platform_device_id) tables are NULL terminated
//
-// Keywords: of_table
+// Keywords: of_table i2c_table platform_table
// Confidence: Medium
// Options: --include-headers

@@ -13,18 +13,27 @@ virtual report
identifier var, arr;
expression E;
@@
-struct of_device_id arr[] = {
+(
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
...,
{
.var = E,
* }
};
+|
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
+ ...,
+ { ..., E, ... },
+* { },
+};
+)

@depends on patch@
identifier var, arr;
expression E;
@@
-struct of_device_id arr[] = {
+(
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
...,
{
.var = E,
@@ -32,19 +41,34 @@ struct of_device_id arr[] = {
+ },
+ { }
};
+|
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
+ ...,
+ { ..., E, ... },
++ { },
+};
+)

@r depends on org || report@
position p1;
identifier var, arr;
expression E;
@@
-struct of_device_id arr[] = {
+(
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
...,
{
.var = E,
}
@p1
};
+|
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
+ ...,
+ { ..., E, ... }
+ @p1
+};
+)

@script:python depends on org@
p1 << r.p1;
--
1.9.1

2015-06-03 09:42:26

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH v4] Added tables i2c_device_id and platform_device_id for checking. Extend checking on tables containing structures which are initialized without specifying member name.



On Tue, 2 Jun 2015, Daniel Granat wrote:

> Signed-off-by: Daniel Granat <[email protected]>
> ---
> scripts/coccinelle/misc/of_table.cocci | 34 +++++++++++++++++++++++++++++-----
> 1 file changed, 29 insertions(+), 5 deletions(-)
>
> diff --git a/scripts/coccinelle/misc/of_table.cocci b/scripts/coccinelle/misc/of_table.cocci
> index 3c93404..bc3c944 100644
> --- a/scripts/coccinelle/misc/of_table.cocci
> +++ b/scripts/coccinelle/misc/of_table.cocci
> @@ -1,6 +1,6 @@
> -/// Make sure of_device_id tables are NULL terminated
> +/// Make sure (of_device_id | i2c_device_id | platform_device_id) tables are NULL terminated

It would be nice for the comment to be limited to 80 characters.

> //
> -// Keywords: of_table
> +// Keywords: of_table i2c_table platform_table
> // Confidence: Medium
> // Options: --include-headers
>
> @@ -13,18 +13,27 @@ virtual report
> identifier var, arr;
> expression E;
> @@
> -struct of_device_id arr[] = {
> +(
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> ...,
> {
> .var = E,
> * }
> };
> +|
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> + ...,
> + { ..., E, ... },
> +* { },

This should be:

struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
...,
* { ..., E, ... },
};

With that you get four results for the context case, like for the others.

The rest looks OK.

julia

> +};
> +)
>
> @depends on patch@
> identifier var, arr;
> expression E;
> @@
> -struct of_device_id arr[] = {
> +(
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> ...,
> {
> .var = E,
> @@ -32,19 +41,34 @@ struct of_device_id arr[] = {
> + },
> + { }
> };
> +|
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> + ...,
> + { ..., E, ... },
> ++ { },
> +};
> +)
>
> @r depends on org || report@
> position p1;
> identifier var, arr;
> expression E;
> @@
> -struct of_device_id arr[] = {
> +(
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> ...,
> {
> .var = E,
> }
> @p1
> };
> +|
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> + ...,
> + { ..., E, ... }
> + @p1
> +};
> +)
>
> @script:python depends on org@
> p1 << r.p1;
> --
> 1.9.1
>
>

2015-06-23 11:02:53

by Daniel Granat

[permalink] [raw]
Subject: [PATCH v5] Added tables (i2c/platform)_device_id for checking. Extend checking on tables containing structures which are initialized without specifying member name.

Signed-off-by: Daniel Granat <[email protected]>
---
scripts/coccinelle/misc/of_table.cocci | 33 ++++++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/scripts/coccinelle/misc/of_table.cocci b/scripts/coccinelle/misc/of_table.cocci
index 3c93404..2294915 100644
--- a/scripts/coccinelle/misc/of_table.cocci
+++ b/scripts/coccinelle/misc/of_table.cocci
@@ -1,6 +1,6 @@
-/// Make sure of_device_id tables are NULL terminated
+/// Make sure (of/i2c/platform)_device_id tables are NULL terminated
//
-// Keywords: of_table
+// Keywords: of_table i2c_table platform_table
// Confidence: Medium
// Options: --include-headers

@@ -13,18 +13,26 @@ virtual report
identifier var, arr;
expression E;
@@
-struct of_device_id arr[] = {
+(
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
...,
{
.var = E,
* }
};
+|
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
+ ...,
+* { ..., E, ... },
+};
+)

@depends on patch@
identifier var, arr;
expression E;
@@
-struct of_device_id arr[] = {
+(
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
...,
{
.var = E,
@@ -32,19 +40,34 @@ struct of_device_id arr[] = {
+ },
+ { }
};
+|
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
+ ...,
+ { ..., E, ... },
++ { },
+};
+)

@r depends on org || report@
position p1;
identifier var, arr;
expression E;
@@
-struct of_device_id arr[] = {
+(
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
...,
{
.var = E,
}
@p1
};
+|
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
+ ...,
+ { ..., E, ... }
+ @p1
+};
+)

@script:python depends on org@
p1 << r.p1;
--
1.9.1

2015-06-23 11:50:57

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH v5] Added tables (i2c/platform)_device_id for checking. Extend checking on tables containing structures which are initialized without specifying member name.

2015-06-23 20:02 GMT+09:00 Daniel Granat <[email protected]>:
> Signed-off-by: Daniel Granat <[email protected]>

Something went wrong. It looks like changelog was used as subject and
the body disappeared.

Best regards,
Krzysztof

2015-06-23 12:25:50

by Julia Lawall

[permalink] [raw]
Subject: Re: [PATCH v5] Added tables (i2c/platform)_device_id for checking. Extend checking on tables containing structures which are initialized without specifying member name.



On Tue, 23 Jun 2015, Daniel Granat wrote:

> Signed-off-by: Daniel Granat <[email protected]>

Acked-by: Julia Lawall <[email protected]>

> ---
> scripts/coccinelle/misc/of_table.cocci | 33 ++++++++++++++++++++++++++++-----
> 1 file changed, 28 insertions(+), 5 deletions(-)
>
> diff --git a/scripts/coccinelle/misc/of_table.cocci b/scripts/coccinelle/misc/of_table.cocci
> index 3c93404..2294915 100644
> --- a/scripts/coccinelle/misc/of_table.cocci
> +++ b/scripts/coccinelle/misc/of_table.cocci
> @@ -1,6 +1,6 @@
> -/// Make sure of_device_id tables are NULL terminated
> +/// Make sure (of/i2c/platform)_device_id tables are NULL terminated
> //
> -// Keywords: of_table
> +// Keywords: of_table i2c_table platform_table
> // Confidence: Medium
> // Options: --include-headers
>
> @@ -13,18 +13,26 @@ virtual report
> identifier var, arr;
> expression E;
> @@
> -struct of_device_id arr[] = {
> +(
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> ...,
> {
> .var = E,
> * }
> };
> +|
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> + ...,
> +* { ..., E, ... },
> +};
> +)
>
> @depends on patch@
> identifier var, arr;
> expression E;
> @@
> -struct of_device_id arr[] = {
> +(
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> ...,
> {
> .var = E,
> @@ -32,19 +40,34 @@ struct of_device_id arr[] = {
> + },
> + { }
> };
> +|
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> + ...,
> + { ..., E, ... },
> ++ { },
> +};
> +)
>
> @r depends on org || report@
> position p1;
> identifier var, arr;
> expression E;
> @@
> -struct of_device_id arr[] = {
> +(
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> ...,
> {
> .var = E,
> }
> @p1
> };
> +|
> +struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
> + ...,
> + { ..., E, ... }
> + @p1
> +};
> +)
>
> @script:python depends on org@
> p1 << r.p1;
> --
> 1.9.1
>
>

2015-06-26 14:40:43

by Daniel Granat

[permalink] [raw]
Subject: [PATCH v6] coccinelle: Improve checking for missing NULL terminators

Extend checking on tables containing structures which are
initialized without specifying member name. Added new tables
for checking: i2c_device_id and platform_device_id.

Signed-off-by: Daniel Granat <[email protected]>
Acked-by: Julia Lawall <[email protected]>
---
scripts/coccinelle/misc/of_table.cocci | 33 ++++++++++++++++++++++++++++-----
1 file changed, 28 insertions(+), 5 deletions(-)

diff --git a/scripts/coccinelle/misc/of_table.cocci b/scripts/coccinelle/misc/of_table.cocci
index 3c93404..2294915 100644
--- a/scripts/coccinelle/misc/of_table.cocci
+++ b/scripts/coccinelle/misc/of_table.cocci
@@ -1,6 +1,6 @@
-/// Make sure of_device_id tables are NULL terminated
+/// Make sure (of/i2c/platform)_device_id tables are NULL terminated
//
-// Keywords: of_table
+// Keywords: of_table i2c_table platform_table
// Confidence: Medium
// Options: --include-headers

@@ -13,18 +13,26 @@ virtual report
identifier var, arr;
expression E;
@@
-struct of_device_id arr[] = {
+(
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
...,
{
.var = E,
* }
};
+|
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
+ ...,
+* { ..., E, ... },
+};
+)

@depends on patch@
identifier var, arr;
expression E;
@@
-struct of_device_id arr[] = {
+(
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
...,
{
.var = E,
@@ -32,19 +40,34 @@ struct of_device_id arr[] = {
+ },
+ { }
};
+|
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
+ ...,
+ { ..., E, ... },
++ { },
+};
+)

@r depends on org || report@
position p1;
identifier var, arr;
expression E;
@@
-struct of_device_id arr[] = {
+(
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
...,
{
.var = E,
}
@p1
};
+|
+struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
+ ...,
+ { ..., E, ... }
+ @p1
+};
+)

@script:python depends on org@
p1 << r.p1;
--
1.9.1