linux-stable/include/net/bluetooth
Linus Torvalds 8926dd7e90 bluetooth: don't use bitmaps for random flag accesses
[ Upstream commit e1cff7002b ]

The bluetooth code uses our bitmap infrastructure for the two bits (!)
of connection setup flags, and in the process causes odd problems when
it converts between a bitmap and just the regular values of said bits.

It's completely pointless to do things like bitmap_to_arr32() to convert
a bitmap into a u32.  It shoudln't have been a bitmap in the first
place.  The reason to use bitmaps is if you have arbitrary number of
bits you want to manage (not two!), or if you rely on the atomicity
guarantees of the bitmap setting and clearing.

The code could use an "atomic_t" and use "atomic_or/andnot()" to set and
clear the bit values, but considering that it then copies the bitmaps
around with "bitmap_to_arr32()" and friends, there clearly cannot be a
lot of atomicity requirements.

So just use a regular integer.

In the process, this avoids the warnings about erroneous use of
bitmap_from_u64() which were triggered on 32-bit architectures when
conversion from a u64 would access two words (and, surprise, surprise,
only one word is needed - and indeed overkill - for a 2-bit bitmap).

That was always problematic, but the compiler seems to notice it and
warn about the invalid pattern only after commit 0a97953fd2 ("lib: add
bitmap_{from,to}_arr64") changed the exact implementation details of
'bitmap_from_u64()', as reported by Sudip Mukherjee and Stephen Rothwell.

Fixes: fe92ee6425 ("Bluetooth: hci_core: Rework hci_conn_params flags")
Link: https://lore.kernel.org/all/YpyJ9qTNHJzz0FHY@debian/
Link: https://lore.kernel.org/all/20220606080631.0c3014f2@canb.auug.org.au/
Link: https://lore.kernel.org/all/20220605162537.1604762-1-yury.norov@gmail.com/
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Reported-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Reviewed-by: Yury Norov <yury.norov@gmail.com>
Cc: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Cc: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-06-14 18:41:26 +02:00
..
bluetooth.h Bluetooth: Fix not checking for valid hdev on bt_dev_{info,warn,err,dbg} 2022-04-13 19:27:19 +02:00
hci.h Bluetooth: HCI: Add HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN quirk 2022-06-09 10:25:27 +02:00
hci_core.h bluetooth: don't use bitmaps for random flag accesses 2022-06-14 18:41:26 +02:00
hci_mon.h Bluetooth: monitor: Add support for ISO packets 2020-01-15 22:28:51 +01:00
hci_sock.h Bluetooth: Use only 8 bits for the HCI CMSG state flags 2020-06-12 15:10:46 +02:00
hci_sync.h Bluetooth: hci_sync: Add hci_le_create_conn_sync 2021-12-22 23:01:35 +01:00
l2cap.h Bluetooth: L2CAP: Fix not checking for maximum number of DCID 2021-03-15 21:08:33 +01:00
mgmt.h Bluetooth: Send device found event on name resolve failure 2021-11-25 21:08:19 +01:00
rfcomm.h Bluetooth: Replace zero-length array with flexible-array member 2020-02-28 08:30:02 +01:00
sco.h Bluetooth: Add support for BT_PKT_STATUS CMSG data for SCO connections 2020-06-12 15:08:49 +02:00