Skip to content

Commit

Permalink
Bluetooth: hci_event: shut up a false-positive warning
Browse files Browse the repository at this point in the history
[ Upstream commit a5812c6 ]

Turning on -Wstringop-overflow globally exposed a misleading compiler
warning in bluetooth:

net/bluetooth/hci_event.c: In function 'hci_cc_read_class_of_dev':
net/bluetooth/hci_event.c:524:9: error: 'memcpy' writing 3 bytes into a
region of size 0 overflows the destination [-Werror=stringop-overflow=]
  524 |         memcpy(hdev->dev_class, rp->dev_class, 3);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The problem here is the check for hdev being NULL in bt_dev_dbg() that
leads the compiler to conclude that hdev->dev_class might be an invalid
pointer access.

Add another explicit check for the same condition to make sure gcc sees
this cannot happen.

Fixes: a9de924 ("[Bluetooth] Switch from OGF+OCF to using only opcodes")
Fixes: 1b56c90 ("Makefile: Enable -Wstringop-overflow globally")
Signed-off-by: Arnd Bergmann <[email protected]>
Signed-off-by: Luiz Augusto von Dentz <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
arndb authored and gregkh committed Jan 1, 2024
1 parent fc64715 commit a1986c4
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions net/bluetooth/hci_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ static u8 hci_cc_read_class_of_dev(struct hci_dev *hdev, void *data,
{
struct hci_rp_read_class_of_dev *rp = data;

if (WARN_ON(!hdev))
return HCI_ERROR_UNSPECIFIED;

bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);

if (rp->status)
Expand Down

0 comments on commit a1986c4

Please sign in to comment.