Remove NULL check before kfree
cover Remove NULL check before kfree
These patches remove null check before kfree using the Coccinelle script-
// <smpl>
@@ expression E; @@
- if (E != NULL) { kfree(E); }
+ kfree(E);
@@ expression E; @@
- if (E != NULL) { kfree(E); E = NULL; }
+ kfree(E);
+ E = NULL;
// </smpl>smpl>
Shraddha Barke (3):
Staging: lustre: osc: Remove null check before kfree
Staging: wilc1000: wilc_wfi_cfgoperations: Remove NULL check before
kfree
Staging: wilc1000: linux_wlan: Remove NULL check before kfree
drivers/staging/lustre/lustre/osc/osc_request.c | 4 +- drivers/staging/wilc1000/linux_wlan.c | 6 +- drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 78 ++++++++--------------- 3 files changed, 28 insertions(+), 60 deletions(-)
Signature · 1 line
2.1.4
PATCH 1/3 Staging: lustre: osc: Remove null check before kfree
kfree on NULL pointer is a no-op.
The semantic patch used to find such an instance where NULL check is present before kfree-
// <smpl>
@@ expression E; @@
- if (E != NULL) { kfree(E); }
+ kfree(E);
@@ expression E; @@
- if (E != NULL) { kfree(E); E = NULL; }
+ kfree(E);
+ E = NULL;
// </smpl>smpl>
--- drivers/staging/lustre/lustre/osc/osc_request.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/lustre/lustre/osc/osc_request.c +1 -3
@@ -1998,9 +1998,7 @@ out:if (mem_tight !=0 )cfs_memory_pressure_restore (mpflag); -if (crattr !=NULL ) { -kfree (crattr); - } +kfree (crattr);if (rc !=0 ) {LASSERT (req ==NULL );
Signature · 1 line
2.1.4
PATCH 2/3 Staging: wilc1000: wilc_wfi_cfgoperations: Remove NULL check before kfree
In reply to Shraddha Barkekfree on NULL pointer is a no-op.
The semantic patch used-
// <smpl>
@@ expression E; @@
- if (E != NULL) { kfree(E); }
+ kfree(E);
@@ expression E; @@
- if (E != NULL) { kfree(E); E = NULL; }
+ kfree(E);
+ E = NULL;
// </smpl>smpl>
--- drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 78 ++++++++--------------- 1 file changed, 25 insertions(+), 53 deletions(-)
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +25 -53
@@ -234,10 +234,8 @@ static void remove_network_from_shadow(unsigned long arg)if (time_after (now, astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan + (unsigned long )(SCAN_RESULT_EXPIRE ))) {PRINT_D (CFG80211_DBG ,"Network expired in ScanShadow: %s\n" , astrLastScannedNtwrksShadow[i].au8ssid); -if (astrLastScannedNtwrksShadow[i].pu8IEs !=NULL ) { -kfree (astrLastScannedNtwrksShadow[i].pu8IEs); - astrLastScannedNtwrksShadow[i].pu8IEs =NULL ; - } +kfree (astrLastScannedNtwrksShadow[i].pu8IEs); + astrLastScannedNtwrksShadow[i].pu8IEs =NULL ;host_int_freeJoinParams (astrLastScannedNtwrksShadow[i].pJoinParams);
@@ -1172,15 +1170,13 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, KeyLen = params->key_len -16 ; }/* if there has been previous allocation for the same index through its key, free that memory and allocate again*/ -if (priv->wilc_gtk[key_index]->key) -kfree (priv->wilc_gtk[key_index]->key); +kfree (priv->wilc_gtk[key_index]->key); priv->wilc_gtk[key_index]->key =kmalloc (params->key_len,GFP_KERNEL );memcpy (priv->wilc_gtk[key_index]->key, params->key, params->key_len);/* if there has been previous allocation for the same index through its seq, free that memory and allocate again*/ -if (priv->wilc_gtk[key_index]->seq) -kfree (priv->wilc_gtk[key_index]->seq); +kfree (priv->wilc_gtk[key_index]->seq);if ((params->seq_len) >0 ) { priv->wilc_gtk[key_index]->seq =kmalloc (params->seq_len,GFP_KERNEL );
@@ -1218,13 +1214,11 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, KeyLen = params->key_len -16 ; } -if (priv->wilc_ptk[key_index]->key) -kfree (priv->wilc_ptk[key_index]->key); +kfree (priv->wilc_ptk[key_index]->key); priv->wilc_ptk[key_index]->key =kmalloc (params->key_len,GFP_KERNEL ); -if (priv->wilc_ptk[key_index]->seq) -kfree (priv->wilc_ptk[key_index]->seq); +kfree (priv->wilc_ptk[key_index]->seq);if ((params->seq_len) >0 ) priv->wilc_ptk[key_index]->seq =kmalloc (params->seq_len,GFP_KERNEL );
@@ -1371,25 +1365,17 @@ static int del_key(struct wiphy *wiphy, struct net_device *netdev, g_wep_keys_saved = false;/*Delete saved WEP keys params, if any*/ -if (g_key_wep_params.key !=NULL ) { -kfree (g_key_wep_params.key); - g_key_wep_params.key =NULL ; - } +kfree (g_key_wep_params.key); + g_key_wep_params.key =NULL ;/*freeing memory allocated by "wilc_gtk" and "wilc_ptk" in "WILC_WIFI_ADD_KEY"*/ if ((priv->wilc_gtk[key_index]) !=NULL ) { -if (priv->wilc_gtk[key_index]->key !=NULL ) { - -kfree (priv->wilc_gtk[key_index]->key); - priv->wilc_gtk[key_index]->key =NULL ; - } -if (priv->wilc_gtk[key_index]->seq) { - -kfree (priv->wilc_gtk[key_index]->seq); - priv->wilc_gtk[key_index]->seq =NULL ; - } +kfree (priv->wilc_gtk[key_index]->key); + priv->wilc_gtk[key_index]->key =NULL ; +kfree (priv->wilc_gtk[key_index]->seq); + priv->wilc_gtk[key_index]->seq =NULL ;kfree (priv->wilc_gtk[key_index]); priv->wilc_gtk[key_index] =NULL ;
@@ -1398,38 +1384,24 @@ static int del_key(struct wiphy *wiphy, struct net_device *netdev,if ((priv->wilc_ptk[key_index]) !=NULL ) { -if (priv->wilc_ptk[key_index]->key) { - -kfree (priv->wilc_ptk[key_index]->key); - priv->wilc_ptk[key_index]->key =NULL ; - } -if (priv->wilc_ptk[key_index]->seq) { - -kfree (priv->wilc_ptk[key_index]->seq); - priv->wilc_ptk[key_index]->seq =NULL ; - } +kfree (priv->wilc_ptk[key_index]->key); + priv->wilc_ptk[key_index]->key =NULL ; +kfree (priv->wilc_ptk[key_index]->seq); + priv->wilc_ptk[key_index]->seq =NULL ;kfree (priv->wilc_ptk[key_index]); priv->wilc_ptk[key_index] =NULL ; }/*Delete saved PTK and GTK keys params, if any*/ -if (g_key_ptk_params.key !=NULL ) { -kfree (g_key_ptk_params.key); - g_key_ptk_params.key =NULL ; - } -if (g_key_ptk_params.seq !=NULL ) { -kfree (g_key_ptk_params.seq); - g_key_ptk_params.seq =NULL ; - } - -if (g_key_gtk_params.key !=NULL ) { -kfree (g_key_gtk_params.key); - g_key_gtk_params.key =NULL ; - } -if (g_key_gtk_params.seq !=NULL ) { -kfree (g_key_gtk_params.seq); - g_key_gtk_params.seq =NULL ; - } +kfree (g_key_ptk_params.key); + g_key_ptk_params.key =NULL ; +kfree (g_key_ptk_params.seq); + g_key_ptk_params.seq =NULL ; + +kfree (g_key_gtk_params.key); + g_key_gtk_params.key =NULL ; +kfree (g_key_gtk_params.seq); + g_key_gtk_params.seq =NULL ;/*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/ Set_machw_change_vir_if (false);
Signature · 1 line
2.1.4
PATCH 3/3 Staging: wilc1000: linux_wlan: Remove NULL check before kfree
In reply to Shraddha Barkekfree on NULL pointer is a no-op.
The semantic patch used -
// <smpl>
@@ expression E; @@
- if (E != NULL) { kfree(E); }
+ kfree(E);
@@ expression E; @@
- if (E != NULL) { kfree(E); E = NULL; }
+ kfree(E);
+ E = NULL;
// </smpl>smpl>
--- drivers/staging/wilc1000/linux_wlan.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/staging/wilc1000/linux_wlan.c +2 -4
@@ -1887,10 +1887,8 @@ static void __exit exit_wilc_driver(void)sdio_unregister_driver (&wilc_bus);#endif -if (g_linux_wlan !=NULL ) { -kfree (g_linux_wlan); - g_linux_wlan =NULL ; - } +kfree (g_linux_wlan); + g_linux_wlan =NULL ;printk ("Module_exit Done.\n" );#if defined(WILC_DEBUGFS )
Signature · 1 line
2.1.4
Re: [Outreachy kernel] [PATCH 3/3] Staging: wilc1000: linux_wlan: Remove NULL check before kfree
Quoted 4 lines · Shraddha Barke
kfree on NULL pointer is a no-op.
The semantic patch used -
Quoted 9 lines
// <smpl>
@@ expression E; @@
- if (E != NULL) { kfree(E); }
+ kfree(E);
@@ expression E; @@
- if (E != NULL) { kfree(E); E = NULL; }
+ kfree(E);
+ E = NULL;
// </smpl>smpl>
Nice :)
Quoted 33 lines
Signed-off-by Shraddha Barke <[email protected]>--- drivers/staging/wilc1000/linux_wlan.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/staging/wilc1000/linux_wlan.c +2
-5@@ -1887,10 +1887,8 @@ static void __exit exit_wilc_driver(void)sdio_unregister_driver (&wilc_bus);#endif -if (g_linux_wlan !=NULL ) { -kfree (g_linux_wlan); - g_linux_wlan =NULL ; - } +kfree (g_linux_wlan); + g_linux_wlan =NULL ;printk ("Module_exit Done.\n" );#if defined(WILC_DEBUGFS ) --2.1.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1444663160-26795-4-git-send-email-shraddha.6596%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Re: [Outreachy kernel] [PATCH 2/3] Staging: wilc1000: wilc_wfi_cfgoperations: Remove NULL check before kfree
In reply to Shraddha BarkeQuoted 24 lines · Shraddha Barke
kfree on NULL pointer is a no-op.
The semantic patch used-
// <smpl>
@@ expression E; @@
- if (E != NULL) { kfree(E); }
+ kfree(E);
@@ expression E; @@
- if (E != NULL) { kfree(E); E = NULL; }
+ kfree(E);
+ E = NULL;
// </smpl>smpl>Signed-off-by Shraddha Barke <[email protected]>--- drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 78 ++++++++--------------- 1 file changed, 25 insertions(+), 53 deletions(-)drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +0
-0
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c static void remove_network_from_shadow(unsigned long arg) · line 238
Quoted 9 lines
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +2
-4@@ -234,10 +234,8 @@ static void remove_network_from_shadow(unsigned long arg)if (time_after (now, astrLastScannedNtwrksShadow[i].u32TimeRcvdInScan + (unsigned long )(SCAN_RESULT_EXPIRE ))) {PRINT_D (CFG80211_DBG ,"Network expired in ScanShadow: %s\n" , astrLastScannedNtwrksShadow[i].au8ssid); -if (astrLastScannedNtwrksShadow[i].pu8IEs !=NULL ) { -kfree (astrLastScannedNtwrksShadow[i].pu8IEs); - astrLastScannedNtwrksShadow[i].pu8IEs =NULL ; - } +kfree (astrLastScannedNtwrksShadow[i].pu8IEs); + astrLastScannedNtwrksShadow[i].pu8IEs =NULL ;
iWonderWhatIsTheLongestVariableNameInTheLinuxKernel :)
julia
Quoted 131 lines
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c +23
-50host_int_freeJoinParams (astrLastScannedNtwrksShadow[i].pJoinParams);@@ -1172,15 +1170,13 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, KeyLen = params->key_len -16 ; }/* if there has been previous allocation for the same index through its key, free that memory and allocate again*/ -if (priv->wilc_gtk[key_index]->key) -kfree (priv->wilc_gtk[key_index]->key); +kfree (priv->wilc_gtk[key_index]->key); priv->wilc_gtk[key_index]->key =kmalloc (params->key_len,GFP_KERNEL );memcpy (priv->wilc_gtk[key_index]->key, params->key, params->key_len);/* if there has been previous allocation for the same index through its seq, free that memory and allocate again*/ -if (priv->wilc_gtk[key_index]->seq) -kfree (priv->wilc_gtk[key_index]->seq); +kfree (priv->wilc_gtk[key_index]->seq);if ((params->seq_len) >0 ) { priv->wilc_gtk[key_index]->seq =kmalloc (params->seq_len,GFP_KERNEL );@@ -1218,13 +1214,11 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index, KeyLen = params->key_len -16 ; } -if (priv->wilc_ptk[key_index]->key) -kfree (priv->wilc_ptk[key_index]->key); +kfree (priv->wilc_ptk[key_index]->key); priv->wilc_ptk[key_index]->key =kmalloc (params->key_len,GFP_KERNEL ); -if (priv->wilc_ptk[key_index]->seq) -kfree (priv->wilc_ptk[key_index]->seq); +kfree (priv->wilc_ptk[key_index]->seq);if ((params->seq_len) >0 ) priv->wilc_ptk[key_index]->seq =kmalloc (params->seq_len,GFP_KERNEL );@@ -1371,25 +1365,17 @@ static int del_key(struct wiphy *wiphy, struct net_device *netdev, g_wep_keys_saved = false;/*Delete saved WEP keys params, if any*/ -if (g_key_wep_params.key !=NULL ) { -kfree (g_key_wep_params.key); - g_key_wep_params.key =NULL ; - } +kfree (g_key_wep_params.key); + g_key_wep_params.key =NULL ;/*freeing memory allocated by "wilc_gtk" and "wilc_ptk" in "WILC_WIFI_ADD_KEY"*/ if ((priv->wilc_gtk[key_index]) !=NULL ) { -if (priv->wilc_gtk[key_index]->key !=NULL ) { - -kfree (priv->wilc_gtk[key_index]->key); - priv->wilc_gtk[key_index]->key =NULL ; - } -if (priv->wilc_gtk[key_index]->seq) { - -kfree (priv->wilc_gtk[key_index]->seq); - priv->wilc_gtk[key_index]->seq =NULL ; - } +kfree (priv->wilc_gtk[key_index]->key); + priv->wilc_gtk[key_index]->key =NULL ; +kfree (priv->wilc_gtk[key_index]->seq); + priv->wilc_gtk[key_index]->seq =NULL ;kfree (priv->wilc_gtk[key_index]); priv->wilc_gtk[key_index] =NULL ;@@ -1398,38 +1384,24 @@ static int del_key(struct wiphy *wiphy, struct net_device *netdev,if ((priv->wilc_ptk[key_index]) !=NULL ) { -if (priv->wilc_ptk[key_index]->key) { - -kfree (priv->wilc_ptk[key_index]->key); - priv->wilc_ptk[key_index]->key =NULL ; - } -if (priv->wilc_ptk[key_index]->seq) { - -kfree (priv->wilc_ptk[key_index]->seq); - priv->wilc_ptk[key_index]->seq =NULL ; - } +kfree (priv->wilc_ptk[key_index]->key); + priv->wilc_ptk[key_index]->key =NULL ; +kfree (priv->wilc_ptk[key_index]->seq); + priv->wilc_ptk[key_index]->seq =NULL ;kfree (priv->wilc_ptk[key_index]); priv->wilc_ptk[key_index] =NULL ; }/*Delete saved PTK and GTK keys params, if any*/ -if (g_key_ptk_params.key !=NULL ) { -kfree (g_key_ptk_params.key); - g_key_ptk_params.key =NULL ; - } -if (g_key_ptk_params.seq !=NULL ) { -kfree (g_key_ptk_params.seq); - g_key_ptk_params.seq =NULL ; - } - -if (g_key_gtk_params.key !=NULL ) { -kfree (g_key_gtk_params.key); - g_key_gtk_params.key =NULL ; - } -if (g_key_gtk_params.seq !=NULL ) { -kfree (g_key_gtk_params.seq); - g_key_gtk_params.seq =NULL ; - } +kfree (g_key_ptk_params.key); + g_key_ptk_params.key =NULL ; +kfree (g_key_ptk_params.seq); + g_key_ptk_params.seq =NULL ; + +kfree (g_key_gtk_params.key); + g_key_gtk_params.key =NULL ; +kfree (g_key_gtk_params.seq); + g_key_gtk_params.seq =NULL ;/*Reset WILC_CHANGING_VIR_IF register to allow adding futrue keys to CE H/W*/ Set_machw_change_vir_if (false); --2.1.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1444663160-26795-3-git-send-email-shraddha.6596%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Re: [Outreachy kernel] [PATCH 1/3] Staging: lustre: osc: Remove null check before kfree
In reply to Shraddha BarkeQuoted 14 lines · Shraddha Barke
kfree on NULL pointer is a no-op.
The semantic patch used to find such an instance where NULL check is present before kfree-// <smpl>
@@ expression E; @@
- if (E != NULL) { kfree(E); }
+ kfree(E);
@@ expression E; @@
- if (E != NULL) { kfree(E); E = NULL; }
+ kfree(E);
+ E = NULL;
// </smpl>smpl>
Quoted 1 line
Signed-off-by Shraddha Barke <[email protected]>
Quoted 23 lines
--- drivers/staging/lustre/lustre/osc/osc_request.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/staging/lustre/lustre/osc/osc_request.c +1
-4@@ -1998,9 +1998,7 @@ out:if (mem_tight !=0 )cfs_memory_pressure_restore (mpflag); -if (crattr !=NULL ) { -kfree (crattr); - } +kfree (crattr);if (rc !=0 ) {LASSERT (req ==NULL ); --2.1.4
--