linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] bluetooth: fix uninitialized variables notify_evt
@ 2021-11-16  1:17 Jackie Liu
  2021-11-16 13:57 ` Marcel Holtmann
  0 siblings, 1 reply; 2+ messages in thread
From: Jackie Liu @ 2021-11-16  1:17 UTC (permalink / raw)
  To: marcel
  Cc: chethan.tumkur.narayan, luiz.von.dentz, linux-bluetooth, davem, liu.yun

From: Jackie Liu <liuyun01@kylinos.cn>

Coverity Scan report:

[...]
*** CID 1493985:  Uninitialized variables  (UNINIT)
/net/bluetooth/hci_event.c: 4535 in hci_sync_conn_complete_evt()
4529
4530     	/* Notify only in case of SCO over HCI transport data path which
4531     	 * is zero and non-zero value shall be non-HCI transport data path
4532     	 */
4533     	if (conn->codec.data_path == 0) {
4534     		if (hdev->notify)
>>>     CID 1493985:  Uninitialized variables  (UNINIT)
>>>     Using uninitialized value "notify_evt" when calling "*hdev->notify".
4535     			hdev->notify(hdev, notify_evt);
4536     	}
4537
4538     	hci_connect_cfm(conn, ev->status);
4539     	if (ev->status)
4540     		hci_conn_del(conn);
[...]

Although only btusb uses air_mode, and he only handles HCI_NOTIFY_ENABLE_SCO_CVSD
and HCI_NOTIFY_ENABLE_SCO_TRANSP, there is still a very small chance that
ev->air_mode is not equal to 0x2 and 0x3, but notify_evt is initialized to
HCI_NOTIFY_ENABLE_SCO_CVSD or HCI_NOTIFY_ENABLE_SCO_TRANSP. the context is
maybe not correct.

Let us directly use the required function instead of re-initializing it,
so as to restore the original logic and make the code more correct.

Addresses-Coverity: ("Uninitialized variables")
Fixes: f4f9fa0c07bb ("Bluetooth: Allow usb to auto-suspend when SCO use	non-HCI transport")
Suggested-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 net/bluetooth/hci_event.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 7d0db1ca1248..f52394e3d08e 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -4445,7 +4445,6 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev,
 {
 	struct hci_ev_sync_conn_complete *ev = (void *) skb->data;
 	struct hci_conn *conn;
-	unsigned int notify_evt;
 
 	BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
 
@@ -4517,22 +4516,18 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev,
 	}
 
 	bt_dev_dbg(hdev, "SCO connected with air mode: %02x", ev->air_mode);
-
-	switch (ev->air_mode) {
-	case 0x02:
-		notify_evt = HCI_NOTIFY_ENABLE_SCO_CVSD;
-		break;
-	case 0x03:
-		notify_evt = HCI_NOTIFY_ENABLE_SCO_TRANSP;
-		break;
-	}
-
 	/* Notify only in case of SCO over HCI transport data path which
 	 * is zero and non-zero value shall be non-HCI transport data path
 	 */
-	if (conn->codec.data_path == 0) {
-		if (hdev->notify)
-			hdev->notify(hdev, notify_evt);
+	if (conn->codec.data_path == 0 && hdev->notify) {
+		switch (ev->air_mode) {
+		case 0x02:
+			hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_CVSD);
+			break;
+		case 0x03:
+			hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_TRANSP);
+			break;
+		}
 	}
 
 	hci_connect_cfm(conn, ev->status);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] bluetooth: fix uninitialized variables notify_evt
  2021-11-16  1:17 [PATCH v2] bluetooth: fix uninitialized variables notify_evt Jackie Liu
@ 2021-11-16 13:57 ` Marcel Holtmann
  0 siblings, 0 replies; 2+ messages in thread
From: Marcel Holtmann @ 2021-11-16 13:57 UTC (permalink / raw)
  To: Jackie Liu
  Cc: chethan.tumkur.narayan, Luiz Augusto von Dentz, linux-bluetooth,
	David S. Miller

Hi Jackie,

> Coverity Scan report:
> 
> [...]
> *** CID 1493985:  Uninitialized variables  (UNINIT)
> /net/bluetooth/hci_event.c: 4535 in hci_sync_conn_complete_evt()
> 4529
> 4530     	/* Notify only in case of SCO over HCI transport data path which
> 4531     	 * is zero and non-zero value shall be non-HCI transport data path
> 4532     	 */
> 4533     	if (conn->codec.data_path == 0) {
> 4534     		if (hdev->notify)
>>>>    CID 1493985:  Uninitialized variables  (UNINIT)
>>>>    Using uninitialized value "notify_evt" when calling "*hdev->notify".
> 4535     			hdev->notify(hdev, notify_evt);
> 4536     	}
> 4537
> 4538     	hci_connect_cfm(conn, ev->status);
> 4539     	if (ev->status)
> 4540     		hci_conn_del(conn);
> [...]
> 
> Although only btusb uses air_mode, and he only handles HCI_NOTIFY_ENABLE_SCO_CVSD
> and HCI_NOTIFY_ENABLE_SCO_TRANSP, there is still a very small chance that
> ev->air_mode is not equal to 0x2 and 0x3, but notify_evt is initialized to
> HCI_NOTIFY_ENABLE_SCO_CVSD or HCI_NOTIFY_ENABLE_SCO_TRANSP. the context is
> maybe not correct.
> 
> Let us directly use the required function instead of re-initializing it,
> so as to restore the original logic and make the code more correct.
> 
> Addresses-Coverity: ("Uninitialized variables")
> Fixes: f4f9fa0c07bb ("Bluetooth: Allow usb to auto-suspend when SCO use	non-HCI transport")
> Suggested-by: Marcel Holtmann <marcel@holtmann.org>
> Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
> ---
> net/bluetooth/hci_event.c | 23 +++++++++--------------
> 1 file changed, 9 insertions(+), 14 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-16 13:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-16  1:17 [PATCH v2] bluetooth: fix uninitialized variables notify_evt Jackie Liu
2021-11-16 13:57 ` Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).