@@ -257,15 +257,16 @@ struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
257257 kmemcheck_annotate_variable (shinfo -> destructor_arg );
258258
259259 if (flags & SKB_ALLOC_FCLONE ) {
260- struct sk_buff * child = skb + 1 ;
261- atomic_t * fclone_ref = (atomic_t * ) (child + 1 );
260+ struct sk_buff_fclones * fclones ;
262261
263- kmemcheck_annotate_bitfield (child , flags1 );
262+ fclones = container_of (skb , struct sk_buff_fclones , skb1 );
263+
264+ kmemcheck_annotate_bitfield (& fclones -> skb2 , flags1 );
264265 skb -> fclone = SKB_FCLONE_ORIG ;
265- atomic_set (fclone_ref , 1 );
266+ atomic_set (& fclones -> fclone_ref , 1 );
266267
267- child -> fclone = SKB_FCLONE_UNAVAILABLE ;
268- child -> pfmemalloc = pfmemalloc ;
268+ fclones -> skb2 . fclone = SKB_FCLONE_UNAVAILABLE ;
269+ fclones -> skb2 . pfmemalloc = pfmemalloc ;
269270 }
270271out :
271272 return skb ;
@@ -524,31 +525,29 @@ static void skb_release_data(struct sk_buff *skb)
524525 */
525526static void kfree_skbmem (struct sk_buff * skb )
526527{
527- struct sk_buff * other ;
528- atomic_t * fclone_ref ;
528+ struct sk_buff_fclones * fclones ;
529529
530530 switch (skb -> fclone ) {
531531 case SKB_FCLONE_UNAVAILABLE :
532532 kmem_cache_free (skbuff_head_cache , skb );
533533 break ;
534534
535535 case SKB_FCLONE_ORIG :
536- fclone_ref = ( atomic_t * ) ( skb + 2 );
537- if (atomic_dec_and_test (fclone_ref ))
538- kmem_cache_free (skbuff_fclone_cache , skb );
536+ fclones = container_of ( skb , struct sk_buff_fclones , skb1 );
537+ if (atomic_dec_and_test (& fclones -> fclone_ref ))
538+ kmem_cache_free (skbuff_fclone_cache , fclones );
539539 break ;
540540
541541 case SKB_FCLONE_CLONE :
542- fclone_ref = (atomic_t * ) (skb + 1 );
543- other = skb - 1 ;
542+ fclones = container_of (skb , struct sk_buff_fclones , skb2 );
544543
545544 /* The clone portion is available for
546545 * fast-cloning again.
547546 */
548547 skb -> fclone = SKB_FCLONE_UNAVAILABLE ;
549548
550- if (atomic_dec_and_test (fclone_ref ))
551- kmem_cache_free (skbuff_fclone_cache , other );
549+ if (atomic_dec_and_test (& fclones -> fclone_ref ))
550+ kmem_cache_free (skbuff_fclone_cache , fclones );
552551 break ;
553552 }
554553}
@@ -859,17 +858,18 @@ EXPORT_SYMBOL_GPL(skb_copy_ubufs);
859858
860859struct sk_buff * skb_clone (struct sk_buff * skb , gfp_t gfp_mask )
861860{
862- struct sk_buff * n ;
861+ struct sk_buff_fclones * fclones = container_of (skb ,
862+ struct sk_buff_fclones ,
863+ skb1 );
864+ struct sk_buff * n = & fclones -> skb2 ;
863865
864866 if (skb_orphan_frags (skb , gfp_mask ))
865867 return NULL ;
866868
867- n = skb + 1 ;
868869 if (skb -> fclone == SKB_FCLONE_ORIG &&
869870 n -> fclone == SKB_FCLONE_UNAVAILABLE ) {
870- atomic_t * fclone_ref = (atomic_t * ) (n + 1 );
871871 n -> fclone = SKB_FCLONE_CLONE ;
872- atomic_inc (fclone_ref );
872+ atomic_inc (& fclones -> fclone_ref );
873873 } else {
874874 if (skb_pfmemalloc (skb ))
875875 gfp_mask |= __GFP_MEMALLOC ;
@@ -3240,8 +3240,7 @@ void __init skb_init(void)
32403240 SLAB_HWCACHE_ALIGN |SLAB_PANIC ,
32413241 NULL );
32423242 skbuff_fclone_cache = kmem_cache_create ("skbuff_fclone_cache" ,
3243- (2 * sizeof (struct sk_buff )) +
3244- sizeof (atomic_t ),
3243+ sizeof (struct sk_buff_fclones ),
32453244 0 ,
32463245 SLAB_HWCACHE_ALIGN |SLAB_PANIC ,
32473246 NULL );
0 commit comments