On Mon, Feb 27, 2023 at 03:11:31AM -0800, Yi Liu wrote:
> @@ -309,6 +310,13 @@ void vfio_unregister_group_dev(struct vfio_device 
> *device)
>       bool interrupted = false;
>       long rc;
>  
> +     /*
> +      * Balances vfio_device_add in register path. Putting it as the
> +      * first operation in unregister to prevent registration refcount
> +      * from incrementing per cdev open.
> +      */
> +     vfio_device_del(device);
> +
>       vfio_device_put_registration(device);
>       rc = try_wait_for_completion(&device->comp);
>       while (rc <= 0) {
> @@ -334,9 +342,6 @@ void vfio_unregister_group_dev(struct vfio_device *device)
>  
>       vfio_device_group_unregister(device);
>  
> -     /* Balances device_add in register path */
> -     device_del(&device->device);
> -
>       /* Balances vfio_device_set_group in register path */
>       vfio_device_remove_group(device);

The same rational applies to vfio_device_group_unregister too, so it
should be moved up as well.

Jason

Reply via email to