of_table.cocci 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /// Make sure (of/i2c/platform)_device_id tables are NULL terminated
  2. //
  3. // Keywords: of_table i2c_table platform_table
  4. // Confidence: Medium
  5. // Options: --include-headers
  6. virtual patch
  7. virtual context
  8. virtual org
  9. virtual report
  10. @depends on context@
  11. identifier var, arr;
  12. expression E;
  13. @@
  14. (
  15. struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
  16. ...,
  17. {
  18. .var = E,
  19. * }
  20. };
  21. |
  22. struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
  23. ...,
  24. * { ..., E, ... },
  25. };
  26. )
  27. @depends on patch@
  28. identifier var, arr;
  29. expression E;
  30. @@
  31. (
  32. struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
  33. ...,
  34. {
  35. .var = E,
  36. - }
  37. + },
  38. + { }
  39. };
  40. |
  41. struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
  42. ...,
  43. { ..., E, ... },
  44. + { },
  45. };
  46. )
  47. @r depends on org || report@
  48. position p1;
  49. identifier var, arr;
  50. expression E;
  51. @@
  52. (
  53. struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
  54. ...,
  55. {
  56. .var = E,
  57. }
  58. @p1
  59. };
  60. |
  61. struct \(of_device_id \| i2c_device_id \| platform_device_id\) arr[] = {
  62. ...,
  63. { ..., E, ... }
  64. @p1
  65. };
  66. )
  67. @script:python depends on org@
  68. p1 << r.p1;
  69. arr << r.arr;
  70. @@
  71. cocci.print_main(arr,p1)
  72. @script:python depends on report@
  73. p1 << r.p1;
  74. arr << r.arr;
  75. @@
  76. msg = "%s is not NULL terminated at line %s" % (arr, p1[0].line)
  77. coccilib.report.print_report(p1[0],msg)