Remove unnecessary variable
cover Remove unnecessary variable
This patchset detects and removes unnecessary return variables using coccinelle.
Cristina Opriceana (3):
Staging: rtl8192u: Remove unnecessary variable
Staging: rtl8192e: Remove unnecessary variables
Staging: rtl8712: Remove unnecessary variables
drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c | 3 +-- drivers/staging/rtl8192e/rtl8192e/rtl_core.c | 3 +-- drivers/staging/rtl8192e/rtl819x_HTProc.c | 4 +--- drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c | 11 +++-------- drivers/staging/rtl8712/os_intfs.c | 6 ++---- drivers/staging/rtl8712/rtl871x_recv.c | 3 +-- 6 files changed, 9 insertions(+), 21 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/3 Staging: rtl8192u: Remove unnecessary variable
This patch detects the cases in which a variable is not modified through the code and it is used as a return value. The variable is detected and removed by coccinelle using the following semantic patch:
@@ type T; expression expr; identifier r; constant c; @@
-T r = expr;
... when != r
when strict
-return r;
+return expr;
--- drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/staging/rtl8192u/ieee80211/rtl819x_HTProc.c +3 -8
@@ -471,12 +471,10 @@ static bool HTIOTActIsDisableMCS15(struct ieee80211_device *ieee)static bool HTIOTActIsDisableMCSTwoSpatialStream (struct ieee80211_device *ieee,u8 *PeerMacAddr) { -bool retValue = false; -#ifdef TODO // Apply for 819u only #endif -return retValue; +return false; }/********************************************************************************************************************
@@ -488,11 +486,8 @@ static bool HTIOTActIsDisableMCSTwoSpatialStream(struct ieee80211_device *ieee,* *****************************************************************************************************************/ static u8 HTIOTActIsDisableEDCATurbo (struct ieee80211_device *ieee,u8 *PeerMacAddr) -{ -u8 retValue = false;// default enable EDCA Turbo mode. -// Set specific EDCA parameter for different AP in DM handler. - -return retValue; +{/* default enable EDCA Turbo mode. */ +return false; }/********************************************************************************************************************
Signature · 1 line
1.9.1
PATCH 2/3 Staging: rtl8192e: Remove unnecessary variables
In reply to Cristina OpriceanaThis patch removes unnecessary intermediary variables in return lines and uses actual values.
Found by coccinelle using this semantic patch:
@@ type T; expression expr; identifier r; @@
-T r = expr;
... when != r
when strict
-return r;
+return expr;
--- drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c | 3 +-- drivers/staging/rtl8192e/rtl8192e/rtl_core.c | 3 +-- drivers/staging/rtl8192e/rtl819x_HTProc.c | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-)
drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c +1 -2
@@ -36,7 +36,6 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address, u32 buffer_len) {struct r8192_priv *priv =rtllib_priv (dev); -bool rt_status = true;u16 frag_threshold;u16 frag_length, frag_offset =0 ;int i;
@@ -99,7 +98,7 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,write_nic_byte (dev, TPPoll, TPPoll_CQ); -return rt_status; +return true; }static bool CPUcheck_maincodeok_turnonCPU (struct net_device *dev)
drivers/staging/rtl8192e/rtl8192e/rtl_core.c +1 -2
@@ -3059,7 +3059,6 @@ bool NicIFEnableNIC(struct net_device *dev) }bool NicIFDisableNIC (struct net_device *dev) { -bool status = true;struct r8192_priv *priv =rtllib_priv (dev);u8 tmp_state =0 ;
@@ -3074,7 +3073,7 @@ bool NicIFDisableNIC(struct net_device *dev) priv->ops->stop_adapter (dev, false);RT_TRACE (COMP_PS ,"<=========%s()\n" , __func__); -return status; +return true; }static int __init rtl8192_pci_module_init (void )
drivers/staging/rtl8192e/rtl819x_HTProc.c +1 -3
@@ -386,9 +386,7 @@ static u8 HTIOTActIsDisableMCS14(struct rtllib_device *ieee, u8 *PeerMacAddr)static bool HTIOTActIsDisableMCS15 (struct rtllib_device *ieee) { -bool retValue = false; - -return retValue; +return false; }static bool HTIOTActIsDisableMCSTwoSpatialStream (struct rtllib_device *ieee)
Signature · 1 line
1.9.1
PATCH 3/3 Staging: rtl8712: Remove unnecessary variables
In reply to Cristina OpriceanaThis patch removes unnecessary intermediary variables used in return lines and replaces them with the actual values.
Found by coccinelle using the following semantic patch:
@@ type T; expression expr; identifier r; @@
-T r = expr;
... when != r
when strict
-return r;
+return expr;
--- drivers/staging/rtl8712/os_intfs.c | 6 ++---- drivers/staging/rtl8712/rtl871x_recv.c | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-)
drivers/staging/rtl8712/os_intfs.c +2 -4
@@ -128,7 +128,6 @@ static int netdev_close(struct net_device *pnetdev);static uint loadparam (struct _adapter *padapter,struct net_device *pnetdev) { -uint status = _SUCCESS;struct registry_priv *registry_par = &padapter->registrypriv; registry_par->chip_version = (u8 )chip_version;
@@ -172,7 +171,7 @@ static uint loadparam(struct _adapter *padapter, struct net_device *pnetdev) registry_par->low_power = (u8 )low_power; registry_par->wifi_test = (u8 ) wifi_test; r8712_initmac = initmac; -return status; +return _SUCCESS; }static int r871x_net_set_mac_address (struct net_device *pnetdev,void *p)
@@ -274,7 +273,6 @@ void r8712_stop_drv_timers(struct _adapter *padapter)static u8 init_default_value (struct _adapter *padapter) { -u8 ret = _SUCCESS;struct registry_priv *pregistrypriv = &padapter->registrypriv;struct xmit_priv *pxmitpriv = &padapter->xmitpriv;struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -307,7 +305,7 @@ static u8 init_default_value(struct _adapter *padapter)r8712_init_registrypriv_dev_network (padapter);r8712_update_registrypriv_dev_network (padapter);/*misc.*/ -return ret; +return _SUCCESS; }u8 r8712_init_drv_sw (struct _adapter *padapter)
drivers/staging/rtl8712/rtl871x_recv.c +1 -2
@@ -221,7 +221,6 @@ union recv_frame *r8712_decryptor(struct _adapter *padapter, {struct rx_pkt_attrib *prxattrib = &precv_frame->u.hdr.attrib;struct security_priv *psecuritypriv = &padapter->securitypriv; -union recv_frame *return_packet = precv_frame;if ((prxattrib->encrypt >0 ) && ((prxattrib->bdecrypted ==0 ) || (psecuritypriv->sw_decrypt == true))) {
@@ -242,7 +241,7 @@ union recv_frame *r8712_decryptor(struct _adapter *padapter, } }else if (prxattrib->bdecrypted ==1 ) psecuritypriv->hw_decrypted = true; -return return_packet; +return precv_frame; }/*###set the security information in the recv_frame */ union recv_frame *r8712_portctrl(struct _adapter *adapter,
Signature · 1 line
1.9.1
Re: [Outreachy kernel] [PATCH 3/3] Staging: rtl8712: Remove unnecessary variables
Quoted 30 lines · On Thursday 12 March 2015 04:23:42 Cristina Opriceana wrote:
drivers/staging/rtl8712/os_intfs.c +1
-3@@ -128,7 +128,6 @@ static int netdev_close(struct net_device *pnetdev);static uint loadparam (struct _adapter *padapter,struct net_device *pnetdev) { -uint status = _SUCCESS;struct registry_priv *registry_par = &padapter->registrypriv; registry_par->chip_version = (u8 )chip_version;@@ -172,7 +171,7 @@ static uint loadparam(struct _adapter *padapter, struct net_device *pnetdev) registry_par->low_power = (u8 )low_power; registry_par->wifi_test = (u8 ) wifi_test; r8712_initmac = initmac; -return status; +return _SUCCESS; }static int r871x_net_set_mac_address (struct net_device *pnetdev,void *p)@@ -274,7 +273,6 @@ void r8712_stop_drv_timers(struct _adapter *padapter)static u8 init_default_value (struct _adapter *padapter) { -u8 ret = _SUCCESS;struct registry_priv *pregistrypriv = &padapter->registrypriv;struct xmit_priv *pxmitpriv = &padapter->xmitpriv;struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
drivers/staging/rtl8712/os_intfs.c static u8 init_default_value(struct _adapter *padapter) · line 309
Quoted 6 lines
drivers/staging/rtl8712/os_intfs.c +1
-1@@ -307,7 +305,7 @@ static u8 init_default_value(struct _adapter *padapter)r8712_init_registrypriv_dev_network (padapter);r8712_update_registrypriv_dev_network (padapter);/*misc.*/ -return ret; +return _SUCCESS; }
When a local function unconditionally returns success, it's often a good idea to change the prototype so it returns void.
That would also improve it a bit by avoiding the non-standard _SUCCESS return code. The kernel convention normally is to return '0' for success and a negative error numer (e.g. -ENXIO) in case of an error, with a type of 'int'. Changing all the return codes in this driver would of course be a separate patch.
Arnd
Re: [Outreachy kernel] [PATCH 3/3] Staging: rtl8712: Remove unnecessary variables
Quoted 9 lines
When a local function unconditionally returns success, it's often a good idea to change the prototype so it returns void.
That would also improve it a bit by avoiding the non-standard
_SUCCESSreturn code. The kernel convention normally is to return '0' for success and a negative error numer (e.g.-ENXIO) in case of an error, with a type of 'int'. Changing all the return codes in this driver would of course be a separate patch.
Indeed, _SUCCESS doesn't look well there. I'll check this out.
Thanks,
Cristina