@@ -75,13 +75,10 @@ struct i915_syncmap {
75
75
unsigned int height ;
76
76
unsigned int bitmap ;
77
77
struct i915_syncmap * parent ;
78
- /*
79
- * Following this header is an array of either seqno or child pointers:
80
- * union {
81
- * u32 seqno[KSYNCMAP];
82
- * struct i915_syncmap *child[KSYNCMAP];
83
- * };
84
- */
78
+ union {
79
+ DECLARE_FLEX_ARRAY (u32 , seqno );
80
+ DECLARE_FLEX_ARRAY (struct i915_syncmap * , child );
81
+ };
85
82
};
86
83
87
84
/**
@@ -99,13 +96,13 @@ void i915_syncmap_init(struct i915_syncmap **root)
99
96
static inline u32 * __sync_seqno (struct i915_syncmap * p )
100
97
{
101
98
GEM_BUG_ON (p -> height );
102
- return ( u32 * )( p + 1 ) ;
99
+ return p -> seqno ;
103
100
}
104
101
105
102
static inline struct i915_syncmap * * __sync_child (struct i915_syncmap * p )
106
103
{
107
104
GEM_BUG_ON (!p -> height );
108
- return ( struct i915_syncmap * * )( p + 1 ) ;
105
+ return p -> child ;
109
106
}
110
107
111
108
static inline unsigned int
@@ -200,7 +197,7 @@ __sync_alloc_leaf(struct i915_syncmap *parent, u64 id)
200
197
{
201
198
struct i915_syncmap * p ;
202
199
203
- p = kmalloc (sizeof ( * p ) + KSYNCMAP * sizeof ( u32 ), GFP_KERNEL );
200
+ p = kmalloc (struct_size ( p , seqno , KSYNCMAP ), GFP_KERNEL );
204
201
if (unlikely (!p ))
205
202
return NULL ;
206
203
@@ -282,7 +279,7 @@ static noinline int __sync_set(struct i915_syncmap **root, u64 id, u32 seqno)
282
279
unsigned int above ;
283
280
284
281
/* Insert a join above the current layer */
285
- next = kzalloc (sizeof ( * next ) + KSYNCMAP * sizeof ( next ),
282
+ next = kzalloc (struct_size ( next , child , KSYNCMAP ),
286
283
GFP_KERNEL );
287
284
if (unlikely (!next ))
288
285
return - ENOMEM ;
0 commit comments