From: Johannes Berg <johannes@sipsolutions.net>
To: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Cc: linux-wireless@vger.kernel.org
Subject: Re: [PATCH v8 2/2] nl80211: Convert sched_scan_req pointer to RCU pointer
Date: Fri, 28 Nov 2014 13:34:12 +0100 [thread overview]
Message-ID: <1417178052.27562.2.camel@sipsolutions.net> (raw)
In-Reply-To: <1417083668-11958-3-git-send-email-jukka.rissanen@linux.intel.com> (sfid-20141127_112140_121468_F37E5F3F)
> +++ b/net/wireless/nl80211.c
> @@ -6077,30 +6078,34 @@ static int nl80211_start_sched_scan(struct sk_buff *skb,
> if (rdev->sched_scan_req)
> return -EINPROGRESS;
>
> - rdev->sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
> - info->attrs);
> - err = PTR_ERR_OR_ZERO(rdev->sched_scan_req);
> + sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
> + info->attrs);
> +
> + err = PTR_ERR_OR_ZERO(sched_scan_req);
> if (err)
> goto out_err;
>
> - err = rdev_sched_scan_start(rdev, dev, rdev->sched_scan_req);
> + rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
> +
> + err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
> if (err)
> goto out_free;
>
> - rdev->sched_scan_req->dev = dev;
> - rdev->sched_scan_req->wiphy = &rdev->wiphy;
> -
> if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
> - rdev->sched_scan_req->owner_nlportid = info->snd_portid;
> + rtnl_dereference(rdev->sched_scan_req)->owner_nlportid =
> + info->snd_portid;
> +
> + rtnl_dereference(rdev->sched_scan_req)->dev = dev;
> + rtnl_dereference(rdev->sched_scan_req)->wiphy = &rdev->wiphy;
This is still all wrong - you need to fully build the local variable and
then assign it after everything is done.
You can *probably* assign it only after calling the driver, in which
case you don't even need to kfree_rcu() below if it was never assigned
in failure cases.
> out_free:
> - kfree(rdev->sched_scan_req);
> + kfree_rcu(sched_scan_req, rcu_head);
> + rcu_assign_pointer(rdev->sched_scan_req, NULL);
use RCU_INIT_POINTER() for NULL values
> out_err:
> - rdev->sched_scan_req = NULL;
Also why did that move into a different label?
> void cfg80211_sched_scan_results(struct wiphy *wiphy)
> {
> + struct cfg80211_sched_scan_request *sched_scan_req;
> +
> trace_cfg80211_sched_scan_results(wiphy);
> /* ignore if we're not scanning */
> - if (wiphy_to_rdev(wiphy)->sched_scan_req)
> +
> + rcu_read_lock();
> + sched_scan_req = rcu_dereference(wiphy_to_rdev(wiphy)->sched_scan_req);
> + rcu_read_unlock();
Umm. No no no. You probably don't want anything but rcu_access_pointer()
here, or do the rcu_read_lock() around all the users ...
> - kfree(rdev->sched_scan_req);
> - rdev->sched_scan_req = NULL;
> + kfree_rcu(sched_scan_req, rcu_head);
> +
> + rcu_assign_pointer(rdev->sched_scan_req, NULL);
You really need to do that the other way around...
Maybe you can find somebody else who has experience with RCU and is
willing to review your patches first? :)
s
Also - this patch really should come *first* in the series. Don't break
the code and fix it in the next patch, do it right once.
johanne
prev parent reply other threads:[~2014-11-28 12:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-27 10:21 [PATCH v8 0/2] Stop scheduled scan if netlink client disappears Jukka Rissanen
2014-11-27 10:21 ` [PATCH v8 1/2] nl80211: " Jukka Rissanen
2014-11-27 10:21 ` [PATCH v8 2/2] nl80211: Convert sched_scan_req pointer to RCU pointer Jukka Rissanen
2014-11-28 12:34 ` Johannes Berg [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1417178052.27562.2.camel@sipsolutions.net \
--to=johannes@sipsolutions.net \
--cc=jukka.rissanen@linux.intel.com \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.