[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20231122221805.3139482-1-arnd@kernel.org>
Date: Wed, 22 Nov 2023 23:17:44 +0100
From: Arnd Bergmann <arnd@...nel.org>
To: Marcel Holtmann <marcel@...tmann.org>,
Johan Hedberg <johan.hedberg@...il.com>,
Luiz Augusto von Dentz <luiz.dentz@...il.com>,
"Gustavo A. R. Silva" <gustavoars@...nel.org>
Cc: Arnd Bergmann <arnd@...db.de>,
Iulia Tanasescu <iulia.tanasescu@....com>,
Pauli Virtanen <pav@....fi>, Jakub Kicinski <kuba@...nel.org>,
"Lee, Chun-Yi" <jlee@...e.com>,
Claudia Draghicescu <claudia.rosu@....com>,
Ziyang Xuan <william.xuanziyang@...wei.com>,
linux-bluetooth@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] Bluetooth: hci_event: shut up a false-positive warning
From: Arnd Bergmann <arnd@...db.de>
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: a9de9248064b ("[Bluetooth] Switch from OGF+OCF to using only opcodes")
Fixes: 1b56c90018f0 ("Makefile: Enable -Wstringop-overflow globally")
Signed-off-by: Arnd Bergmann <arnd@...db.de>
---
net/bluetooth/hci_event.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 5b6fd625fc09..5651e96e78da 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -516,6 +516,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 -ENXIO;
+
bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
if (rp->status)
--
2.39.2
Powered by blists - more mailing lists