> From: Anthony DeRossi <ajderossi@xxxxxxxxx> > Sent: Sunday, November 6, 2022 6:45 AM > > In vfio_device_open(), vfio_container_device_register() is always called vfio_device_container_register() > when open_count == 1. On error, vfio_device_container_unregister() is > only called when open_count == 1 and close_device is set. This leaks a > registration for devices without a close_device implementation. > > In vfio_device_fops_release(), vfio_device_container_unregister() is > called unconditionally. This can cause a device to be unregistered > multiple times. > > Treating container device registration/unregistration uniformly (always > when open_count == 1) fixes both issues. > > Fixes: ce4b4657ff18 ("vfio: Replace the DMA unmapping notifier with a > callback") > Signed-off-by: Anthony DeRossi <ajderossi@xxxxxxxxx> Reviewed-by: Kevin Tian <kevin.tian@xxxxxxxxx>