100-wifi-ath-add-struct_group-for-struct-ath_cycle_count.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. From e8053643b6d70e23a634f14e4408f3a6d1d3a6bf Mon Sep 17 00:00:00 2001
  2. From: Shiji Yang <[email protected]>
  3. Date: Sat, 27 May 2023 09:04:48 +0000
  4. Subject: [PATCH] wifi: ath: add struct_group for struct ath_cycle_counters
  5. Add a struct_group to around all members in struct ath_cycle_counters.
  6. It can help the compiler detect the intended bounds of the memcpy() and
  7. memset().
  8. This patch fixes the following build warning:
  9. In function 'fortify_memset_chk',
  10. inlined from 'ath9k_ps_wakeup' at /home/db/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/backports-6.1.24/drivers/net/wireless/ath/ath9k/main.c:140:3:
  11. ./include/linux/fortify-string.h:314:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
  12. 314 | __write_overflow_field(p_size_field, size);
  13. | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. Signed-off-by: Shiji Yang <[email protected]>
  15. ---
  16. drivers/net/wireless/ath/ath.h | 10 ++++++----
  17. drivers/net/wireless/ath/ath5k/ani.c | 2 +-
  18. drivers/net/wireless/ath/ath5k/base.c | 4 ++--
  19. drivers/net/wireless/ath/ath5k/mac80211-ops.c | 2 +-
  20. drivers/net/wireless/ath/ath9k/link.c | 2 +-
  21. drivers/net/wireless/ath/ath9k/main.c | 4 ++--
  22. drivers/net/wireless/ath/hw.c | 2 +-
  23. 7 files changed, 14 insertions(+), 12 deletions(-)
  24. --- a/drivers/net/wireless/ath/ath.h
  25. +++ b/drivers/net/wireless/ath/ath.h
  26. @@ -43,10 +43,12 @@ struct ath_ani {
  27. };
  28. struct ath_cycle_counters {
  29. - u32 cycles;
  30. - u32 rx_busy;
  31. - u32 rx_frame;
  32. - u32 tx_frame;
  33. + struct_group(cnts,
  34. + u32 cycles;
  35. + u32 rx_busy;
  36. + u32 rx_frame;
  37. + u32 tx_frame;
  38. + );
  39. };
  40. enum ath_device_state {
  41. --- a/drivers/net/wireless/ath/ath5k/ani.c
  42. +++ b/drivers/net/wireless/ath/ath5k/ani.c
  43. @@ -379,7 +379,7 @@ ath5k_hw_ani_get_listen_time(struct ath5
  44. spin_lock_bh(&common->cc_lock);
  45. ath_hw_cycle_counters_update(common);
  46. - memcpy(&as->last_cc, &common->cc_ani, sizeof(as->last_cc));
  47. + memcpy(&as->last_cc.cnts, &common->cc_ani.cnts, sizeof(as->last_cc.cnts));
  48. /* clears common->cc_ani */
  49. listen = ath_hw_get_listen_time(common);
  50. --- a/drivers/net/wireless/ath/ath5k/base.c
  51. +++ b/drivers/net/wireless/ath/ath5k/base.c
  52. @@ -2985,8 +2985,8 @@ ath5k_reset(struct ath5k_hw *ah, struct
  53. memset(&ah->survey, 0, sizeof(ah->survey));
  54. spin_lock_bh(&common->cc_lock);
  55. ath_hw_cycle_counters_update(common);
  56. - memset(&common->cc_survey, 0, sizeof(common->cc_survey));
  57. - memset(&common->cc_ani, 0, sizeof(common->cc_ani));
  58. + memset(&common->cc_survey.cnts, 0, sizeof(common->cc_survey.cnts));
  59. + memset(&common->cc_ani.cnts, 0, sizeof(common->cc_ani.cnts));
  60. spin_unlock_bh(&common->cc_lock);
  61. /*
  62. --- a/drivers/net/wireless/ath/ath5k/mac80211-ops.c
  63. +++ b/drivers/net/wireless/ath/ath5k/mac80211-ops.c
  64. @@ -664,7 +664,7 @@ ath5k_get_survey(struct ieee80211_hw *hw
  65. ah->survey.time_rx += cc->rx_frame / div;
  66. ah->survey.time_tx += cc->tx_frame / div;
  67. }
  68. - memset(cc, 0, sizeof(*cc));
  69. + memset(&cc->cnts, 0, sizeof(cc->cnts));
  70. spin_unlock_bh(&common->cc_lock);
  71. memcpy(survey, &ah->survey, sizeof(*survey));
  72. --- a/drivers/net/wireless/ath/ath9k/link.c
  73. +++ b/drivers/net/wireless/ath/ath9k/link.c
  74. @@ -536,7 +536,7 @@ int ath_update_survey_stats(struct ath_s
  75. if (cc->cycles > 0)
  76. ret = cc->rx_busy * 100 / cc->cycles;
  77. - memset(cc, 0, sizeof(*cc));
  78. + memset(&cc->cnts, 0, sizeof(cc->cnts));
  79. ath_update_survey_nf(sc, pos);
  80. --- a/drivers/net/wireless/ath/ath9k/main.c
  81. +++ b/drivers/net/wireless/ath/ath9k/main.c
  82. @@ -135,8 +135,8 @@ void ath9k_ps_wakeup(struct ath_softc *s
  83. if (power_mode != ATH9K_PM_AWAKE) {
  84. spin_lock(&common->cc_lock);
  85. ath_hw_cycle_counters_update(common);
  86. - memset(&common->cc_survey, 0, sizeof(common->cc_survey));
  87. - memset(&common->cc_ani, 0, sizeof(common->cc_ani));
  88. + memset(&common->cc_survey.cnts, 0, sizeof(common->cc_survey.cnts));
  89. + memset(&common->cc_ani.cnts, 0, sizeof(common->cc_ani.cnts));
  90. spin_unlock(&common->cc_lock);
  91. }
  92. --- a/drivers/net/wireless/ath/hw.c
  93. +++ b/drivers/net/wireless/ath/hw.c
  94. @@ -183,7 +183,7 @@ int32_t ath_hw_get_listen_time(struct at
  95. listen_time = (cc->cycles - cc->rx_frame - cc->tx_frame) /
  96. (common->clockrate * 1000);
  97. - memset(cc, 0, sizeof(*cc));
  98. + memset(&cc->cnts, 0, sizeof(cc->cnts));
  99. return listen_time;
  100. }