3636#include "uverbs.h"
3737
3838struct 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+ );
4042 u8 data [];
4143};
4244
4345struct bundle_priv {
4446 /* Must be first */
45- struct bundle_alloc_head alloc_head ;
47+ struct bundle_alloc_head_hdr alloc_head ;
4648 struct bundle_alloc_head * allocated_mem ;
4749 size_t internal_avail ;
4850 size_t internal_used ;
@@ -64,7 +66,7 @@ struct bundle_priv {
6466 * Must be last. bundle ends in a flex array which overlaps
6567 * internal_buffer.
6668 */
67- struct uverbs_attr_bundle bundle ;
69+ struct uverbs_attr_bundle_hdr bundle ;
6870 u64 internal_buffer [32 ];
6971};
7072
@@ -77,9 +79,10 @@ void uapi_compute_bundle_size(struct uverbs_api_ioctl_method *method_elm,
7779 unsigned int num_attrs )
7880{
7981 struct bundle_priv * pbundle ;
82+ struct uverbs_attr_bundle * bundle ;
8083 size_t bundle_size =
8184 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 +
8386 sizeof (* pbundle -> uattrs ) * num_attrs ;
8487
8588 method_elm -> use_stack = bundle_size <= sizeof (* pbundle );
@@ -107,7 +110,7 @@ __malloc void *_uverbs_alloc(struct uverbs_attr_bundle *bundle, size_t size,
107110 gfp_t flags )
108111{
109112 struct bundle_priv * pbundle =
110- container_of (bundle , struct bundle_priv , bundle );
113+ container_of (& bundle -> hdr , struct bundle_priv , bundle );
111114 size_t new_used ;
112115 void * res ;
113116
@@ -149,7 +152,7 @@ static int uverbs_set_output(const struct uverbs_attr_bundle *bundle,
149152 const struct uverbs_attr * attr )
150153{
151154 struct bundle_priv * pbundle =
152- container_of (bundle , struct bundle_priv , bundle );
155+ container_of (& bundle -> hdr , struct bundle_priv , bundle );
153156 u16 flags ;
154157
155158 flags = pbundle -> uattrs [attr -> ptr_attr .uattr_idx ].flags |
@@ -166,6 +169,8 @@ static int uverbs_process_idrs_array(struct bundle_priv *pbundle,
166169 struct ib_uverbs_attr * uattr ,
167170 u32 attr_bkey )
168171{
172+ struct uverbs_attr_bundle * bundle =
173+ container_of (& pbundle -> bundle , struct uverbs_attr_bundle , hdr );
169174 const struct uverbs_attr_spec * spec = & attr_uapi -> spec ;
170175 size_t array_len ;
171176 u32 * idr_vals ;
@@ -184,7 +189,7 @@ static int uverbs_process_idrs_array(struct bundle_priv *pbundle,
184189 return - EINVAL ;
185190
186191 attr -> uobjects =
187- uverbs_alloc (& pbundle -> bundle ,
192+ uverbs_alloc (bundle ,
188193 array_size (array_len , sizeof (* attr -> uobjects )));
189194 if (IS_ERR (attr -> uobjects ))
190195 return PTR_ERR (attr -> uobjects );
@@ -209,7 +214,7 @@ static int uverbs_process_idrs_array(struct bundle_priv *pbundle,
209214 for (i = 0 ; i != array_len ; i ++ ) {
210215 attr -> uobjects [i ] = uverbs_get_uobject_from_file (
211216 spec -> u2 .objs_arr .obj_type , spec -> u2 .objs_arr .access ,
212- idr_vals [i ], & pbundle -> bundle );
217+ idr_vals [i ], bundle );
213218 if (IS_ERR (attr -> uobjects [i ])) {
214219 ret = PTR_ERR (attr -> uobjects [i ]);
215220 break ;
@@ -240,7 +245,9 @@ static int uverbs_process_attr(struct bundle_priv *pbundle,
240245 struct ib_uverbs_attr * uattr , u32 attr_bkey )
241246{
242247 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 ];
244251 const struct uverbs_attr_spec * val_spec = spec ;
245252 struct uverbs_obj_attr * o_attr ;
246253
@@ -288,7 +295,7 @@ static int uverbs_process_attr(struct bundle_priv *pbundle,
288295 if (val_spec -> alloc_and_copy && !uverbs_attr_ptr_is_inline (e )) {
289296 void * p ;
290297
291- p = uverbs_alloc (& pbundle -> bundle , uattr -> len );
298+ p = uverbs_alloc (bundle , uattr -> len );
292299 if (IS_ERR (p ))
293300 return PTR_ERR (p );
294301
@@ -321,7 +328,7 @@ static int uverbs_process_attr(struct bundle_priv *pbundle,
321328 */
322329 o_attr -> uobject = uverbs_get_uobject_from_file (
323330 spec -> u .obj .obj_type , spec -> u .obj .access ,
324- uattr -> data_s64 , & pbundle -> bundle );
331+ uattr -> data_s64 , bundle );
325332 if (IS_ERR (o_attr -> uobject ))
326333 return PTR_ERR (o_attr -> uobject );
327334 __set_bit (attr_bkey , pbundle -> uobj_finalize );
@@ -422,6 +429,8 @@ static int ib_uverbs_run_method(struct bundle_priv *pbundle,
422429 unsigned int num_attrs )
423430{
424431 int (* handler )(struct uverbs_attr_bundle * attrs );
432+ struct uverbs_attr_bundle * bundle =
433+ container_of (& pbundle -> bundle , struct uverbs_attr_bundle , hdr );
425434 size_t uattrs_size = array_size (sizeof (* pbundle -> uattrs ), num_attrs );
426435 unsigned int destroy_bkey = pbundle -> method_elm -> destroy_bkey ;
427436 unsigned int i ;
@@ -434,7 +443,7 @@ static int ib_uverbs_run_method(struct bundle_priv *pbundle,
434443 if (!handler )
435444 return - EIO ;
436445
437- pbundle -> uattrs = uverbs_alloc (& pbundle -> bundle , uattrs_size );
446+ pbundle -> uattrs = uverbs_alloc (bundle , uattrs_size );
438447 if (IS_ERR (pbundle -> uattrs ))
439448 return PTR_ERR (pbundle -> uattrs );
440449 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,
453462 return - EINVAL ;
454463
455464 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 ,
458466 UVERBS_ATTR_UHW_IN , UVERBS_ATTR_UHW_OUT );
459467 else
460468 pbundle -> bundle .driver_udata = (struct ib_udata ){};
461469
462470 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 ;
465472
466- ret = uobj_destroy (destroy_attr -> uobject , & pbundle -> bundle );
473+ ret = uobj_destroy (destroy_attr -> uobject , bundle );
467474 if (ret )
468475 return ret ;
469476 __clear_bit (destroy_bkey , pbundle -> uobj_finalize );
470477
471- ret = handler (& pbundle -> bundle );
478+ ret = handler (bundle );
472479 uobj_put_destroy (destroy_attr -> uobject );
473480 } else {
474- ret = handler (& pbundle -> bundle );
481+ ret = handler (bundle );
475482 }
476483
477484 /*
@@ -481,10 +488,10 @@ static int ib_uverbs_run_method(struct bundle_priv *pbundle,
481488 */
482489 if (!ret && pbundle -> method_elm -> has_udata ) {
483490 const struct uverbs_attr * attr =
484- uverbs_attr_get (& pbundle -> bundle , UVERBS_ATTR_UHW_OUT );
491+ uverbs_attr_get (bundle , UVERBS_ATTR_UHW_OUT );
485492
486493 if (!IS_ERR (attr ))
487- ret = uverbs_set_output (& pbundle -> bundle , attr );
494+ ret = uverbs_set_output (bundle , attr );
488495 }
489496
490497 /*
@@ -501,27 +508,28 @@ static int ib_uverbs_run_method(struct bundle_priv *pbundle,
501508static void bundle_destroy (struct bundle_priv * pbundle , bool commit )
502509{
503510 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 );
504513 struct bundle_alloc_head * memblock ;
505514 unsigned int i ;
506515
507516 /* fast path for simple uobjects */
508517 i = -1 ;
509518 while ((i = find_next_bit (pbundle -> uobj_finalize , key_bitmap_len ,
510519 i + 1 )) < key_bitmap_len ) {
511- struct uverbs_attr * attr = & pbundle -> bundle . attrs [i ];
520+ struct uverbs_attr * attr = & bundle -> attrs [i ];
512521
513522 uverbs_finalize_object (
514523 attr -> obj_attr .uobject ,
515524 attr -> obj_attr .attr_elm -> spec .u .obj .access ,
516525 test_bit (i , pbundle -> uobj_hw_obj_valid ),
517- commit ,
518- & pbundle -> bundle );
526+ commit , bundle );
519527 }
520528
521529 i = -1 ;
522530 while ((i = find_next_bit (pbundle -> spec_finalize , key_bitmap_len ,
523531 i + 1 )) < key_bitmap_len ) {
524- struct uverbs_attr * attr = & pbundle -> bundle . attrs [i ];
532+ struct uverbs_attr * attr = & bundle -> attrs [i ];
525533 const struct uverbs_api_attr * attr_uapi ;
526534 void __rcu * * slot ;
527535
@@ -535,7 +543,7 @@ static void bundle_destroy(struct bundle_priv *pbundle, bool commit)
535543
536544 if (attr_uapi -> spec .type == UVERBS_ATTR_TYPE_IDRS_ARRAY ) {
537545 uverbs_free_idrs_array (attr_uapi , & attr -> objs_arr_attr ,
538- commit , & pbundle -> bundle );
546+ commit , bundle );
539547 }
540548 }
541549
@@ -578,7 +586,8 @@ static int ib_uverbs_cmd_verbs(struct ib_uverbs_file *ufile,
578586 method_elm -> bundle_size -
579587 offsetof(struct bundle_priv , internal_buffer );
580588 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 );
582591 } else {
583592 pbundle = & onstack ;
584593 pbundle -> internal_avail = sizeof (pbundle -> internal_buffer );
@@ -596,8 +605,9 @@ static int ib_uverbs_cmd_verbs(struct ib_uverbs_file *ufile,
596605 pbundle -> user_attrs = user_attrs ;
597606
598607 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 ));
601611 memset (pbundle -> bundle .attr_present , 0 ,
602612 sizeof (pbundle -> bundle .attr_present ));
603613 memset (pbundle -> uobj_finalize , 0 , sizeof (pbundle -> uobj_finalize ));
@@ -700,11 +710,13 @@ void uverbs_fill_udata(struct uverbs_attr_bundle *bundle,
700710 unsigned int attr_out )
701711{
702712 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 );
704716 const struct uverbs_attr * in =
705- uverbs_attr_get (& pbundle -> bundle , attr_in );
717+ uverbs_attr_get (bundle_aux , attr_in );
706718 const struct uverbs_attr * out =
707- uverbs_attr_get (& pbundle -> bundle , attr_out );
719+ uverbs_attr_get (bundle_aux , attr_out );
708720
709721 if (!IS_ERR (in )) {
710722 udata -> inlen = in -> ptr_attr .len ;
@@ -829,7 +841,7 @@ void uverbs_finalize_uobj_create(const struct uverbs_attr_bundle *bundle,
829841 u16 idx )
830842{
831843 struct bundle_priv * pbundle =
832- container_of (bundle , struct bundle_priv , bundle );
844+ container_of (& bundle -> hdr , struct bundle_priv , bundle );
833845
834846 __set_bit (uapi_bkey_attr (uapi_key_attr (idx )),
835847 pbundle -> uobj_hw_obj_valid );
0 commit comments