Usually we wait for the host to complete the unref request, then cleanup
the guest-side state of the object in the completion callback.  When
submitting the unref command failed the completion callback will not be
called though, so cleanup right away.
Fixes a WARN on stale mm entries on driver shutdown.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20200908070723.6394-4-kraxel@redhat.com
 {
        struct virtio_gpu_resource_unref *cmd_p;
        struct virtio_gpu_vbuffer *vbuf;
+       int ret;
 
        cmd_p = virtio_gpu_alloc_cmd_cb(vgdev, &vbuf, sizeof(*cmd_p),
                                        virtio_gpu_cmd_unref_cb);
        cmd_p->resource_id = cpu_to_le32(bo->hw_res_handle);
 
        vbuf->resp_cb_data = bo;
-       virtio_gpu_queue_ctrl_buffer(vgdev, vbuf);
+       ret = virtio_gpu_queue_ctrl_buffer(vgdev, vbuf);
+       if (ret < 0)
+               virtio_gpu_cleanup_object(bo);
 }
 
 void virtio_gpu_cmd_set_scanout(struct virtio_gpu_device *vgdev,