Skip to content

Commit 5aa95d8

Browse files
frank-wjoergroedel
authored andcommitted
iommu: Check if group is NULL before remove device
If probe_device is failing, iommu_group is not initialized because iommu_group_add_device is not reached, so freeing it will result in NULL pointer access. iommu_bus_init ->bus_iommu_probe ->probe_iommu_group in for each:/* return -22 in fail case */ ->iommu_probe_device ->__iommu_probe_device /* return -22 here.*/ -> ops->probe_device /* return -22 here.*/ -> iommu_group_get_for_dev -> ops->device_group -> iommu_group_add_device //good case ->remove_iommu_group //in fail case, it will remove group ->iommu_release_device ->iommu_group_remove_device // here we don't have group In my case ops->probe_device (mtk_iommu_probe_device from mtk_iommu_v1.c) is due to failing fwspec->ops mismatch. Fixes: d72e31c ("iommu: IOMMU Groups") Signed-off-by: Frank Wunderlich <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 0fbea68 commit 5aa95d8

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/iommu/iommu.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,9 @@ void iommu_group_remove_device(struct device *dev)
924924
struct iommu_group *group = dev->iommu_group;
925925
struct group_device *tmp_device, *device = NULL;
926926

927+
if (!group)
928+
return;
929+
927930
dev_info(dev, "Removing from iommu group %d\n", group->id);
928931

929932
/* Pre-notify listeners that a device is being removed. */

0 commit comments

Comments
 (0)