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
24 * Allocate a new struct sk_buff with GFP_KERNEL, zero fill the give length
25 * and add it as a resource to the kunit test for automatic cleanup.
27 * Returns: newly allocated SKB, or %NULL on error
29 static inline struct sk_buff *kunit_zalloc_skb(struct kunit *test, int len,
32 struct sk_buff *res = alloc_skb(len, GFP_KERNEL);
34 if (!res || skb_pad(res, len))
37 if (kunit_add_action_or_reset(test, kunit_action_kfree_skb, res))
44 * kunit_kfree_skb() - Like kfree_skb except for allocations managed by KUnit.
45 * @test: The test case to which the resource belongs.
46 * @skb: The SKB to free.
48 static inline void kunit_kfree_skb(struct kunit *test, struct sk_buff *skb)
53 kunit_release_action(test, kunit_action_kfree_skb, (void *)skb);
56 #endif /* _KUNIT_SKBUFF_H */