1 /* SPDX-License-Identifier: GPL-2.0 */
3 * KUnit resource management helpers for SKBs (skbuff).
5 * Copyright (C) 2023 Intel Corporation
8 #ifndef _KUNIT_SKBUFF_H
9 #define _KUNIT_SKBUFF_H
11 #include <kunit/resource.h>
12 #include <linux/skbuff.h>
14 static void kunit_action_kfree_skb(void *p
)
16 kfree_skb((struct sk_buff
*)p
);
20 * kunit_zalloc_skb() - Allocate and initialize a resource managed skb.
21 * @test: The test case to which the skb belongs
22 * @len: size to allocate
23 * @gfp: allocation flags
25 * Allocate a new struct sk_buff with gfp flags, zero fill the given length
26 * and add it as a resource to the kunit test for automatic cleanup.
28 * Returns: newly allocated SKB, or %NULL on error
30 static inline struct sk_buff
*kunit_zalloc_skb(struct kunit
*test
, int len
,
33 struct sk_buff
*res
= alloc_skb(len
, gfp
);
35 if (!res
|| skb_pad(res
, len
))
38 if (kunit_add_action_or_reset(test
, kunit_action_kfree_skb
, res
))
45 * kunit_kfree_skb() - Like kfree_skb except for allocations managed by KUnit.
46 * @test: The test case to which the resource belongs.
47 * @skb: The SKB to free.
49 static inline void kunit_kfree_skb(struct kunit
*test
, struct sk_buff
*skb
)
54 kunit_release_action(test
, kunit_action_kfree_skb
, (void *)skb
);
57 #endif /* _KUNIT_SKBUFF_H */