Commit c4585ed
Bluetooth: hci_conn, hci_sync: Use __counted_by() to avoid -Wfamnae warnings
Prepare for the coming implementation by GCC and Clang of the
__counted_by attribute. Flexible array members annotated with
__counted_by can have their accesses bounds-checked at run-time
via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE
(for strcpy/memcpy-family functions).
Also, -Wflex-array-member-not-at-end is coming in GCC-14, and we are
getting ready to enable it globally.
So, use the `DEFINE_FLEX()` helper for multiple on-stack definitions
of a flexible structure where the size of the flexible-array member
is known at compile-time, and refactor the rest of the code,
accordingly.
Notice that, due to the use of `__counted_by()` in `struct
hci_cp_le_create_cis`, the for loop in function `hci_cs_le_create_cis()`
had to be modified. Once the index `i`, through which `cp->cis[i]` is
accessed, falls in the interval [0, cp->num_cis), `cp->num_cis` cannot
be decremented all the way down to zero while accessing `cp->cis[]`:
net/bluetooth/hci_event.c:4310:
4310 for (i = 0; cp->num_cis; cp->num_cis--, i++) {
...
4314 handle = __le16_to_cpu(cp->cis[i].cis_handle);
otherwise, only half (one iteration before `cp->num_cis == i`) or half
plus one (one iteration before `cp->num_cis < i`) of the items in the
array will be accessed before running into an out-of-bounds issue. So,
in order to avoid this, set `cp->num_cis` to zero just after the for
loop.
Also, make use of `aux_num_cis` variable to update `cmd->num_cis` after
a `list_for_each_entry_rcu()` loop.
With these changes, fix the following warnings:
net/bluetooth/hci_sync.c:1239:56: warning: structure containing a flexible
array member is not at the end of another structure
[-Wflex-array-member-not-at-end]
net/bluetooth/hci_sync.c:1415:51: warning: structure containing a flexible
array member is not at the end of another structure
[-Wflex-array-member-not-at-end]
net/bluetooth/hci_sync.c:1731:51: warning: structure containing a flexible
array member is not at the end of another structure
[-Wflex-array-member-not-at-end]
net/bluetooth/hci_sync.c:6497:45: warning: structure containing a flexible
array member is not at the end of another structure
[-Wflex-array-member-not-at-end]
Link: KSPP#202
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>1 parent 3487cda commit c4585ed
3 files changed
Lines changed: 40 additions & 55 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2026 | 2026 | | |
2027 | 2027 | | |
2028 | 2028 | | |
2029 | | - | |
| 2029 | + | |
2030 | 2030 | | |
2031 | 2031 | | |
2032 | 2032 | | |
| |||
2035 | 2035 | | |
2036 | 2036 | | |
2037 | 2037 | | |
2038 | | - | |
| 2038 | + | |
2039 | 2039 | | |
2040 | 2040 | | |
2041 | 2041 | | |
| |||
2061 | 2061 | | |
2062 | 2062 | | |
2063 | 2063 | | |
2064 | | - | |
| 2064 | + | |
2065 | 2065 | | |
2066 | 2066 | | |
2067 | 2067 | | |
| |||
2162 | 2162 | | |
2163 | 2163 | | |
2164 | 2164 | | |
2165 | | - | |
| 2165 | + | |
2166 | 2166 | | |
2167 | 2167 | | |
2168 | 2168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4307 | 4307 | | |
4308 | 4308 | | |
4309 | 4309 | | |
4310 | | - | |
| 4310 | + | |
4311 | 4311 | | |
4312 | 4312 | | |
4313 | 4313 | | |
| |||
4323 | 4323 | | |
4324 | 4324 | | |
4325 | 4325 | | |
| 4326 | + | |
4326 | 4327 | | |
4327 | 4328 | | |
4328 | 4329 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1235 | 1235 | | |
1236 | 1236 | | |
1237 | 1237 | | |
1238 | | - | |
1239 | | - | |
1240 | | - | |
1241 | | - | |
| 1238 | + | |
| 1239 | + | |
1242 | 1240 | | |
1243 | 1241 | | |
1244 | 1242 | | |
1245 | 1243 | | |
1246 | | - | |
1247 | | - | |
1248 | 1244 | | |
1249 | 1245 | | |
1250 | 1246 | | |
1251 | 1247 | | |
1252 | 1248 | | |
1253 | 1249 | | |
1254 | | - | |
| 1250 | + | |
1255 | 1251 | | |
1256 | | - | |
1257 | | - | |
1258 | | - | |
1259 | | - | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
1260 | 1256 | | |
1261 | 1257 | | |
1262 | | - | |
| 1258 | + | |
1263 | 1259 | | |
1264 | 1260 | | |
1265 | 1261 | | |
1266 | 1262 | | |
1267 | 1263 | | |
1268 | 1264 | | |
1269 | 1265 | | |
1270 | | - | |
| 1266 | + | |
1271 | 1267 | | |
1272 | 1268 | | |
1273 | 1269 | | |
| |||
1411 | 1407 | | |
1412 | 1408 | | |
1413 | 1409 | | |
1414 | | - | |
1415 | | - | |
1416 | | - | |
1417 | | - | |
| 1410 | + | |
| 1411 | + | |
1418 | 1412 | | |
1419 | 1413 | | |
1420 | | - | |
1421 | | - | |
1422 | 1414 | | |
1423 | 1415 | | |
1424 | 1416 | | |
1425 | 1417 | | |
1426 | 1418 | | |
1427 | 1419 | | |
1428 | 1420 | | |
1429 | | - | |
| 1421 | + | |
1430 | 1422 | | |
1431 | | - | |
1432 | | - | |
1433 | | - | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
1434 | 1426 | | |
1435 | 1427 | | |
1436 | | - | |
| 1428 | + | |
1437 | 1429 | | |
1438 | 1430 | | |
1439 | 1431 | | |
| |||
1727 | 1719 | | |
1728 | 1720 | | |
1729 | 1721 | | |
1730 | | - | |
1731 | | - | |
1732 | | - | |
1733 | | - | |
| 1722 | + | |
| 1723 | + | |
1734 | 1724 | | |
1735 | 1725 | | |
1736 | 1726 | | |
1737 | 1727 | | |
1738 | | - | |
1739 | | - | |
1740 | 1728 | | |
1741 | 1729 | | |
1742 | 1730 | | |
1743 | 1731 | | |
1744 | 1732 | | |
1745 | 1733 | | |
1746 | | - | |
| 1734 | + | |
1747 | 1735 | | |
1748 | | - | |
1749 | | - | |
1750 | | - | |
1751 | | - | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
1752 | 1740 | | |
1753 | 1741 | | |
1754 | | - | |
| 1742 | + | |
1755 | 1743 | | |
1756 | 1744 | | |
1757 | 1745 | | |
| |||
1760 | 1748 | | |
1761 | 1749 | | |
1762 | 1750 | | |
1763 | | - | |
| 1751 | + | |
1764 | 1752 | | |
1765 | 1753 | | |
1766 | 1754 | | |
| |||
6493 | 6481 | | |
6494 | 6482 | | |
6495 | 6483 | | |
6496 | | - | |
6497 | | - | |
6498 | | - | |
6499 | | - | |
| 6484 | + | |
| 6485 | + | |
6500 | 6486 | | |
6501 | 6487 | | |
6502 | 6488 | | |
| |||
6523 | 6509 | | |
6524 | 6510 | | |
6525 | 6511 | | |
6526 | | - | |
6527 | | - | |
6528 | 6512 | | |
6529 | 6513 | | |
6530 | 6514 | | |
| |||
6561 | 6545 | | |
6562 | 6546 | | |
6563 | 6547 | | |
6564 | | - | |
| 6548 | + | |
6565 | 6549 | | |
6566 | 6550 | | |
6567 | 6551 | | |
| |||
6570 | 6554 | | |
6571 | 6555 | | |
6572 | 6556 | | |
6573 | | - | |
| 6557 | + | |
6574 | 6558 | | |
6575 | | - | |
| 6559 | + | |
6576 | 6560 | | |
6577 | 6561 | | |
| 6562 | + | |
6578 | 6563 | | |
6579 | 6564 | | |
6580 | 6565 | | |
6581 | 6566 | | |
6582 | 6567 | | |
6583 | 6568 | | |
6584 | | - | |
| 6569 | + | |
6585 | 6570 | | |
6586 | 6571 | | |
6587 | 6572 | | |
6588 | 6573 | | |
6589 | | - | |
6590 | | - | |
6591 | | - | |
| 6574 | + | |
| 6575 | + | |
6592 | 6576 | | |
6593 | 6577 | | |
6594 | 6578 | | |
| |||
0 commit comments