accel/ivpu: Enable HWS by default on all platforms
[drm/drm-misc.git] / include / kunit / skbuff.h
blob07784694357c10eaa32d1c9db2d9068a4c9361c2
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * KUnit resource management helpers for SKBs (skbuff).
5 * Copyright (C) 2023 Intel Corporation
6 */
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);
19 /**
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,
31 gfp_t gfp)
33 struct sk_buff *res = alloc_skb(len, gfp);
35 if (!res || skb_pad(res, len))
36 return NULL;
38 if (kunit_add_action_or_reset(test, kunit_action_kfree_skb, res))
39 return NULL;
41 return res;
44 /**
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)
51 if (!skb)
52 return;
54 kunit_release_action(test, kunit_action_kfree_skb, (void *)skb);
57 #endif /* _KUNIT_SKBUFF_H */