36
36
#include "uverbs.h"
37
37
38
38
struct bundle_alloc_head {
39
- struct bundle_alloc_head * next ;
39
+ struct_group_tagged (bundle_alloc_head_hdr , hdr ,
40
+ struct bundle_alloc_head * next ;
41
+ );
40
42
u8 data [];
41
43
};
42
44
43
45
struct bundle_priv {
44
46
/* Must be first */
45
- struct bundle_alloc_head alloc_head ;
47
+ struct bundle_alloc_head_hdr alloc_head ;
46
48
struct bundle_alloc_head * allocated_mem ;
47
49
size_t internal_avail ;
48
50
size_t internal_used ;
@@ -64,7 +66,7 @@ struct bundle_priv {
64
66
* Must be last. bundle ends in a flex array which overlaps
65
67
* internal_buffer.
66
68
*/
67
- struct uverbs_attr_bundle bundle ;
69
+ struct uverbs_attr_bundle_hdr bundle ;
68
70
u64 internal_buffer [32 ];
69
71
};
70
72
@@ -77,9 +79,10 @@ void uapi_compute_bundle_size(struct uverbs_api_ioctl_method *method_elm,
77
79
unsigned int num_attrs )
78
80
{
79
81
struct bundle_priv * pbundle ;
82
+ struct uverbs_attr_bundle * bundle ;
80
83
size_t bundle_size =
81
84
offsetof(struct bundle_priv , internal_buffer ) +
82
- sizeof (* pbundle -> bundle . attrs ) * method_elm -> key_bitmap_len +
85
+ sizeof (* bundle -> attrs ) * method_elm -> key_bitmap_len +
83
86
sizeof (* pbundle -> uattrs ) * num_attrs ;
84
87
85
88
method_elm -> use_stack = bundle_size <= sizeof (* pbundle );
@@ -107,7 +110,7 @@ __malloc void *_uverbs_alloc(struct uverbs_attr_bundle *bundle, size_t size,
107
110
gfp_t flags )
108
111
{
109
112
struct bundle_priv * pbundle =
110
- container_of (bundle , struct bundle_priv , bundle );
113
+ container_of (& bundle -> hdr , struct bundle_priv , bundle );
111
114
size_t new_used ;
112
115
void * res ;
113
116
@@ -149,7 +152,7 @@ static int uverbs_set_output(const struct uverbs_attr_bundle *bundle,
149
152
const struct uverbs_attr * attr )
150
153
{
151
154
struct bundle_priv * pbundle =
152
- container_of (bundle , struct bundle_priv , bundle );
155
+ container_of (& bundle -> hdr , struct bundle_priv , bundle );
153
156
u16 flags ;
154
157
155
158
flags = pbundle -> uattrs [attr -> ptr_attr .uattr_idx ].flags |
@@ -166,6 +169,8 @@ static int uverbs_process_idrs_array(struct bundle_priv *pbundle,
166
169
struct ib_uverbs_attr * uattr ,
167
170
u32 attr_bkey )
168
171
{
172
+ struct uverbs_attr_bundle * bundle =
173
+ container_of (& pbundle -> bundle , struct uverbs_attr_bundle , hdr );
169
174
const struct uverbs_attr_spec * spec = & attr_uapi -> spec ;
170
175
size_t array_len ;
171
176
u32 * idr_vals ;
@@ -184,7 +189,7 @@ static int uverbs_process_idrs_array(struct bundle_priv *pbundle,
184
189
return - EINVAL ;
185
190
186
191
attr -> uobjects =
187
- uverbs_alloc (& pbundle -> bundle ,
192
+ uverbs_alloc (bundle ,
188
193
array_size (array_len , sizeof (* attr -> uobjects )));
189
194
if (IS_ERR (attr -> uobjects ))
190
195
return PTR_ERR (attr -> uobjects );
@@ -209,7 +214,7 @@ static int uverbs_process_idrs_array(struct bundle_priv *pbundle,
209
214
for (i = 0 ; i != array_len ; i ++ ) {
210
215
attr -> uobjects [i ] = uverbs_get_uobject_from_file (
211
216
spec -> u2 .objs_arr .obj_type , spec -> u2 .objs_arr .access ,
212
- idr_vals [i ], & pbundle -> bundle );
217
+ idr_vals [i ], bundle );
213
218
if (IS_ERR (attr -> uobjects [i ])) {
214
219
ret = PTR_ERR (attr -> uobjects [i ]);
215
220
break ;
@@ -240,7 +245,9 @@ static int uverbs_process_attr(struct bundle_priv *pbundle,
240
245
struct ib_uverbs_attr * uattr , u32 attr_bkey )
241
246
{
242
247
const struct uverbs_attr_spec * spec = & attr_uapi -> spec ;
243
- struct uverbs_attr * e = & pbundle -> bundle .attrs [attr_bkey ];
248
+ struct uverbs_attr_bundle * bundle =
249
+ container_of (& pbundle -> bundle , struct uverbs_attr_bundle , hdr );
250
+ struct uverbs_attr * e = & bundle -> attrs [attr_bkey ];
244
251
const struct uverbs_attr_spec * val_spec = spec ;
245
252
struct uverbs_obj_attr * o_attr ;
246
253
@@ -288,7 +295,7 @@ static int uverbs_process_attr(struct bundle_priv *pbundle,
288
295
if (val_spec -> alloc_and_copy && !uverbs_attr_ptr_is_inline (e )) {
289
296
void * p ;
290
297
291
- p = uverbs_alloc (& pbundle -> bundle , uattr -> len );
298
+ p = uverbs_alloc (bundle , uattr -> len );
292
299
if (IS_ERR (p ))
293
300
return PTR_ERR (p );
294
301
@@ -321,7 +328,7 @@ static int uverbs_process_attr(struct bundle_priv *pbundle,
321
328
*/
322
329
o_attr -> uobject = uverbs_get_uobject_from_file (
323
330
spec -> u .obj .obj_type , spec -> u .obj .access ,
324
- uattr -> data_s64 , & pbundle -> bundle );
331
+ uattr -> data_s64 , bundle );
325
332
if (IS_ERR (o_attr -> uobject ))
326
333
return PTR_ERR (o_attr -> uobject );
327
334
__set_bit (attr_bkey , pbundle -> uobj_finalize );
@@ -422,6 +429,8 @@ static int ib_uverbs_run_method(struct bundle_priv *pbundle,
422
429
unsigned int num_attrs )
423
430
{
424
431
int (* handler )(struct uverbs_attr_bundle * attrs );
432
+ struct uverbs_attr_bundle * bundle =
433
+ container_of (& pbundle -> bundle , struct uverbs_attr_bundle , hdr );
425
434
size_t uattrs_size = array_size (sizeof (* pbundle -> uattrs ), num_attrs );
426
435
unsigned int destroy_bkey = pbundle -> method_elm -> destroy_bkey ;
427
436
unsigned int i ;
@@ -434,7 +443,7 @@ static int ib_uverbs_run_method(struct bundle_priv *pbundle,
434
443
if (!handler )
435
444
return - EIO ;
436
445
437
- pbundle -> uattrs = uverbs_alloc (& pbundle -> bundle , uattrs_size );
446
+ pbundle -> uattrs = uverbs_alloc (bundle , uattrs_size );
438
447
if (IS_ERR (pbundle -> uattrs ))
439
448
return PTR_ERR (pbundle -> uattrs );
440
449
if (copy_from_user (pbundle -> uattrs , pbundle -> user_attrs , uattrs_size ))
@@ -453,25 +462,23 @@ static int ib_uverbs_run_method(struct bundle_priv *pbundle,
453
462
return - EINVAL ;
454
463
455
464
if (pbundle -> method_elm -> has_udata )
456
- uverbs_fill_udata (& pbundle -> bundle ,
457
- & pbundle -> bundle .driver_udata ,
465
+ uverbs_fill_udata (bundle , & pbundle -> bundle .driver_udata ,
458
466
UVERBS_ATTR_UHW_IN , UVERBS_ATTR_UHW_OUT );
459
467
else
460
468
pbundle -> bundle .driver_udata = (struct ib_udata ){};
461
469
462
470
if (destroy_bkey != UVERBS_API_ATTR_BKEY_LEN ) {
463
- struct uverbs_obj_attr * destroy_attr =
464
- & pbundle -> bundle .attrs [destroy_bkey ].obj_attr ;
471
+ struct uverbs_obj_attr * destroy_attr = & bundle -> attrs [destroy_bkey ].obj_attr ;
465
472
466
- ret = uobj_destroy (destroy_attr -> uobject , & pbundle -> bundle );
473
+ ret = uobj_destroy (destroy_attr -> uobject , bundle );
467
474
if (ret )
468
475
return ret ;
469
476
__clear_bit (destroy_bkey , pbundle -> uobj_finalize );
470
477
471
- ret = handler (& pbundle -> bundle );
478
+ ret = handler (bundle );
472
479
uobj_put_destroy (destroy_attr -> uobject );
473
480
} else {
474
- ret = handler (& pbundle -> bundle );
481
+ ret = handler (bundle );
475
482
}
476
483
477
484
/*
@@ -481,10 +488,10 @@ static int ib_uverbs_run_method(struct bundle_priv *pbundle,
481
488
*/
482
489
if (!ret && pbundle -> method_elm -> has_udata ) {
483
490
const struct uverbs_attr * attr =
484
- uverbs_attr_get (& pbundle -> bundle , UVERBS_ATTR_UHW_OUT );
491
+ uverbs_attr_get (bundle , UVERBS_ATTR_UHW_OUT );
485
492
486
493
if (!IS_ERR (attr ))
487
- ret = uverbs_set_output (& pbundle -> bundle , attr );
494
+ ret = uverbs_set_output (bundle , attr );
488
495
}
489
496
490
497
/*
@@ -501,27 +508,28 @@ static int ib_uverbs_run_method(struct bundle_priv *pbundle,
501
508
static void bundle_destroy (struct bundle_priv * pbundle , bool commit )
502
509
{
503
510
unsigned int key_bitmap_len = pbundle -> method_elm -> key_bitmap_len ;
511
+ struct uverbs_attr_bundle * bundle =
512
+ container_of (& pbundle -> bundle , struct uverbs_attr_bundle , hdr );
504
513
struct bundle_alloc_head * memblock ;
505
514
unsigned int i ;
506
515
507
516
/* fast path for simple uobjects */
508
517
i = -1 ;
509
518
while ((i = find_next_bit (pbundle -> uobj_finalize , key_bitmap_len ,
510
519
i + 1 )) < key_bitmap_len ) {
511
- struct uverbs_attr * attr = & pbundle -> bundle . attrs [i ];
520
+ struct uverbs_attr * attr = & bundle -> attrs [i ];
512
521
513
522
uverbs_finalize_object (
514
523
attr -> obj_attr .uobject ,
515
524
attr -> obj_attr .attr_elm -> spec .u .obj .access ,
516
525
test_bit (i , pbundle -> uobj_hw_obj_valid ),
517
- commit ,
518
- & pbundle -> bundle );
526
+ commit , bundle );
519
527
}
520
528
521
529
i = -1 ;
522
530
while ((i = find_next_bit (pbundle -> spec_finalize , key_bitmap_len ,
523
531
i + 1 )) < key_bitmap_len ) {
524
- struct uverbs_attr * attr = & pbundle -> bundle . attrs [i ];
532
+ struct uverbs_attr * attr = & bundle -> attrs [i ];
525
533
const struct uverbs_api_attr * attr_uapi ;
526
534
void __rcu * * slot ;
527
535
@@ -535,7 +543,7 @@ static void bundle_destroy(struct bundle_priv *pbundle, bool commit)
535
543
536
544
if (attr_uapi -> spec .type == UVERBS_ATTR_TYPE_IDRS_ARRAY ) {
537
545
uverbs_free_idrs_array (attr_uapi , & attr -> objs_arr_attr ,
538
- commit , & pbundle -> bundle );
546
+ commit , bundle );
539
547
}
540
548
}
541
549
@@ -578,7 +586,8 @@ static int ib_uverbs_cmd_verbs(struct ib_uverbs_file *ufile,
578
586
method_elm -> bundle_size -
579
587
offsetof(struct bundle_priv , internal_buffer );
580
588
pbundle -> alloc_head .next = NULL ;
581
- pbundle -> allocated_mem = & pbundle -> alloc_head ;
589
+ pbundle -> allocated_mem = container_of (& pbundle -> alloc_head ,
590
+ struct bundle_alloc_head , hdr );
582
591
} else {
583
592
pbundle = & onstack ;
584
593
pbundle -> internal_avail = sizeof (pbundle -> internal_buffer );
@@ -596,8 +605,9 @@ static int ib_uverbs_cmd_verbs(struct ib_uverbs_file *ufile,
596
605
pbundle -> user_attrs = user_attrs ;
597
606
598
607
pbundle -> internal_used = ALIGN (pbundle -> method_elm -> key_bitmap_len *
599
- sizeof (* pbundle -> bundle .attrs ),
600
- sizeof (* pbundle -> internal_buffer ));
608
+ sizeof (* container_of (& pbundle -> bundle ,
609
+ struct uverbs_attr_bundle , hdr )-> attrs ),
610
+ sizeof (* pbundle -> internal_buffer ));
601
611
memset (pbundle -> bundle .attr_present , 0 ,
602
612
sizeof (pbundle -> bundle .attr_present ));
603
613
memset (pbundle -> uobj_finalize , 0 , sizeof (pbundle -> uobj_finalize ));
@@ -700,11 +710,13 @@ void uverbs_fill_udata(struct uverbs_attr_bundle *bundle,
700
710
unsigned int attr_out )
701
711
{
702
712
struct bundle_priv * pbundle =
703
- container_of (bundle , struct bundle_priv , bundle );
713
+ container_of (& bundle -> hdr , struct bundle_priv , bundle );
714
+ struct uverbs_attr_bundle * bundle_aux =
715
+ container_of (& pbundle -> bundle , struct uverbs_attr_bundle , hdr );
704
716
const struct uverbs_attr * in =
705
- uverbs_attr_get (& pbundle -> bundle , attr_in );
717
+ uverbs_attr_get (bundle_aux , attr_in );
706
718
const struct uverbs_attr * out =
707
- uverbs_attr_get (& pbundle -> bundle , attr_out );
719
+ uverbs_attr_get (bundle_aux , attr_out );
708
720
709
721
if (!IS_ERR (in )) {
710
722
udata -> inlen = in -> ptr_attr .len ;
@@ -829,7 +841,7 @@ void uverbs_finalize_uobj_create(const struct uverbs_attr_bundle *bundle,
829
841
u16 idx )
830
842
{
831
843
struct bundle_priv * pbundle =
832
- container_of (bundle , struct bundle_priv , bundle );
844
+ container_of (& bundle -> hdr , struct bundle_priv , bundle );
833
845
834
846
__set_bit (uapi_bkey_attr (uapi_key_attr (idx )),
835
847
pbundle -> uobj_hw_obj_valid );
0 commit comments