rcu_assign_pointer(the_virtio_vsock, NULL);
        synchronize_rcu();
 
-       flush_work(&vsock->loopback_work);
-       flush_work(&vsock->rx_work);
-       flush_work(&vsock->tx_work);
-       flush_work(&vsock->event_work);
-       flush_work(&vsock->send_pkt_work);
-
        /* Reset all connected sockets when the device disappear */
        vsock_for_each_connected_socket(virtio_vsock_reset_sock);
 
        /* Delete virtqueues and flush outstanding callbacks if any */
        vdev->config->del_vqs(vdev);
 
+       /* Other works can be queued before 'config->del_vqs()', so we flush
+        * all works before to free the vsock object to avoid use after free.
+        */
+       flush_work(&vsock->loopback_work);
+       flush_work(&vsock->rx_work);
+       flush_work(&vsock->tx_work);
+       flush_work(&vsock->event_work);
+       flush_work(&vsock->send_pkt_work);
+
        mutex_unlock(&the_virtio_vsock_mutex);
 
        kfree(vsock);