/* SPDX-License-Identifier: GPL-2.0 */1/*2* KUnit resource management helpers for SKBs (skbuff).3*4* Copyright (C) 2023 Intel Corporation5*/67#ifndef _KUNIT_SKBUFF_H8#define _KUNIT_SKBUFF_H910#include <kunit/resource.h>11#include <linux/skbuff.h>1213static void kunit_action_kfree_skb(void *p)14{15kfree_skb((struct sk_buff *)p);16}1718/**19* kunit_zalloc_skb() - Allocate and initialize a resource managed skb.20* @test: The test case to which the skb belongs21* @len: size to allocate22* @gfp: allocation flags23*24* Allocate a new struct sk_buff with gfp flags, zero fill the given length25* and add it as a resource to the kunit test for automatic cleanup.26*27* Returns: newly allocated SKB, or %NULL on error28*/29static inline struct sk_buff *kunit_zalloc_skb(struct kunit *test, int len,30gfp_t gfp)31{32struct sk_buff *res = alloc_skb(len, gfp);3334if (!res || skb_pad(res, len))35return NULL;3637if (kunit_add_action_or_reset(test, kunit_action_kfree_skb, res))38return NULL;3940return res;41}4243/**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.47*/48static inline void kunit_kfree_skb(struct kunit *test, struct sk_buff *skb)49{50if (!skb)51return;5253kunit_release_action(test, kunit_action_kfree_skb, (void *)skb);54}5556#endif /* _KUNIT_SKBUFF_H */575859