File: util.c

package info (click to toggle)
linux 6.17.13-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,735,112 kB
  • sloc: ansic: 26,688,265; asm: 271,225; sh: 147,407; python: 75,980; makefile: 57,304; perl: 36,943; xml: 19,562; cpp: 5,899; yacc: 4,909; lex: 2,943; awk: 1,556; sed: 29; ruby: 25
file content (56 lines) | stat: -rw-r--r-- 1,382 bytes parent folder | download | duplicates (20)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: GPL-2.0-only
/*
 * KUnit fixture to have a (configurable) wiphy
 *
 * Copyright (C) 2023 Intel Corporation
 */
#include <linux/ieee80211.h>
#include <net/cfg80211.h>
#include <kunit/test.h>
#include <kunit/test-bug.h>
#include "util.h"

int t_wiphy_init(struct kunit_resource *resource, void *ctx)
{
	struct kunit *test = kunit_get_current_test();
	struct cfg80211_ops *ops;
	struct wiphy *wiphy;
	struct t_wiphy_priv *priv;

	ops = kzalloc(sizeof(*ops), GFP_KERNEL);
	KUNIT_ASSERT_NOT_NULL(test, ops);

	wiphy = wiphy_new_nm(ops, sizeof(*priv), "kunit");
	KUNIT_ASSERT_NOT_NULL(test, wiphy);

	priv = wiphy_priv(wiphy);
	priv->ctx = ctx;
	priv->ops = ops;

	/* Initialize channels, feel free to add more here channels/bands */
	memcpy(priv->channels_2ghz, channels_2ghz, sizeof(channels_2ghz));
	wiphy->bands[NL80211_BAND_2GHZ] = &priv->band_2ghz;
	priv->band_2ghz.channels = priv->channels_2ghz;
	priv->band_2ghz.n_channels = ARRAY_SIZE(channels_2ghz);

	resource->data = wiphy;
	resource->name = "wiphy";

	return 0;
}

void t_wiphy_exit(struct kunit_resource *resource)
{
	struct t_wiphy_priv *priv;
	struct cfg80211_ops *ops;

	priv = wiphy_priv(resource->data);
	ops = priv->ops;

	/* Should we ensure anything about the state here?
	 * e.g. full destruction or no calls to any ops on destruction?
	 */

	wiphy_free(resource->data);
	kfree(ops);
}