nfc: check if virtqueue is ready 70/13370/1
authormunkyu.im <munkyu.im@samsung.com>
Wed, 4 Dec 2013 08:25:03 +0000 (17:25 +0900)
committermunkyu.im <munkyu.im@samsung.com>
Wed, 4 Dec 2013 08:25:03 +0000 (17:25 +0900)
Before sending event,
virtio device needs to check if virtqueue is ready.
Otherwise when emulator reset,
device operation may have problem to send message.

Change-Id: Ia715e314d0c1f65098eb7f1c612dc79c039bcdbe
Signed-off-by: munkyu.im <munkyu.im@samsung.com>
tizen/src/hw/maru_virtio_nfc.c

index 332dd4d..3dc2120 100644 (file)
@@ -77,9 +77,15 @@ static pthread_mutex_t recv_buf_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 bool send_to_nfc(unsigned char id, unsigned char type, const char* data, const uint32_t len)
 {
+    if (unlikely(!virtio_queue_ready(vio_nfc->rvq))) {
+        ERR("virtio queue is not ready\n");
+        return false;
+    }
+
     MsgInfo* _msg = (MsgInfo*) malloc(sizeof(MsgInfo));
-    if (!_msg)
+    if (!_msg) {
         return false;
+    }
 
     memset(&_msg->info, 0, sizeof(nfc_msg_info));
 
@@ -119,8 +125,9 @@ static void flush_nfc_recv_queue(void)
     while (!QTAILQ_EMPTY(&nfc_recv_msg_queue))
     {
         MsgInfo* msginfo = QTAILQ_FIRST(&nfc_recv_msg_queue);
-        if (!msginfo)
+        if (!msginfo) {
             break;
+        }
 
         VirtQueueElement elem;
         index = virtqueue_pop(vio_nfc->rvq, &elem);