Skip to content

Commit

Permalink
Merge tag 'wireless-next-2024-01-03' of git://git.kernel.org/pub/scm/…
Browse files Browse the repository at this point in the history
…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/20240103144423.52269-3-johannes@sipsolutions.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Jan 5, 2024
2 parents a2634a5 + 3aca362 commit a180b0b
Show file tree
Hide file tree
Showing 16 changed files with 1,244 additions and 52 deletions.
12 changes: 4 additions & 8 deletions Documentation/dev-tools/kunit/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,9 @@ By reusing the same ``cases`` array from above, we can write the test as a
},
};
// Need a helper function to generate a name for each test case.
static void case_to_desc(const struct sha1_test_case *t, char *desc)
{
strcpy(desc, t->str);
}
// Creates `sha1_gen_params()` to iterate over `cases`.
KUNIT_ARRAY_PARAM(sha1, cases, case_to_desc);
// Creates `sha1_gen_params()` to iterate over `cases` while using
// the struct member `str` for the case description.
KUNIT_ARRAY_PARAM_DESC(sha1, cases, str);
// Looks no different from a normal test.
static void sha1_test(struct kunit *test)
Expand All @@ -588,7 +584,7 @@ By reusing the same ``cases`` array from above, we can write the test as a
}
// Instead of KUNIT_CASE, we use KUNIT_CASE_PARAM and pass in the
// function declared by KUNIT_ARRAY_PARAM.
// function declared by KUNIT_ARRAY_PARAM or KUNIT_ARRAY_PARAM_DESC.
static struct kunit_case sha1_test_cases[] = {
KUNIT_CASE_PARAM(sha1_test, sha1_gen_params),
{}
Expand Down
56 changes: 56 additions & 0 deletions include/kunit/skbuff.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* KUnit resource management helpers for SKBs (skbuff).
*
* Copyright (C) 2023 Intel Corporation
*/

#ifndef _KUNIT_SKBUFF_H
#define _KUNIT_SKBUFF_H

#include <kunit/resource.h>
#include <linux/skbuff.h>

static void kunit_action_kfree_skb(void *p)
{
kfree_skb((struct sk_buff *)p);
}

/**
* kunit_zalloc_skb() - Allocate and initialize a resource managed skb.
* @test: The test case to which the skb belongs
* @len: size to allocate
*
* Allocate a new struct sk_buff with GFP_KERNEL, zero fill the give length
* and add it as a resource to the kunit test for automatic cleanup.
*
* Returns: newly allocated SKB, or %NULL on error
*/
static inline struct sk_buff *kunit_zalloc_skb(struct kunit *test, int len,
gfp_t gfp)
{
struct sk_buff *res = alloc_skb(len, GFP_KERNEL);

if (!res || skb_pad(res, len))
return NULL;

if (kunit_add_action_or_reset(test, kunit_action_kfree_skb, res))
return NULL;

return res;
}

/**
* kunit_kfree_skb() - Like kfree_skb except for allocations managed by KUnit.
* @test: The test case to which the resource belongs.
* @skb: The SKB to free.
*/
static inline void kunit_kfree_skb(struct kunit *test, struct sk_buff *skb)
{
if (!skb)
return;

kunit_release_action(test, kunit_action_kfree_skb, (void *)skb);
}

#endif /* _KUNIT_SKBUFF_H */
19 changes: 19 additions & 0 deletions include/kunit/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,25 @@ do { \
return NULL; \
}

/**
* KUNIT_ARRAY_PARAM_DESC() - Define test parameter generator from an array.
* @name: prefix for the test parameter generator function.
* @array: array of test parameters.
* @desc_member: structure member from array element to use as description
*
* Define function @name_gen_params which uses @array to generate parameters.
*/
#define KUNIT_ARRAY_PARAM_DESC(name, array, desc_member) \
static const void *name##_gen_params(const void *prev, char *desc) \
{ \
typeof((array)[0]) *__next = prev ? ((typeof(__next)) prev) + 1 : (array); \
if (__next - (array) < ARRAY_SIZE((array))) { \
strscpy(desc, __next->desc_member, KUNIT_PARAM_DESC_SIZE); \
return __next; \
} \
return NULL; \
}

// TODO(dlatypov@google.com): consider eventually migrating users to explicitly
// include resource.h themselves if they need it.
#include <kunit/resource.h>
Expand Down
2 changes: 1 addition & 1 deletion net/mac80211/debugfs_sta.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "sta_info.h"
#include "driver-ops.h"

/* sta attributtes */
/* sta attributes */

#define STA_READ(name, field, format_string) \
static ssize_t sta_ ##name## _read(struct file *file, \
Expand Down
10 changes: 10 additions & 0 deletions net/mac80211/ieee80211_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -2608,4 +2608,14 @@ void ieee80211_check_wbrf_support(struct ieee80211_local *local);
void ieee80211_add_wbrf(struct ieee80211_local *local, struct cfg80211_chan_def *chandef);
void ieee80211_remove_wbrf(struct ieee80211_local *local, struct cfg80211_chan_def *chandef);

#if IS_ENABLED(CONFIG_MAC80211_KUNIT_TEST)
#define EXPORT_SYMBOL_IF_MAC80211_KUNIT(sym) EXPORT_SYMBOL_IF_KUNIT(sym)
#define VISIBLE_IF_MAC80211_KUNIT
ieee80211_rx_result
ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx);
#else
#define EXPORT_SYMBOL_IF_MAC80211_KUNIT(sym)
#define VISIBLE_IF_MAC80211_KUNIT static
#endif

