Debian Codegraph @

gcc/testsuite/gcc.dg/analyzer/torture/asm-x86-linux-wfx_get_ps_timeout-full.c

raw
1 /* { dg-do compile { target x86_64-*-* } } */
2 /* { dg-require-effective-target lp64 } */
3 /* { dg-additional-options "-std=gnu17 -fsanitize=bounds -fno-analyzer-call-summaries" } */
4 /* { dg-skip-if "" { *-*-* } { "-O0" } { "" } } */
5
6 /* Reduced from linux kernel: drivers/staging/wfx/sta.c (GPL-2.0)
7 on x86_64 with "allyesconfig"
8
9 This test is deliberately not fully reduced, as an integration test
10 that the analyzer doesn't emit bogus "dereference of NULL" warnings
11 on the repeated wdev_to_wvif calls. */
12
13 #define NULL ((void *)0)
14
15 /* Types. */
16
17 typedef unsigned char __u8;
18 typedef unsigned short __u16;
19 __extension__ typedef unsigned long long __u64;
20
21 typedef __u8 u8;
22 typedef __u16 u16;
23 typedef __u64 u64;
24
25 enum { false = 0, true = 1 };
26 typedef _Bool bool;
27
28 struct device;
29
30 typedef struct {
31 int counter;
32 } atomic_t;
33
34 struct static_key {
35 atomic_t enabled;
36 union {
37 unsigned long type;
38 struct jump_entry *entries;
39 struct static_key_mod *next;
40 };
41 };
42
43 struct static_key_true {
44 struct static_key key;
45 };
46
47 struct static_key_false {
48 struct static_key key;
49 };
50
51 struct _ddebug {
52 const char *modname;
53 const char *function;
54 const char *filename;
55 const char *format;
56 unsigned int lineno : 18;
57 unsigned int flags : 8;
58
59 union {
60 struct static_key_true dd_key_true;
61 struct static_key_false dd_key_false;
62 } key;
63
64 } __attribute__((aligned(8)));
65
66 enum nl80211_iftype {
67 /* [...snip...] */
68 NL80211_IFTYPE_AP,
69 /* [...snip...] */
70 NUM_NL80211_IFTYPES,
71 NL80211_IFTYPE_MAX = NUM_NL80211_IFTYPES - 1
72 };
73
74 struct ieee80211_channel {
75 /* [...snip...] */
76 u16 hw_value;
77 /* [...snip...] */
78 };
79
80 struct cfg80211_chan_def {
81 struct ieee80211_channel *chan;
82 /* [...snip...] */
83 };
84
85 struct ieee80211_bss_conf {
86 /* [...snip...] */
87 bool assoc, ibss_joined;
88 /* [...snip...] */
89 struct cfg80211_chan_def chandef;
90 /* [...snip...] */
91 bool ps;
92 /* [...snip...] */
93 };
94
95 struct ieee80211_conf {
96 /* [...snip...] */
97 int power_level, dynamic_ps_timeout;
98 /* [...snip...] */
99 };
100
101 struct ieee80211_vif {
102 enum nl80211_iftype type;
103 struct ieee80211_bss_conf bss_conf;
104 /* [...snip...] */
105 u8 drv_priv[] __attribute__((__aligned__(sizeof(void *))));
106 };
107
108 struct ieee80211_hw {
109 struct ieee80211_conf conf;
110 /* [...snip...] */
111 };
112
113 struct wfx_dev {
114 /* [...snip...] */
115 struct device *dev;
116 struct ieee80211_hw *hw;
117 struct ieee80211_vif *vif[2];
118 /* [...snip...] */
119 int force_ps_timeout;
120 };
121
122 struct wfx_vif {
123 struct wfx_dev *wdev;
124 struct ieee80211_vif *vif;
125 /* [...snip...] */
126 };
127
128 /* Function decls. */
129
130 extern __attribute__((__format__(printf, 1, 2))) void
131 __warn_printk(const char *fmt, ...);
132
133 extern bool ____wrong_branch_error(void);
134
135 extern __attribute__((__format__(printf, 3, 4))) void
136 __dynamic_dev_dbg(struct _ddebug *descriptor, const struct device *dev,
137 const char *fmt, ...);
138
139 bool wfx_api_older_than(struct wfx_dev *wdev, int major, int minor);
140
141 /* Function defns. */
142
143 static inline unsigned long array_index_mask_nospec(unsigned long index,
144 unsigned long size) {
145 unsigned long mask;
146
147 asm volatile("cmp %1,%2; sbb %0,%0;"
148 : "=r"(mask)
149 : "g"(size), "r"(index)
150 : "cc");
151 return mask;
152 }
153
154 static inline __attribute__((__always_inline__)) bool
155 arch_static_branch(struct static_key *key, bool branch) {
156 asm goto("1:"
157 "jmp %l[l_yes] # objtool NOPs this \n\t"
158 ".pushsection __jump_table, \"aw\" \n\t"
159 " "
160 ".balign 8"
161 " "
162 "\n\t"
163 ".long 1b - . \n\t"
164 ".long %l[l_yes] - . \n\t"
165 " "
166 ".quad"
167 " "
168 "%c0 + %c1 - .\n\t"
169 ".popsection \n\t"
170 :
171 : "i"(key), "i"(2 | branch)
172 :
173 : l_yes);
174 asm("");
175
176 return false;
177 l_yes:
178 return true;
179 }
180
181 static inline __attribute__((__always_inline__)) bool
182 arch_static_branch_jump(struct static_key *const key, const bool branch) {
183 asm goto("1:"
184 "jmp %l[l_yes]\n\t"
185 ".pushsection __jump_table, \"aw\" \n\t"
186 " "
187 ".balign 8"
188 " "
189 "\n\t"
190 ".long 1b - . \n\t"
191 ".long %l[l_yes] - . \n\t"
192 " "
193 ".quad"
194 " "
195 "%c0 + %c1 - .\n\t"
196 ".popsection \n\t"
197 :
198 : "i"(key), "i"(branch)
199 :
200 : l_yes);
201 asm("");
202
203 return false;
204 l_yes:
205 return true;
206 }
207
208 static inline struct wfx_vif *wdev_to_wvif(struct wfx_dev *wdev, int vif_id) {
209 if (vif_id >=
210 (sizeof(wdev->vif) / sizeof((wdev->vif)[0]) + ((int)(sizeof(struct {
211 int : (-!!(__builtin_types_compatible_p(typeof((wdev->vif)),
212 typeof(&(wdev->vif)[0]))));
213 }))))) {
214 static struct _ddebug __attribute__((__aligned__(8)))
215 __attribute__((__section__("__dyndbg"))) __UNIQUE_ID_ddebug1678 = {
216 .modname = "wfx",
217 .function = __func__,
218 .filename = "drivers/staging/wfx/wfx.h",
219 .format = ("requesting non-existent vif: %d\n"),
220 .lineno = 97,
221 .flags = 0,
222 .key.dd_key_false = ((struct static_key_false){
223 .key = {.enabled = {0}, {.entries = (void *)0UL}},
224 })};
225 if (({
226 bool branch;
227 if (__builtin_types_compatible_p(
228 typeof(*&__UNIQUE_ID_ddebug1678.key.dd_key_false),
229 struct static_key_true))
230 branch = arch_static_branch_jump(
231 &(&__UNIQUE_ID_ddebug1678.key.dd_key_false)->key, false);
232 else if (__builtin_types_compatible_p(
233 typeof(*&__UNIQUE_ID_ddebug1678.key.dd_key_false),
234 struct static_key_false))
235 branch = arch_static_branch(
236 &(&__UNIQUE_ID_ddebug1678.key.dd_key_false)->key, false);
237 else
238 branch = ____wrong_branch_error();
239 __builtin_expect(!!(branch), 0);
240 }))
241 __dynamic_dev_dbg(&__UNIQUE_ID_ddebug1678, wdev->dev,
242 "requesting non-existent vif: %d\n", vif_id);
243 return NULL;
244 }
245 typeof(vif_id) _i = (vif_id);
246 typeof((sizeof(wdev->vif) / sizeof((wdev->vif)[0]) + ((int)(sizeof(struct {
247 int : (-!!(__builtin_types_compatible_p(typeof((wdev->vif)),
248 typeof(&(wdev->vif)[0]))));
249 }))))) _s =
250 ((sizeof(wdev->vif) / sizeof((wdev->vif)[0]) + ((int)(sizeof(struct {
251 int : (-!!(__builtin_types_compatible_p(typeof((wdev->vif)),
252 typeof(&(wdev->vif)[0]))));
253 })))));
254 unsigned long _mask = array_index_mask_nospec(_i, _s);
255 vif_id = (typeof(_i))(_i & _mask);
256 if (!wdev->vif[vif_id]) {
257 static struct _ddebug __attribute__((__aligned__(8)))
258 __attribute__((__section__("__dyndbg"))) __UNIQUE_ID_ddebug1681 = {
259 .modname = "wfx",
260 .function = __func__,
261 .filename = "drivers/staging/wfx/wfx.h",
262 .format = ("requesting non-allocated vif: %d\n"),
263 .lineno = 102,
264 .flags = 0,
265 .key.dd_key_false = ((struct static_key_false){
266 .key = {.enabled = {0}, {.entries = (void *)0UL}},
267 })};
268 if (({
269 bool branch;
270 if (__builtin_types_compatible_p(
271 typeof(*&__UNIQUE_ID_ddebug1681.key.dd_key_false),
272 struct static_key_true))
273 branch = arch_static_branch_jump(
274 &(&__UNIQUE_ID_ddebug1681.key.dd_key_false)->key, false);
275 else if (__builtin_types_compatible_p(
276 typeof(*&__UNIQUE_ID_ddebug1681.key.dd_key_false),
277 struct static_key_false))
278 branch = arch_static_branch(
279 &(&__UNIQUE_ID_ddebug1681.key.dd_key_false)->key, false);
280 else
281 branch = ____wrong_branch_error();
282 __builtin_expect(!!(branch), 0);
283 }))
284 __dynamic_dev_dbg(&__UNIQUE_ID_ddebug1681, wdev->dev,
285 "requesting non-allocated vif: %d\n", vif_id);
286 return NULL;
287 }
288 return (struct wfx_vif *)wdev->vif[vif_id]->drv_priv;
289 }
290
291 int wfx_get_ps_timeout(struct wfx_vif *wvif, bool *enable_ps) {
292 struct ieee80211_channel *chan0 = NULL, *chan1 = NULL;
293 struct ieee80211_conf *conf = &wvif->wdev->hw->conf;
294
295 if (wdev_to_wvif(wvif->wdev, 0))
296 chan0 = wdev_to_wvif(wvif->wdev, 0)->vif->bss_conf.chandef.chan; /* { dg-bogus "dereference of NULL" } */
297 if (wdev_to_wvif(wvif->wdev, 1))
298 chan1 = wdev_to_wvif(wvif->wdev, 1)->vif->bss_conf.chandef.chan; /* { dg-bogus "dereference of NULL" } */
299 if (chan0 && chan1 && chan0->hw_value != chan1->hw_value &&
300 wvif->vif->type != NL80211_IFTYPE_AP) {
301
302 if (enable_ps)
303 *enable_ps = true;
304 if (wvif->wdev->force_ps_timeout > -1)
305 return wvif->wdev->force_ps_timeout;
306 else if (wfx_api_older_than(wvif->wdev, 3, 2))
307 return 0;
308 else
309 return 30;
310 }
311 if (enable_ps)
312 *enable_ps = wvif->vif->bss_conf.ps;
313 if (wvif->wdev->force_ps_timeout > -1)
314 return wvif->wdev->force_ps_timeout;
315 else if (wvif->vif->bss_conf.assoc && wvif->vif->bss_conf.ps)
316 return conf->dynamic_ps_timeout;
317 else
318 return -1;
319 }