On Mon, Mar 27, 2023 at 02:34:58AM -0700, Yi Liu wrote: > + devices = kcalloc(count, sizeof(*devices), GFP_KERNEL); > + if (!devices) { > + ret = -ENOMEM; > + goto reset_info_exit; > + } This doesn't need to be so complicated > + list_for_each_entry(cur, &vdev->vdev.dev_set->device_list, vdev.dev_set_list) { > + cur_iommufd = vfio_iommufd_physical_ictx(&cur->vdev); > + if (cur->vdev.open_count) { > + if (cur_iommufd != iommufd) { > + ret = -EPERM; > + break; > + } > + ret = vfio_iommufd_physical_devid(&cur->vdev, &devices[index]); u32 device; if (index >= hdr.count) return -ENOSPC; ret = vfio_iommufd_physical_devid(&cur->vdev, &devices); ... if (put_user(&arg->devices[index], device)) -EFAULT index++; Jason