@@ -126,12 +126,24 @@ struct mock_iommu_domain {
126
126
struct xarray pfns ;
127
127
};
128
128
129
+ static inline struct mock_iommu_domain *
130
+ to_mock_domain (struct iommu_domain * domain )
131
+ {
132
+ return container_of (domain , struct mock_iommu_domain , domain );
133
+ }
134
+
129
135
struct mock_iommu_domain_nested {
130
136
struct iommu_domain domain ;
131
137
struct mock_iommu_domain * parent ;
132
138
u32 iotlb [MOCK_NESTED_DOMAIN_IOTLB_NUM ];
133
139
};
134
140
141
+ static inline struct mock_iommu_domain_nested *
142
+ to_mock_nested (struct iommu_domain * domain )
143
+ {
144
+ return container_of (domain , struct mock_iommu_domain_nested , domain );
145
+ }
146
+
135
147
enum selftest_obj_type {
136
148
TYPE_IDEV ,
137
149
};
@@ -142,6 +154,11 @@ struct mock_dev {
142
154
int id ;
143
155
};
144
156
157
+ static inline struct mock_dev * to_mock_dev (struct device * dev )
158
+ {
159
+ return container_of (dev , struct mock_dev , dev );
160
+ }
161
+
145
162
struct selftest_obj {
146
163
struct iommufd_object obj ;
147
164
enum selftest_obj_type type ;
@@ -155,10 +172,15 @@ struct selftest_obj {
155
172
};
156
173
};
157
174
175
+ static inline struct selftest_obj * to_selftest_obj (struct iommufd_object * obj )
176
+ {
177
+ return container_of (obj , struct selftest_obj , obj );
178
+ }
179
+
158
180
static int mock_domain_nop_attach (struct iommu_domain * domain ,
159
181
struct device * dev )
160
182
{
161
- struct mock_dev * mdev = container_of ( dev , struct mock_dev , dev );
183
+ struct mock_dev * mdev = to_mock_dev ( dev );
162
184
163
185
if (domain -> dirty_ops && (mdev -> flags & MOCK_FLAGS_DEVICE_NO_DIRTY ))
164
186
return - EINVAL ;
@@ -193,8 +215,7 @@ static void *mock_domain_hw_info(struct device *dev, u32 *length, u32 *type)
193
215
static int mock_domain_set_dirty_tracking (struct iommu_domain * domain ,
194
216
bool enable )
195
217
{
196
- struct mock_iommu_domain * mock =
197
- container_of (domain , struct mock_iommu_domain , domain );
218
+ struct mock_iommu_domain * mock = to_mock_domain (domain );
198
219
unsigned long flags = mock -> flags ;
199
220
200
221
if (enable && !domain -> dirty_ops )
@@ -243,8 +264,7 @@ static int mock_domain_read_and_clear_dirty(struct iommu_domain *domain,
243
264
unsigned long flags ,
244
265
struct iommu_dirty_bitmap * dirty )
245
266
{
246
- struct mock_iommu_domain * mock =
247
- container_of (domain , struct mock_iommu_domain , domain );
267
+ struct mock_iommu_domain * mock = to_mock_domain (domain );
248
268
unsigned long end = iova + size ;
249
269
void * ent ;
250
270
@@ -281,7 +301,7 @@ static const struct iommu_dirty_ops dirty_ops = {
281
301
282
302
static struct iommu_domain * mock_domain_alloc_paging (struct device * dev )
283
303
{
284
- struct mock_dev * mdev = container_of ( dev , struct mock_dev , dev );
304
+ struct mock_dev * mdev = to_mock_dev ( dev );
285
305
struct mock_iommu_domain * mock ;
286
306
287
307
mock = kzalloc (sizeof (* mock ), GFP_KERNEL );
@@ -327,7 +347,7 @@ mock_domain_alloc_user(struct device *dev, u32 flags,
327
347
328
348
/* must be mock_domain */
329
349
if (!parent ) {
330
- struct mock_dev * mdev = container_of ( dev , struct mock_dev , dev );
350
+ struct mock_dev * mdev = to_mock_dev ( dev );
331
351
bool has_dirty_flag = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING ;
332
352
bool no_dirty_ops = mdev -> flags & MOCK_FLAGS_DEVICE_NO_DIRTY ;
333
353
struct iommu_domain * domain ;
@@ -341,8 +361,7 @@ mock_domain_alloc_user(struct device *dev, u32 flags,
341
361
if (!domain )
342
362
return ERR_PTR (- ENOMEM );
343
363
if (has_dirty_flag )
344
- container_of (domain , struct mock_iommu_domain , domain )
345
- -> domain .dirty_ops = & dirty_ops ;
364
+ domain -> dirty_ops = & dirty_ops ;
346
365
return domain ;
347
366
}
348
367
@@ -352,7 +371,7 @@ mock_domain_alloc_user(struct device *dev, u32 flags,
352
371
if (!parent || parent -> ops != mock_ops .default_domain_ops )
353
372
return ERR_PTR (- EINVAL );
354
373
355
- mock_parent = container_of (parent , struct mock_iommu_domain , domain );
374
+ mock_parent = to_mock_domain (parent );
356
375
if (!mock_parent )
357
376
return ERR_PTR (- EINVAL );
358
377
@@ -366,8 +385,7 @@ mock_domain_alloc_user(struct device *dev, u32 flags,
366
385
367
386
static void mock_domain_free (struct iommu_domain * domain )
368
387
{
369
- struct mock_iommu_domain * mock =
370
- container_of (domain , struct mock_iommu_domain , domain );
388
+ struct mock_iommu_domain * mock = to_mock_domain (domain );
371
389
372
390
WARN_ON (!xa_empty (& mock -> pfns ));
373
391
kfree (mock );
@@ -378,8 +396,7 @@ static int mock_domain_map_pages(struct iommu_domain *domain,
378
396
size_t pgsize , size_t pgcount , int prot ,
379
397
gfp_t gfp , size_t * mapped )
380
398
{
381
- struct mock_iommu_domain * mock =
382
- container_of (domain , struct mock_iommu_domain , domain );
399
+ struct mock_iommu_domain * mock = to_mock_domain (domain );
383
400
unsigned long flags = MOCK_PFN_START_IOVA ;
384
401
unsigned long start_iova = iova ;
385
402
@@ -430,8 +447,7 @@ static size_t mock_domain_unmap_pages(struct iommu_domain *domain,
430
447
size_t pgcount ,
431
448
struct iommu_iotlb_gather * iotlb_gather )
432
449
{
433
- struct mock_iommu_domain * mock =
434
- container_of (domain , struct mock_iommu_domain , domain );
450
+ struct mock_iommu_domain * mock = to_mock_domain (domain );
435
451
bool first = true;
436
452
size_t ret = 0 ;
437
453
void * ent ;
@@ -479,8 +495,7 @@ static size_t mock_domain_unmap_pages(struct iommu_domain *domain,
479
495
static phys_addr_t mock_domain_iova_to_phys (struct iommu_domain * domain ,
480
496
dma_addr_t iova )
481
497
{
482
- struct mock_iommu_domain * mock =
483
- container_of (domain , struct mock_iommu_domain , domain );
498
+ struct mock_iommu_domain * mock = to_mock_domain (domain );
484
499
void * ent ;
485
500
486
501
WARN_ON (iova % MOCK_IO_PAGE_SIZE );
@@ -491,7 +506,7 @@ static phys_addr_t mock_domain_iova_to_phys(struct iommu_domain *domain,
491
506
492
507
static bool mock_domain_capable (struct device * dev , enum iommu_cap cap )
493
508
{
494
- struct mock_dev * mdev = container_of ( dev , struct mock_dev , dev );
509
+ struct mock_dev * mdev = to_mock_dev ( dev );
495
510
496
511
switch (cap ) {
497
512
case IOMMU_CAP_CACHE_COHERENCY :
@@ -571,18 +586,14 @@ static const struct iommu_ops mock_ops = {
571
586
572
587
static void mock_domain_free_nested (struct iommu_domain * domain )
573
588
{
574
- struct mock_iommu_domain_nested * mock_nested =
575
- container_of (domain , struct mock_iommu_domain_nested , domain );
576
-
577
- kfree (mock_nested );
589
+ kfree (to_mock_nested (domain ));
578
590
}
579
591
580
592
static int
581
593
mock_domain_cache_invalidate_user (struct iommu_domain * domain ,
582
594
struct iommu_user_data_array * array )
583
595
{
584
- struct mock_iommu_domain_nested * mock_nested =
585
- container_of (domain , struct mock_iommu_domain_nested , domain );
596
+ struct mock_iommu_domain_nested * mock_nested = to_mock_nested (domain );
586
597
struct iommu_hwpt_invalidate_selftest inv ;
587
598
u32 processed = 0 ;
588
599
int i = 0 , j ;
@@ -657,7 +668,7 @@ get_md_pagetable(struct iommufd_ucmd *ucmd, u32 mockpt_id,
657
668
iommufd_put_object (ucmd -> ictx , & hwpt -> obj );
658
669
return ERR_PTR (- EINVAL );
659
670
}
660
- * mock = container_of (hwpt -> domain , struct mock_iommu_domain , domain );
671
+ * mock = to_mock_domain (hwpt -> domain );
661
672
return hwpt ;
662
673
}
663
674
@@ -675,14 +686,13 @@ get_md_pagetable_nested(struct iommufd_ucmd *ucmd, u32 mockpt_id,
675
686
iommufd_put_object (ucmd -> ictx , & hwpt -> obj );
676
687
return ERR_PTR (- EINVAL );
677
688
}
678
- * mock_nested = container_of (hwpt -> domain ,
679
- struct mock_iommu_domain_nested , domain );
689
+ * mock_nested = to_mock_nested (hwpt -> domain );
680
690
return hwpt ;
681
691
}
682
692
683
693
static void mock_dev_release (struct device * dev )
684
694
{
685
- struct mock_dev * mdev = container_of ( dev , struct mock_dev , dev );
695
+ struct mock_dev * mdev = to_mock_dev ( dev );
686
696
687
697
ida_free (& mock_dev_ida , mdev -> id );
688
698
kfree (mdev );
@@ -813,7 +823,7 @@ static int iommufd_test_mock_domain_replace(struct iommufd_ucmd *ucmd,
813
823
if (IS_ERR (dev_obj ))
814
824
return PTR_ERR (dev_obj );
815
825
816
- sobj = container_of (dev_obj , struct selftest_obj , obj );
826
+ sobj = to_selftest_obj (dev_obj );
817
827
if (sobj -> type != TYPE_IDEV ) {
818
828
rc = - EINVAL ;
819
829
goto out_dev_obj ;
@@ -951,8 +961,7 @@ static int iommufd_test_md_check_iotlb(struct iommufd_ucmd *ucmd,
951
961
if (IS_ERR (hwpt ))
952
962
return PTR_ERR (hwpt );
953
963
954
- mock_nested = container_of (hwpt -> domain ,
955
- struct mock_iommu_domain_nested , domain );
964
+ mock_nested = to_mock_nested (hwpt -> domain );
956
965
957
966
if (iotlb_id > MOCK_NESTED_DOMAIN_IOTLB_ID_MAX ||
958
967
mock_nested -> iotlb [iotlb_id ] != iotlb )
@@ -1431,7 +1440,7 @@ static int iommufd_test_trigger_iopf(struct iommufd_ucmd *ucmd,
1431
1440
1432
1441
void iommufd_selftest_destroy (struct iommufd_object * obj )
1433
1442
{
1434
- struct selftest_obj * sobj = container_of ( obj , struct selftest_obj , obj );
1443
+ struct selftest_obj * sobj = to_selftest_obj ( obj );
1435
1444
1436
1445
switch (sobj -> type ) {
1437
1446
case TYPE_IDEV :
0 commit comments