Skip to content

Commit a180b0b

Browse files
committed
Merge tag 'wireless-next-2024-01-03' of git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next
Johannes Berg says: ==================== Just a couple of more things over the holidays: - first kunit tests for both cfg80211 and mac80211 - a few multi-link fixes - DSCP mapping update - RCU fix * tag 'wireless-next-2024-01-03' of git://git.kernel.org/pub/scm/linux/kernel/git/wireless/wireless-next: wifi: mac80211: remove redundant ML element check wifi: cfg80211: parse all ML elements in an ML probe response wifi: cfg80211: correct comment about MLD ID wifi: cfg80211: Update the default DSCP-to-UP mapping wifi: cfg80211: tests: add some scanning related tests wifi: mac80211: kunit: extend MFP tests wifi: mac80211: kunit: generalize public action test wifi: mac80211: add kunit tests for public action handling kunit: add a convenience allocation wrapper for SKBs kunit: add parameter generation macro using description from array wifi: mac80211: fix spelling typo in comment wifi: cfg80211: fix RCU dereference in __cfg80211_bss_update ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents a2634a5 + 3aca362 commit a180b0b

File tree

16 files changed

+1244
-52
lines changed

16 files changed

+1244
-52
lines changed

Documentation/dev-tools/kunit/usage.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -566,13 +566,9 @@ By reusing the same ``cases`` array from above, we can write the test as a
566566
},
567567
};
568568
569-
// Need a helper function to generate a name for each test case.
570-
static void case_to_desc(const struct sha1_test_case *t, char *desc)
571-
{
572-
strcpy(desc, t->str);
573-
}
574-
// Creates `sha1_gen_params()` to iterate over `cases`.
575-
KUNIT_ARRAY_PARAM(sha1, cases, case_to_desc);
569+
// Creates `sha1_gen_params()` to iterate over `cases` while using
570+
// the struct member `str` for the case description.
571+
KUNIT_ARRAY_PARAM_DESC(sha1, cases, str);
576572
577573
// Looks no different from a normal test.
578574
static void sha1_test(struct kunit *test)
@@ -588,7 +584,7 @@ By reusing the same ``cases`` array from above, we can write the test as a
588584
}
589585
590586
// Instead of KUNIT_CASE, we use KUNIT_CASE_PARAM and pass in the
591-
// function declared by KUNIT_ARRAY_PARAM.
587+
// function declared by KUNIT_ARRAY_PARAM or KUNIT_ARRAY_PARAM_DESC.
592588
static struct kunit_case sha1_test_cases[] = {
593589
KUNIT_CASE_PARAM(sha1_test, sha1_gen_params),
594590
{}

include/kunit/skbuff.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* KUnit resource management helpers for SKBs (skbuff).
4+
*
5+
* Copyright (C) 2023 Intel Corporation
6+
*/
7+
8+
#ifndef _KUNIT_SKBUFF_H
9+
#define _KUNIT_SKBUFF_H
10+
11+
#include <kunit/resource.h>
12+
#include <linux/skbuff.h>
13+
14+
static void kunit_action_kfree_skb(void *p)
15+
{
16+
kfree_skb((struct sk_buff *)p);
17+
}
18+
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+
*
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.
26+
*
27+
* Returns: newly allocated SKB, or %NULL on error
28+
*/
29+
static inline struct sk_buff *kunit_zalloc_skb(struct kunit *test, int len,
30+
gfp_t gfp)
31+
{
32+
struct sk_buff *res = alloc_skb(len, GFP_KERNEL);
33+
34+
if (!res || skb_pad(res, len))
35+
return NULL;
36+
37+
if (kunit_add_action_or_reset(test, kunit_action_kfree_skb, res))
38+
return NULL;
39+
40+
return res;
41+
}
42+
43+
/**
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+
*/
48+
static inline void kunit_kfree_skb(struct kunit *test, struct sk_buff *skb)
49+
{
50+
if (!skb)
51+
return;
52+
53+
kunit_release_action(test, kunit_action_kfree_skb, (void *)skb);
54+
}
55+
56+
#endif /* _KUNIT_SKBUFF_H */

include/kunit/test.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,25 @@ do { \
15141514
return NULL; \
15151515
}
15161516

1517+
/**
1518+
* KUNIT_ARRAY_PARAM_DESC() - Define test parameter generator from an array.
1519+
* @name: prefix for the test parameter generator function.
1520+
* @array: array of test parameters.
1521+
* @desc_member: structure member from array element to use as description
1522+
*
1523+
* Define function @name_gen_params which uses @array to generate parameters.
1524+
*/
1525+
#define KUNIT_ARRAY_PARAM_DESC(name, array, desc_member) \
1526+
static const void *name##_gen_params(const void *prev, char *desc) \
1527+
{ \
1528+
typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array); \
1529+
if (__next - (array) < ARRAY_SIZE((array))) { \
1530+
strscpy(desc, __next->desc_member, KUNIT_PARAM_DESC_SIZE); \
1531+
return __next; \
1532+
} \
1533+
return NULL; \
1534+
}
1535+
15171536
// TODO([email protected]): consider eventually migrating users to explicitly
15181537
// include resource.h themselves if they need it.
15191538
#include <kunit/resource.h>

