Skip to content

Commit 959eb2f

Browse files
committed
mac80211_hwsim: stop using pointers as cookies
Instead of using pointers, use sequentially assigned cookies. This is easier to understand while debugging and also avoids problems when the pointer is reused for the next allocation. Signed-off-by: Johannes Berg <[email protected]>
1 parent 00eeccc commit 959eb2f

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

drivers/net/wireless/mac80211_hwsim.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ struct mac80211_hwsim_data {
517517
bool ps_poll_pending;
518518
struct dentry *debugfs;
519519

520+
uintptr_t pending_cookie;
520521
struct sk_buff_head pending; /* packets pending */
521522
/*
522523
* Only radios in the same group can communicate together (the
@@ -963,6 +964,7 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
963964
unsigned int hwsim_flags = 0;
964965
int i;
965966
struct hwsim_tx_rate tx_attempts[IEEE80211_TX_MAX_RATES];
967+
uintptr_t cookie;
966968

967969
if (data->ps != PS_DISABLED)
968970
hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
@@ -1021,7 +1023,10 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
10211023
goto nla_put_failure;
10221024

10231025
/* We create a cookie to identify this skb */
1024-
if (nla_put_u64(skb, HWSIM_ATTR_COOKIE, (unsigned long) my_skb))
1026+
data->pending_cookie++;
1027+
cookie = data->pending_cookie;
1028+
info->rate_driver_data[0] = (void *)cookie;
1029+
if (nla_put_u64(skb, HWSIM_ATTR_COOKIE, cookie))
10251030
goto nla_put_failure;
10261031

10271032
genlmsg_end(skb, msg_head);
@@ -2749,7 +2754,7 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
27492754
struct mac80211_hwsim_data *data2;
27502755
struct ieee80211_tx_info *txi;
27512756
struct hwsim_tx_rate *tx_attempts;
2752-
unsigned long ret_skb_ptr;
2757+
u64 ret_skb_cookie;
27532758
struct sk_buff *skb, *tmp;
27542759
const u8 *src;
27552760
unsigned int hwsim_flags;
@@ -2767,15 +2772,20 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
27672772

27682773
src = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]);
27692774
hwsim_flags = nla_get_u32(info->attrs[HWSIM_ATTR_FLAGS]);
2770-
ret_skb_ptr = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]);
2775+
ret_skb_cookie = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]);
27712776

27722777
data2 = get_hwsim_data_ref_from_addr(src);
27732778
if (!data2)
27742779
goto out;
27752780

27762781
/* look for the skb matching the cookie passed back from user */
27772782
skb_queue_walk_safe(&data2->pending, skb, tmp) {
2778-
if ((unsigned long)skb == ret_skb_ptr) {
2783+
u64 skb_cookie;
2784+
2785+
txi = IEEE80211_SKB_CB(skb);
2786+
skb_cookie = (u64)(uintptr_t)txi->rate_driver_data[0];
2787+
2788+
if (skb_cookie == ret_skb_cookie) {
27792789
skb_unlink(skb, &data2->pending);
27802790
found = true;
27812791
break;

0 commit comments

Comments
 (0)