[Cocci] [PATCH resent] staging: rtl8188eu: Deletion of unnecessary checks before three function calls

Julia Lawall julia.lawall at lip6.fr
Fri Oct 31 19:01:06 CET 2014


On Fri, 31 Oct 2014, SF Markus Elfring wrote:

> The functions kfree(), rtw_free_netdev() and vfree() test whether their
> argument is NULL and then return immediately. Thus the test around the call
> is not needed.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring at users.sourceforge.net>
> ---
>  drivers/staging/rtl8188eu/core/rtw_efuse.c   | 3 +--
>  drivers/staging/rtl8188eu/core/rtw_mlme.c    | 3 +--
>  drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 3 +--
>  drivers/staging/rtl8188eu/core/rtw_xmit.c    | 6 ++----
>  drivers/staging/rtl8188eu/os_dep/usb_intf.c  | 5 ++---
>  5 files changed, 7 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> index 7006088..77f7552 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_efuse.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_efuse.c
> @@ -212,8 +212,7 @@ efuse_phymap_to_logical(u8 *phymap, u16 _offset, u16
> _size_byte, u8  *pbuf)
>  exit:
>  	kfree(efuseTbl);
>
> -	if (eFuseWord)
> -		kfree(eFuseWord);
> +	kfree(eFuseWord);

I think that this code has been updated already.  It would be better to
add labels so that kfree is only executed when needed.

julia

>  }
>
>  static void efuse_read_phymap_from_txpktbuf(
> diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c
> b/drivers/staging/rtl8188eu/core/rtw_mlme.c
> index 149c271..df54350 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
> @@ -122,8 +122,7 @@ void rtw_free_mlme_priv(struct mlme_priv *pmlmepriv)
>  	rtw_free_mlme_priv_ie_data(pmlmepriv);
>
>  	if (pmlmepriv) {
> -		if (pmlmepriv->free_bss_buf)
> -			vfree(pmlmepriv->free_bss_buf);
> +		vfree(pmlmepriv->free_bss_buf);
>  	}
>  }
>
> diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> index e1dc8fa..af1de9c 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> @@ -201,8 +201,7 @@ u32	_rtw_free_sta_priv(struct	sta_priv *pstapriv)
>
>  		rtw_mfree_sta_priv_lock(pstapriv);
>
> -		if (pstapriv->pallocated_stainfo_buf)
> -			vfree(pstapriv->pallocated_stainfo_buf);
> +		vfree(pstapriv->pallocated_stainfo_buf);
>  	}
>
>  	return _SUCCESS;
> diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c
> b/drivers/staging/rtl8188eu/core/rtw_xmit.c
> index 639ace0..011c9cf 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
> @@ -246,11 +246,9 @@ void _rtw_free_xmit_priv (struct xmit_priv *pxmitpriv)
>  		pxmitbuf++;
>  	}
>
> -	if (pxmitpriv->pallocated_frame_buf)
> -		vfree(pxmitpriv->pallocated_frame_buf);
> +	vfree(pxmitpriv->pallocated_frame_buf);
>
> -	if (pxmitpriv->pallocated_xmitbuf)
> -		vfree(pxmitpriv->pallocated_xmitbuf);
> +	vfree(pxmitpriv->pallocated_xmitbuf);
>
>  	/*  free xmit extension buff */
>  	pxmitbuf = (struct xmit_buf *)pxmitpriv->pxmit_extbuf;
> diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> index 407a318..cdb70e4 100644
> --- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> +++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
> @@ -456,7 +456,7 @@ free_adapter:
>  	if (status != _SUCCESS) {
>  		if (pnetdev)
>  			rtw_free_netdev(pnetdev);
> -		else if (padapter)
> +		else
>  			vfree(padapter);
>  		padapter = NULL;
>  	}
> @@ -487,8 +487,7 @@ static void rtw_usb_if1_deinit(struct adapter *if1)
>  	DBG_88E("+r871xu_dev_remove, hw_init_completed=%d\n",
>  		if1->hw_init_completed);
>  	rtw_free_drv_sw(if1);
> -	if (pnetdev)
> -		rtw_free_netdev(pnetdev);
> +	rtw_free_netdev(pnetdev);
>  }
>
>  static int rtw_drv_init(struct usb_interface *pusb_intf, const struct
> usb_device_id *pdid)
> --
> 2.1.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>


More information about the Cocci mailing list