From: Rolf Eike Beer <eb@xxxxxxxxx> commit 0ee74d5a48635c848c20f152d0d488bf84641304 upstream. iommu_device_sysfs_add() is called before, so is has to be cleaned on subsequent errors. Fixes: 39ab9555c2411 ("iommu: Add sysfs bindings for struct iommu_device") Cc: stable@xxxxxxxxxxxxxxx # 4.11.x Signed-off-by: Rolf Eike Beer <eb@xxxxxxxxx> Acked-by: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx> Link: https://lore.kernel.org/r/17411490.HIIP88n32C@xxxxxxxxxxxxxxxxxxxxxx Link: https://lore.kernel.org/r/20210525070802.361755-2-baolu.lu@xxxxxxxxxxxxxxx Signed-off-by: Joerg Roedel <jroedel@xxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/iommu/intel/dmar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -1144,7 +1144,7 @@ static int alloc_iommu(struct dmar_drhd_ err = iommu_device_register(&iommu->iommu); if (err) - goto err_unmap; + goto err_sysfs; } drhd->iommu = iommu; @@ -1152,6 +1152,8 @@ static int alloc_iommu(struct dmar_drhd_ return 0; +err_sysfs: + iommu_device_sysfs_remove(&iommu->iommu); err_unmap: unmap_iommu(iommu); error_free_seq_id: