All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mac80211_hwsim: stop using pointers as cookies
@ 2015-11-06 10:57 Johannes Berg
  2015-11-08 23:49 ` Bob Copeland
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Berg @ 2015-11-06 10:57 UTC (permalink / raw)
  To: linux-wireless; +Cc: Bob Copeland, Johannes Berg

From: Johannes Berg <johannes.berg@intel.com>

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 <johannes.berg@intel.com>
---
 drivers/net/wireless/mac80211_hwsim.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index ee46f4647fbc..ffb6c72005fd 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -514,6 +514,7 @@ struct mac80211_hwsim_data {
 	bool ps_poll_pending;
 	struct dentry *debugfs;
 
+	uintptr_t pending_cookie;
 	struct sk_buff_head pending;	/* packets pending */
 	/*
 	 * Only radios in the same group can communicate together (the
@@ -960,6 +961,7 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
 	unsigned int hwsim_flags = 0;
 	int i;
 	struct hwsim_tx_rate tx_attempts[IEEE80211_TX_MAX_RATES];
+	uintptr_t cookie;
 
 	if (data->ps != PS_DISABLED)
 		hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
@@ -1018,7 +1020,10 @@ static void mac80211_hwsim_tx_frame_nl(struct ieee80211_hw *hw,
 		goto nla_put_failure;
 
 	/* We create a cookie to identify this skb */
-	if (nla_put_u64(skb, HWSIM_ATTR_COOKIE, (unsigned long) my_skb))
+	data->pending_cookie++;
+	cookie = data->pending_cookie;
+	info->rate_driver_data[0] = (void *)cookie;
+	if (nla_put_u64(skb, HWSIM_ATTR_COOKIE, cookie))
 		goto nla_put_failure;
 
 	genlmsg_end(skb, msg_head);
@@ -2710,7 +2715,7 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
 	struct mac80211_hwsim_data *data2;
 	struct ieee80211_tx_info *txi;
 	struct hwsim_tx_rate *tx_attempts;
-	unsigned long ret_skb_ptr;
+	u64 ret_skb_cookie;
 	struct sk_buff *skb, *tmp;
 	const u8 *src;
 	unsigned int hwsim_flags;
@@ -2728,7 +2733,7 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
 
 	src = (void *)nla_data(info->attrs[HWSIM_ATTR_ADDR_TRANSMITTER]);
 	hwsim_flags = nla_get_u32(info->attrs[HWSIM_ATTR_FLAGS]);
-	ret_skb_ptr = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]);
+	ret_skb_cookie = nla_get_u64(info->attrs[HWSIM_ATTR_COOKIE]);
 
 	data2 = get_hwsim_data_ref_from_addr(src);
 	if (!data2)
@@ -2736,7 +2741,12 @@ static int hwsim_tx_info_frame_received_nl(struct sk_buff *skb_2,
 
 	/* look for the skb matching the cookie passed back from user */
 	skb_queue_walk_safe(&data2->pending, skb, tmp) {
-		if ((unsigned long)skb == ret_skb_ptr) {
+		u64 skb_cookie;
+
+		txi = IEEE80211_SKB_CB(skb);
+		skb_cookie = (u64)(uintptr_t)txi->driver_data[0];
+
+		if (skb_cookie == ret_skb_cookie) {
 			skb_unlink(skb, &data2->pending);
 			found = true;
 			break;
-- 
2.6.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mac80211_hwsim: stop using pointers as cookies
  2015-11-06 10:57 [PATCH] mac80211_hwsim: stop using pointers as cookies Johannes Berg
@ 2015-11-08 23:49 ` Bob Copeland
  2015-11-27 13:52   ` Johannes Berg
  0 siblings, 1 reply; 3+ messages in thread
From: Bob Copeland @ 2015-11-08 23:49 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linux-wireless, Johannes Berg

On Fri, Nov 06, 2015 at 11:57:23AM +0100, Johannes Berg wrote:
> 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.

I tested this out in wmediumd and it didn't go so well...

> +	info->rate_driver_data[0] = (void *)cookie;

[...]

> +		skb_cookie = (u64)(uintptr_t)txi->driver_data[0];

rate_driver_data vs driver_data?

-- 
Bob Copeland %% http://bobcopeland.com/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mac80211_hwsim: stop using pointers as cookies
  2015-11-08 23:49 ` Bob Copeland
@ 2015-11-27 13:52   ` Johannes Berg
  0 siblings, 0 replies; 3+ messages in thread
From: Johannes Berg @ 2015-11-27 13:52 UTC (permalink / raw)
  To: Bob Copeland; +Cc: linux-wireless

On Sun, 2015-11-08 at 18:49 -0500, Bob Copeland wrote:
> On Fri, Nov 06, 2015 at 11:57:23AM +0100, Johannes Berg wrote:
> > 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.
> 
> I tested this out in wmediumd and it didn't go so well...
> 
> > +	info->rate_driver_data[0] = (void *)cookie;
> 
> [...]
> 
> > +		skb_cookie = (u64)(uintptr_t)txi->driver_data[0];
> 
> rate_driver_data vs driver_data?

Yep, that fixes it. I've applied the patch with that fix.

johannes

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-27 13:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-06 10:57 [PATCH] mac80211_hwsim: stop using pointers as cookies Johannes Berg
2015-11-08 23:49 ` Bob Copeland
2015-11-27 13:52   ` Johannes Berg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.