netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rndis_wlan: move the dereference below the NULL test
@ 2012-09-10  4:46 Wei Yongjun
  2012-09-10  6:29 ` Jussi Kivilinna
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Yongjun @ 2012-09-10  4:46 UTC (permalink / raw)
  To: jussi.kivilinna, linville; +Cc: yongjun_wei, linux-wireless, netdev

From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

The dereference should be moved below the NULL test.

spatch with a semantic match is used to found this.
(http://coccinelle.lip6.fr/)

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 drivers/net/wireless/rndis_wlan.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
index 7a4ae9e..de2a673 100644
--- a/drivers/net/wireless/rndis_wlan.c
+++ b/drivers/net/wireless/rndis_wlan.c
@@ -1946,12 +1946,19 @@ static int rndis_get_tx_power(struct wiphy *wiphy, int *dbm)
 static int rndis_scan(struct wiphy *wiphy,
 			struct cfg80211_scan_request *request)
 {
-	struct net_device *dev = request->wdev->netdev;
-	struct usbnet *usbdev = netdev_priv(dev);
-	struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
+	struct net_device *dev;
+	struct usbnet *usbdev;
+	struct rndis_wlan_private *priv;
 	int ret;
 	int delay = SCAN_DELAY_JIFFIES;
 
+	if (!request)
+		return -EINVAL;
+
+	dev = request->wdev->netdev;
+	usbdev = netdev_priv(dev);
+	priv = get_rndis_wlan_priv(usbdev);
+
 	netdev_dbg(usbdev->net, "cfg80211.scan\n");
 
 	/* Get current bssid list from device before new scan, as new scan
@@ -1959,9 +1966,6 @@ static int rndis_scan(struct wiphy *wiphy,
 	 */
 	rndis_check_bssid_list(usbdev, NULL, NULL);
 
-	if (!request)
-		return -EINVAL;
-
 	if (priv->scan_request && priv->scan_request != request)
 		return -EBUSY;
 

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

* Re: [PATCH] rndis_wlan: move the dereference below the NULL test
  2012-09-10  4:46 [PATCH] rndis_wlan: move the dereference below the NULL test Wei Yongjun
@ 2012-09-10  6:29 ` Jussi Kivilinna
  0 siblings, 0 replies; 2+ messages in thread
From: Jussi Kivilinna @ 2012-09-10  6:29 UTC (permalink / raw)
  To: Wei Yongjun; +Cc: linville, yongjun_wei, linux-wireless, netdev

Quoting Wei Yongjun <weiyj.lk@gmail.com>:

> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
>
> The dereference should be moved below the NULL test.
>
> spatch with a semantic match is used to found this.
> (http://coccinelle.lip6.fr/)
>
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> ---
>  drivers/net/wireless/rndis_wlan.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/wireless/rndis_wlan.c  
> b/drivers/net/wireless/rndis_wlan.c
> index 7a4ae9e..de2a673 100644
> --- a/drivers/net/wireless/rndis_wlan.c
> +++ b/drivers/net/wireless/rndis_wlan.c
> @@ -1946,12 +1946,19 @@ static int rndis_get_tx_power(struct wiphy  
> *wiphy, int *dbm)
>  static int rndis_scan(struct wiphy *wiphy,
>  			struct cfg80211_scan_request *request)
>  {
> -	struct net_device *dev = request->wdev->netdev;
> -	struct usbnet *usbdev = netdev_priv(dev);
> -	struct rndis_wlan_private *priv = get_rndis_wlan_priv(usbdev);
> +	struct net_device *dev;
> +	struct usbnet *usbdev;
> +	struct rndis_wlan_private *priv;
>  	int ret;
>  	int delay = SCAN_DELAY_JIFFIES;
>
> +	if (!request)
> +		return -EINVAL;
> +
> +	dev = request->wdev->netdev;
> +	usbdev = netdev_priv(dev);
> +	priv = get_rndis_wlan_priv(usbdev);
> +

'request' is actually always valid pointer and the !request check is  
unneeded. Correct fix is to remove the check.

>  	netdev_dbg(usbdev->net, "cfg80211.scan\n");
>
>  	/* Get current bssid list from device before new scan, as new scan
> @@ -1959,9 +1966,6 @@ static int rndis_scan(struct wiphy *wiphy,
>  	 */
>  	rndis_check_bssid_list(usbdev, NULL, NULL);
>
> -	if (!request)
> -		return -EINVAL;
> -

Only this part is needed.

-Jussi

>  	if (priv->scan_request && priv->scan_request != request)
>  		return -EBUSY;
>

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

end of thread, other threads:[~2012-09-10  6:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-10  4:46 [PATCH] rndis_wlan: move the dereference below the NULL test Wei Yongjun
2012-09-10  6:29 ` Jussi Kivilinna

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).