#endif /* IEEE80211_I_H */
29 changes: 10 additions & 19 deletions net/mac80211/mlme.c
Original file line number Diff line number Diff line change
Expand Up @@ -5407,33 +5407,24 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
}

if (ieee80211_vif_is_mld(&sdata->vif)) {
struct ieee80211_mle_basic_common_info *common;

if (!elems->ml_basic) {
sdata_info(sdata,
"MLO association with %pM but no multi-link element in response!\n",
"MLO association with %pM but no (basic) multi-link element in response!\n",
assoc_data->ap_addr);
goto abandon_assoc;
}

if (le16_get_bits(elems->ml_basic->control,
IEEE80211_ML_CONTROL_TYPE) !=
IEEE80211_ML_CONTROL_TYPE_BASIC) {
common = (void *)elems->ml_basic->variable;

if (memcmp(assoc_data->ap_addr,
common->mld_mac_addr, ETH_ALEN)) {
sdata_info(sdata,
"bad multi-link element (control=0x%x)\n",
le16_to_cpu(elems->ml_basic->control));
"AP MLD MAC address mismatch: got %pM expected %pM\n",
common->mld_mac_addr,
assoc_data->ap_addr);
goto abandon_assoc;
} else {
struct ieee80211_mle_basic_common_info *common;

common = (void *)elems->ml_basic->variable;

if (memcmp(assoc_data->ap_addr,
common->mld_mac_addr, ETH_ALEN)) {
sdata_info(sdata,
"AP MLD MAC address mismatch: got %pM expected %pM\n",
common->mld_mac_addr,
assoc_data->ap_addr);
goto abandon_assoc;
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion net/mac80211/rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <linux/export.h>
#include <linux/kcov.h>
#include <linux/bitops.h>
#include <kunit/visibility.h>
#include <net/mac80211.h>
#include <net/ieee80211_radiotap.h>
#include <asm/unaligned.h>
Expand Down Expand Up @@ -2414,7 +2415,7 @@ static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
return 0;
}

static ieee80211_rx_result
VISIBLE_IF_MAC80211_KUNIT ieee80211_rx_result
ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
{
struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
Expand Down Expand Up @@ -2493,6 +2494,7 @@ ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)

return RX_CONTINUE;
}
EXPORT_SYMBOL_IF_MAC80211_KUNIT(ieee80211_drop_unencrypted_mgmt);

static ieee80211_rx_result
__ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
Expand Down
2 changes: 1 addition & 1 deletion net/mac80211/tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mac80211-tests-y += module.o elems.o
mac80211-tests-y += module.o elems.o mfp.o

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

0 comments on commit a180b0b

Please sign in to comment.