From: Wan Jiabing Date: Tue, 17 May 2022 02:34:41 +0000 (+0800) Subject: kvm/vfio: Fix potential deadlock problem in vfio X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=6b17ca8e5e7a7b10689867dff5e22d7da368ba76;p=linux.git kvm/vfio: Fix potential deadlock problem in vfio Fix following coccicheck warning: ./virt/kvm/vfio.c:258:1-7: preceding lock on line 236 If kvm_vfio_file_iommu_group() failed, code would goto err_fdput with mutex_lock acquired and then return ret. It might cause potential deadlock. Move mutex_unlock bellow err_fdput tag to fix it. Fixes: d55d9e7a45721 ("kvm/vfio: Store the struct file in the kvm_vfio_group") Signed-off-by: Wan Jiabing Reviewed-by: Jason Gunthorpe Link: https://lore.kernel.org/r/20220517023441.4258-1-wanjiabing@vivo.com Signed-off-by: Alex Williamson --- diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c index 8f9f7fffb96a1..ce1b01d02c519 100644 --- a/virt/kvm/vfio.c +++ b/virt/kvm/vfio.c @@ -252,8 +252,8 @@ static int kvm_vfio_group_set_spapr_tce(struct kvm_device *dev, break; } - mutex_unlock(&kv->lock); err_fdput: + mutex_unlock(&kv->lock); fdput(f); return ret; }