rpmsg: use hil_free_vqs to delete virtqueues
[processor-sdk/open-amp.git] / lib / rpmsg / remote_device.c
index 1d038cbdebcd1572a044f470a16ef04937b37dd5..e9d690c3b38305bd149e42f59e53cb1bf56c7ca7 100644 (file)
@@ -214,20 +214,21 @@ void rpmsg_rdev_deinit(struct remote_device *rdev)
                _destroy_endpoint(rdev, rp_ept);
        }
 
-       if (rdev->rvq) {
-               virtqueue_free(rdev->rvq);
-       }
-       if (rdev->tvq) {
-               virtqueue_free(rdev->tvq);
-       }
+       metal_mutex_acquire(&rdev->lock);
+       rdev->rvq = 0;
+       rdev->tvq = 0;
        if (rdev->mem_pool) {
                sh_mem_delete_pool(rdev->mem_pool);
+               rdev->mem_pool = 0;
        }
-       metal_mutex_deinit(&rdev->lock);
+       metal_mutex_release(&rdev->lock);
+       hil_free_vqs(&rdev->virt_dev);
+
        if (rdev->proc) {
                hil_delete_proc(rdev->proc);
                rdev->proc = 0;
        }
+       metal_mutex_deinit(&rdev->lock);
 
        metal_free_memory(rdev);
 }