of_table.cocci 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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)