monitor: fix division by zero about conn->tx_pkt_med
authorJoseph Hwang <josephsih@chromium.org>
Wed, 16 Feb 2022 08:15:18 +0000 (16:15 +0800)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:53 +0000 (14:55 +0530)
In a connection without outgoing traffic, conn->tx_num will remain 0.
In this case, conn->tx_pkt_med should be simply 0 without calculating
"conn->tx_bytes / conn->tx_num".

This was likely to happen, for example, when "btmon -w btsnoop.log"
was launched in the middle of a LE mouse connection, and a number of
incoming ACL Data RX were received as the mouse movements.  When
running "btmon -a btsnoop.log", it would encounter this error.

Reviewed-by: Alain Michaud <alainm@chromium.org>
Reviewed-by: Yun-Hao Chung <howardchung@chromium.org>
Reviewed-by: Shuo-Peng Liao <deanliao@chromium.org>
Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
monitor/analyze.c

index 1610e4f..135dc91 100755 (executable)
@@ -163,7 +163,8 @@ static void conn_destroy(void *data)
                break;
        }
 
-       conn->tx_pkt_med = conn->tx_bytes / conn->tx_num;
+       if (conn->tx_num > 0)
+               conn->tx_pkt_med = conn->tx_bytes / conn->tx_num;
 
        printf("  Found %s connection with handle %u\n", str, conn->handle);
        /* TODO: Store address type */