generic: replace simple AQR hack patch with upstream version
[openwrt/staging/jow.git] / package / kernel / mac80211 / patches / ath / 100-wifi-ath-add-struct_group-for-struct-ath_cycle_count.patch
1 From e8053643b6d70e23a634f14e4408f3a6d1d3a6bf Mon Sep 17 00:00:00 2001
2 From: Shiji Yang <yangshiji66@qq.com>
3 Date: Sat, 27 May 2023 09:04:48 +0000
4 Subject: [PATCH] wifi: ath: add struct_group for struct ath_cycle_counters
5
6 Add a struct_group to around all members in struct ath_cycle_counters.
7 It can help the compiler detect the intended bounds of the memcpy() and
8 memset().
9
10 This patch fixes the following build warning:
11
12 In function 'fortify_memset_chk',
13 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:
14 ./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]
15 314 | __write_overflow_field(p_size_field, size);
16 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17
18 Signed-off-by: Shiji Yang <yangshiji66@qq.com>
19 ---
20 drivers/net/wireless/ath/ath.h | 10 ++++++----
21 drivers/net/wireless/ath/ath5k/ani.c | 2 +-
22 drivers/net/wireless/ath/ath5k/base.c | 4 ++--
23 drivers/net/wireless/ath/ath5k/mac80211-ops.c | 2 +-
24 drivers/net/wireless/ath/ath9k/link.c | 2 +-
25 drivers/net/wireless/ath/ath9k/main.c | 4 ++--
26 drivers/net/wireless/ath/hw.c | 2 +-
27 7 files changed, 14 insertions(+), 12 deletions(-)
28
29 --- a/drivers/net/wireless/ath/ath.h
30 +++ b/drivers/net/wireless/ath/ath.h
31 @@ -43,10 +43,12 @@ struct ath_ani {
32 };
33
34 struct ath_cycle_counters {
35 - u32 cycles;
36 - u32 rx_busy;
37 - u32 rx_frame;
38 - u32 tx_frame;
39 + struct_group(cnts,
40 + u32 cycles;
41 + u32 rx_busy;
42 + u32 rx_frame;
43 + u32 tx_frame;
44 + );
45 };
46
47 enum ath_device_state {
48 --- a/drivers/net/wireless/ath/ath5k/ani.c
49 +++ b/drivers/net/wireless/ath/ath5k/ani.c
50 @@ -379,7 +379,7 @@ ath5k_hw_ani_get_listen_time(struct ath5
51 spin_lock_bh(&common->cc_lock);
52
53 ath_hw_cycle_counters_update(common);
54 - memcpy(&as->last_cc, &common->cc_ani, sizeof(as->last_cc));
55 + memcpy(&as->last_cc.cnts, &common->cc_ani.cnts, sizeof(as->last_cc.cnts));
56
57 /* clears common->cc_ani */
58 listen = ath_hw_get_listen_time(common);
59 --- a/drivers/net/wireless/ath/ath5k/base.c
60 +++ b/drivers/net/wireless/ath/ath5k/base.c
61 @@ -2985,8 +2985,8 @@ ath5k_reset(struct ath5k_hw *ah, struct
62 memset(&ah->survey, 0, sizeof(ah->survey));
63 spin_lock_bh(&common->cc_lock);
64 ath_hw_cycle_counters_update(common);
65 - memset(&common->cc_survey, 0, sizeof(common->cc_survey));
66 - memset(&common->cc_ani, 0, sizeof(common->cc_ani));
67 + memset(&common->cc_survey.cnts, 0, sizeof(common->cc_survey.cnts));
68 + memset(&common->cc_ani.cnts, 0, sizeof(common->cc_ani.cnts));
69 spin_unlock_bh(&common->cc_lock);
70
71 /*
72 --- a/drivers/net/wireless/ath/ath5k/mac80211-ops.c
73 +++ b/drivers/net/wireless/ath/ath5k/mac80211-ops.c
74 @@ -665,7 +665,7 @@ ath5k_get_survey(struct ieee80211_hw *hw
75 ah->survey.time_rx += cc->rx_frame / div;
76 ah->survey.time_tx += cc->tx_frame / div;
77 }
78 - memset(cc, 0, sizeof(*cc));
79 + memset(&cc->cnts, 0, sizeof(cc->cnts));
80 spin_unlock_bh(&common->cc_lock);
81
82 memcpy(survey, &ah->survey, sizeof(*survey));
83 --- a/drivers/net/wireless/ath/ath9k/link.c
84 +++ b/drivers/net/wireless/ath/ath9k/link.c
85 @@ -536,7 +536,7 @@ int ath_update_survey_stats(struct ath_s
86 if (cc->cycles > 0)
87 ret = cc->rx_busy * 100 / cc->cycles;
88
89 - memset(cc, 0, sizeof(*cc));
90 + memset(&cc->cnts, 0, sizeof(cc->cnts));
91
92 ath_update_survey_nf(sc, pos);
93
94 --- a/drivers/net/wireless/ath/ath9k/main.c
95 +++ b/drivers/net/wireless/ath/ath9k/main.c
96 @@ -135,8 +135,8 @@ void ath9k_ps_wakeup(struct ath_softc *s
97 if (power_mode != ATH9K_PM_AWAKE) {
98 spin_lock(&common->cc_lock);
99 ath_hw_cycle_counters_update(common);
100 - memset(&common->cc_survey, 0, sizeof(common->cc_survey));
101 - memset(&common->cc_ani, 0, sizeof(common->cc_ani));
102 + memset(&common->cc_survey.cnts, 0, sizeof(common->cc_survey.cnts));
103 + memset(&common->cc_ani.cnts, 0, sizeof(common->cc_ani.cnts));
104 spin_unlock(&common->cc_lock);
105 }
106
107 --- a/drivers/net/wireless/ath/hw.c
108 +++ b/drivers/net/wireless/ath/hw.c
109 @@ -183,7 +183,7 @@ int32_t ath_hw_get_listen_time(struct at
110 listen_time = (cc->cycles - cc->rx_frame - cc->tx_frame) /
111 (common->clockrate * 1000);
112
113 - memset(cc, 0, sizeof(*cc));
114 + memset(&cc->cnts, 0, sizeof(cc->cnts));
115
116 return listen_time;
117 }