@@ -111,6 +111,23 @@ void iommu_device_unregister(struct iommu_device *iommu)
111111 spin_unlock (& iommu_device_lock );
112112}
113113
114+ int iommu_probe_device (struct device * dev )
115+ {
116+ const struct iommu_ops * ops = dev -> bus -> iommu_ops ;
117+
118+ WARN_ON (dev -> iommu_group );
119+
120+ return ops -> add_device (dev );
121+ }
122+
123+ void iommu_release_device (struct device * dev )
124+ {
125+ const struct iommu_ops * ops = dev -> bus -> iommu_ops ;
126+
127+ if (dev -> iommu_group )
128+ ops -> remove_device (dev );
129+ }
130+
114131static struct iommu_domain * __iommu_domain_alloc (struct bus_type * bus ,
115132 unsigned type );
116133static int __iommu_attach_device (struct iommu_domain * domain ,
@@ -1118,16 +1135,7 @@ struct iommu_domain *iommu_group_default_domain(struct iommu_group *group)
11181135
11191136static int add_iommu_group (struct device * dev , void * data )
11201137{
1121- struct iommu_callback_data * cb = data ;
1122- const struct iommu_ops * ops = cb -> ops ;
1123- int ret ;
1124-
1125- if (!ops -> add_device )
1126- return 0 ;
1127-
1128- WARN_ON (dev -> iommu_group );
1129-
1130- ret = ops -> add_device (dev );
1138+ int ret = iommu_probe_device (dev );
11311139
11321140 /*
11331141 * We ignore -ENODEV errors for now, as they just mean that the
@@ -1142,39 +1150,30 @@ static int add_iommu_group(struct device *dev, void *data)
11421150
11431151static int remove_iommu_group (struct device * dev , void * data )
11441152{
1145- struct iommu_callback_data * cb = data ;
1146- const struct iommu_ops * ops = cb -> ops ;
1147-
1148- if (ops -> remove_device && dev -> iommu_group )
1149- ops -> remove_device (dev );
1153+ iommu_release_device (dev );
11501154
11511155 return 0 ;
11521156}
11531157
11541158static int iommu_bus_notifier (struct notifier_block * nb ,
11551159 unsigned long action , void * data )
11561160{
1161+ unsigned long group_action = 0 ;
11571162 struct device * dev = data ;
1158- const struct iommu_ops * ops = dev -> bus -> iommu_ops ;
11591163 struct iommu_group * group ;
1160- unsigned long group_action = 0 ;
11611164
11621165 /*
11631166 * ADD/DEL call into iommu driver ops if provided, which may
11641167 * result in ADD/DEL notifiers to group->notifier
11651168 */
11661169 if (action == BUS_NOTIFY_ADD_DEVICE ) {
1167- if (ops -> add_device ) {
1168- int ret ;
1170+ int ret ;
11691171
1170- ret = ops -> add_device (dev );
1171- return (ret ) ? NOTIFY_DONE : NOTIFY_OK ;
1172- }
1172+ ret = iommu_probe_device (dev );
1173+ return (ret ) ? NOTIFY_DONE : NOTIFY_OK ;
11731174 } else if (action == BUS_NOTIFY_REMOVED_DEVICE ) {
1174- if (ops -> remove_device && dev -> iommu_group ) {
1175- ops -> remove_device (dev );
1176- return 0 ;
1177- }
1175+ iommu_release_device (dev );
1176+ return NOTIFY_OK ;
11781177 }
11791178
11801179 /*
0 commit comments