OSDN Git Service

Check userial fd before reading
authorChris Manton <cmanton@google.com>
Mon, 15 Sep 2014 15:48:35 +0000 (08:48 -0700)
committerChris Manton <cmanton@google.com>
Thu, 18 Sep 2014 16:30:47 +0000 (09:30 -0700)
The userial read loop uses one global flag
to condition the serial port read and a
second global file descriptor variable that
may change from another thread underneath it.

Check the validity of the serial port file
descriptor by making a copy immediately before
the read and only proceeding if it's a valid fd.

bug: 17552690

Change-Id: Iaaf1b8476fdee462ddc178d2a31ef8f55cb33e52

hci/src/userial.c

index 34de045..e3f3557 100644 (file)
@@ -219,7 +219,11 @@ static void *userial_read_thread(void *arg)
             p_buf->layer_specific = 0;
 
             p = (uint8_t *) (p_buf + 1);
-            rx_length = select_read(userial_cb.fd, p, HCI_MAX_FRAME_SIZE + 1);
+            int userial_fd = userial_cb.fd;
+            if (userial_fd != -1)
+                rx_length = select_read(userial_fd, p, HCI_MAX_FRAME_SIZE + 1);
+            else
+                rx_length = 0;
         }
         else
         {