net/mac80211/debugfs_sta.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "sta_info.h"
1717
#include "driver-ops.h"
1818

19-
/* sta attributtes */
19+
/* sta attributes */
2020

2121
#define STA_READ(name, field, format_string) \
2222
static ssize_t sta_ ##name## _read(struct file *file, \

net/mac80211/ieee80211_i.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2608,4 +2608,14 @@ void ieee80211_check_wbrf_support(struct ieee80211_local *local);
26082608
void ieee80211_add_wbrf(struct ieee80211_local *local, struct cfg80211_chan_def *chandef);
26092609
void ieee80211_remove_wbrf(struct ieee80211_local *local, struct cfg80211_chan_def *chandef);
26102610

2611+
#if IS_ENABLED(CONFIG_MAC80211_KUNIT_TEST)
2612+
#define EXPORT_SYMBOL_IF_MAC80211_KUNIT(sym) EXPORT_SYMBOL_IF_KUNIT(sym)
2613+
#define VISIBLE_IF_MAC80211_KUNIT
2614+
ieee80211_rx_result
2615+
ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx);
2616+
#else
2617+
#define EXPORT_SYMBOL_IF_MAC80211_KUNIT(sym)
2618+
#define VISIBLE_IF_MAC80211_KUNIT static
2619+
#endif
2620+
26112621
#endif /* IEEE80211_I_H */

net/mac80211/mlme.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5407,33 +5407,24 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
54075407
}
54085408

54095409
if (ieee80211_vif_is_mld(&sdata->vif)) {
5410+
struct ieee80211_mle_basic_common_info *common;
5411+
54105412
if (!elems->ml_basic) {
54115413
sdata_info(sdata,
5412-
"MLO association with %pM but no multi-link element in response!\n",
5414+
"MLO association with %pM but no (basic) multi-link element in response!\n",
54135415
assoc_data->ap_addr);
54145416
goto abandon_assoc;
54155417
}
54165418

5417-
if (le16_get_bits(elems->ml_basic->control,
5418-
IEEE80211_ML_CONTROL_TYPE) !=
5419-
IEEE80211_ML_CONTROL_TYPE_BASIC) {
5419+
common = (void *)elems->ml_basic->variable;
5420+
5421+
if (memcmp(assoc_data->ap_addr,
5422+
common->mld_mac_addr, ETH_ALEN)) {
54205423
sdata_info(sdata,
5421-
"bad multi-link element (control=0x%x)\n",
5422-
le16_to_cpu(elems->ml_basic->control));
5424+
"AP MLD MAC address mismatch: got %pM expected %pM\n",
5425+
common->mld_mac_addr,
5426+
assoc_data->ap_addr);
54235427
goto abandon_assoc;
5424-
} else {
5425-
struct ieee80211_mle_basic_common_info *common;
5426-
5427-
common = (void *)elems->ml_basic->variable;
5428-
5429-
if (memcmp(assoc_data->ap_addr,
5430-
common->mld_mac_addr, ETH_ALEN)) {
5431-
sdata_info(sdata,
5432-
"AP MLD MAC address mismatch: got %pM expected %pM\n",
5433-
common->mld_mac_addr,
5434-
assoc_data->ap_addr);
5435-
goto abandon_assoc;
5436-
}
54375428
}
54385429
}
54395430

net/mac80211/rx.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/export.h>
2020
#include <linux/kcov.h>
2121
#include <linux/bitops.h>
22+
#include <kunit/visibility.h>
2223
#include <net/mac80211.h>
2324
#include <net/ieee80211_radiotap.h>
2425
#include <asm/unaligned.h>
@@ -2414,7 +2415,7 @@ static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
24142415
return 0;
24152416
}
24162417

2417-
static ieee80211_rx_result
2418+
VISIBLE_IF_MAC80211_KUNIT ieee80211_rx_result
24182419
ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
24192420
{
24202421
struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
@@ -2493,6 +2494,7 @@ ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
24932494

24942495
return RX_CONTINUE;
24952496
}
2497+
EXPORT_SYMBOL_IF_MAC80211_KUNIT(ieee80211_drop_unencrypted_mgmt);
24962498

24972499
static ieee80211_rx_result
24982500
__ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)

net/mac80211/tests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
mac80211-tests-y += module.o elems.o
1+
mac80211-tests-y += module.o elems.o mfp.o
22

33
obj-$(CONFIG_MAC80211_KUNIT_TEST) += mac80211-tests.o

0 commit comments

Comments
 (0)