coccinelle: Check for missing NULL terminators in of_device_id tables
PATCH 1/1 coccinelle: Check for missing NULL terminators in of_device_id tables
Failure to terminate an of_device_id table can lead to confusing failures depending on where the compiler places the array. Add a check to make sure these tables are terminated. Thanks to Mitchel Humpherys for coming up with the initial pattern.
--- scripts/coccinelle/misc/of_table.cocci | 81 ++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 scripts/coccinelle/misc/of_table.cocci
scripts/coccinelle/misc/of_table.cocci new file +81 -0
@@ -0,0 +1,81 @@ +/// Make sure of_device_id tables are NULL terminated +// +// Keywords: of_table +// Confidence: Medium +// Options: --include-headers + +virtual patch +virtual context +virtual org +virtual report + +@bad_of_table exists@ +identifier var, arr; +expression E; +@@ +... struct of_device_id arr[] = { + ..., + { + ..., + .var = E, + ... + } +}; + +@depends on bad_of_table && context@ +identifier var, arr; +expression E; +@@ + ... struct of_device_id arr[] = { + ..., + { + ..., +* .var = E, + ... + } +}; + +@depends on bad_of_table && patch@ +identifier var, arr; +expression E; +@@ +... struct of_device_id arr[] = { + ..., + { + ..., + .var = E, + ... +- } ++ }, ++ { } +}; + +@r depends on bad_of_table exists@ +position p1; +identifier var, arr; +expression E; +@@ +... struct of_device_id arr[] = { + ..., + { + ..., + .var = E, + ... + } + @p1 +}; + +@script:python depends on org@ +p1 << r.p1; +arr << r.arr; +@@ + +cocci.print_main(arr,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)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Quoted 37 lines · Stephen Boyd
Failure to terminate an
of_device_idtable can lead to confusing failures depending on where the compiler places the array. Add a check to make sure these tables are terminated. Thanks to Mitchel Humpherys for coming up with the initial pattern.Cc Mitchel Humpherys <[email protected]>Cc Julia Lawall <[email protected]>Cc Gilles Muller <[email protected]>Cc Nicolas Palix <nicolas.palix-wMUr/[email protected]>Cc Grant Likely <[email protected]>Cc Rob Herring <[email protected]>Signed-off-by Stephen Boyd <[email protected]>--- scripts/coccinelle/misc/of_table.cocci | 81 ++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 scripts/coccinelle/misc/of_table.cocciscripts/coccinelle/misc/of_table.cocci new file +13
-0@@ -0,0 +1,81 @@ +/// Make sure of_device_id tables are NULL terminated +// +// Keywords: of_table +// Confidence: Medium +// Options: --include-headers + +virtual patch +virtual context +virtual org +virtual report + +@bad_of_table exists@ +identifier var, arr;
scripts/coccinelle/misc/of_table.cocci line 23
Quoted 10 lines
scripts/coccinelle/misc/of_table.cocci new file +10
-0+expression E; +@@ +... struct of_device_id arr[] = { + ..., + { + ..., + .var = E, + ... + } +};
You shouldn't need any of the ...s in these rules.
julia
Quoted 62 lines
scripts/coccinelle/misc/of_table.cocci new file +57
-0+@depends on bad_of_table && context@ +identifier var, arr; +expression E; +@@ + ... struct of_device_id arr[] = { + ..., + { + ..., +* .var = E, + ... + } +}; + +@depends on bad_of_table && patch@ +identifier var, arr; +expression E; +@@ +... struct of_device_id arr[] = { + ..., + { + ..., + .var = E, + ... +- } ++ }, ++ { } +}; + +@r depends on bad_of_table exists@ +position p1; +identifier var, arr; +expression E; +@@ +... struct of_device_id arr[] = { + ..., + { + ..., + .var = E, + ... + } + @p1 +}; + +@script:python depends on org@ +p1 << r.p1; +arr << r.arr; +@@ + +cocci.print_main(arr,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)Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · Stephen Boyd
Failure to terminate an
of_device_idtable can lead to confusing failures depending on where the compiler places the array. Add a check to make sure these tables are terminated. Thanks to Mitchel Humpherys for coming up with the initial pattern.
I've definitely debugged one of those problems. Do you have any actual fixes or there are no errors in the kernel?
Rob
Quoted 105 lines
Cc Mitchel Humpherys <[email protected]>Cc Julia Lawall <[email protected]>Cc Gilles Muller <[email protected]>Cc Nicolas Palix <[email protected]>Cc Grant Likely <[email protected]>Cc Rob Herring <[email protected]>Signed-off-by Stephen Boyd <[email protected]>--- scripts/coccinelle/misc/of_table.cocci | 81 ++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 scripts/coccinelle/misc/of_table.cocciscripts/coccinelle/misc/of_table.cocci new file +81
-1@@ -0,0 +1,81 @@ +/// Make sure of_device_id tables are NULL terminated +// +// Keywords: of_table +// Confidence: Medium +// Options: --include-headers + +virtual patch +virtual context +virtual org +virtual report + +@bad_of_table exists@ +identifier var, arr; +expression E; +@@ +... struct of_device_id arr[] = { + ..., + { + ..., + .var = E, + ... + } +}; + +@depends on bad_of_table && context@ +identifier var, arr; +expression E; +@@ + ... struct of_device_id arr[] = { + ..., + { + ..., +* .var = E, + ... + } +}; + +@depends on bad_of_table && patch@ +identifier var, arr; +expression E; +@@ +... struct of_device_id arr[] = { + ..., + { + ..., + .var = E, + ... +- } ++ }, ++ { } +}; + +@r depends on bad_of_table exists@ +position p1; +identifier var, arr; +expression E; +@@ +... struct of_device_id arr[] = { + ..., + { + ..., + .var = E, + ... + } + @p1 +}; + +@script:python depends on org@ +p1 << r.p1; +arr << r.arr; +@@ + +cocci.print_main(arr,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) --The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Quoted 9 lines · Rob Herring
Quoted 4 lines · Stephen Boyd
Failure to terminate an
of_device_idtable can lead to confusing failures depending on where the compiler places the array. Add a check to make sure these tables are terminated. Thanks to Mitchel Humpherys for coming up with the initial pattern.I've definitely debugged one of those problems. Do you have any actual fixes or there are no errors in the kernel?
Yes I sent five patches out. Here's one for example
https://lkml.org/lkml/2014/5/23/731
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 12 lines · Julia Lawall
scripts/coccinelle/misc/of_table.cocci line 23
Quoted 8 lines · Stephen Boyd
+... struct
of_device_idarr[] = {scripts/coccinelle/misc/of_table.cocci new file +7
-0+ ..., + { + ..., + .var = E, + ... + } +};You shouldn't need any of the ...s in these rules.
Hm.. Removing all the ...s in these rules only gives me 3 matches now. I used to get 5.
Before
$ COCCI=scripts/coccinelle/misc/of_table.cocci make coccicheck MODE=report
Please check for false positives in the output before submitting a patch. When using "patch" mode, carefully review the patch before submitting it.
./sound/soc/pxa/pxa-ssp.c:810:36-37: pxa_ssp_of_ids is not NULL terminated at line 810 ./drivers/mfd/tps65218.c:199:32-33: of_tps65218_match_table is not NULL terminated at line 199 ./drivers/staging/mt29f_spinand/mt29f_spinand.c:926:34-35: spinand_dt is not NULL terminated at line 926 ./drivers/clk/clk-u300.c:1170:1-2: u300_clk_match is not NULL terminated at line 1170 ./drivers/clk/st/clkgen-pll.c:655:1-2: c32_gpu_pll_of_match is not NULL terminated at line 655
After
$ COCCI=scripts/coccinelle/misc/of_table.cocci make coccicheck MODE=report
Please check for false positives in the output before submitting a patch. When using "patch" mode, carefully review the patch before submitting it.
./sound/soc/pxa/pxa-ssp.c:810:36-37: pxa_ssp_of_ids is not NULL terminated at line 810 ./drivers/mfd/tps65218.c:199:32-33: of_tps65218_match_table is not NULL terminated at line 199 ./drivers/staging/mt29f_spinand/mt29f_spinand.c:926:34-35: spinand_dt is not NULL terminated at line 926
Removing most of the ...s seems to work though. I'll send a v2.
Signature · 7 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html