of_table.cocci 1.3 KB

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