Skip to contentSkip to conversation

staging: rtl8723bs: os_dep: Remove typecast in kfree

PATCH In review Nachammai Karuppiah 2 participants 3 messages Oct 8, 2019 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8723bs: os_dep: Remove typecast in kfree

Remove typecast in the call to kfree as it is not needed. Issue found using the below coccinelle script,

@@
type t1;
expression e;
@@

-kfree((t1 *)e);
+kfree(e);

---
 drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 10 +++++-----
 drivers/staging/rtl8723bs/os_dep/os_intfs.c       |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +5 -5
index 67d56f3..8555f52 100644
@@ -165,7 +165,7 @@ static void rtw_spt_band_free(struct ieee80211_supported_band *spt_band)
 			+ sizeof(struct ieee80211_channel)*RTW_2G_CHANNELS_NUM
 			+ sizeof(struct ieee80211_rate)*RTW_G_RATES_NUM;
 	}
-	kfree((u8 *)spt_band);
+	kfree(spt_band);
 }
 
 static const struct ieee80211_txrx_stypes
@@ -1156,7 +1156,7 @@ static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev,
 	}
 
 addkey_end:
-	kfree((u8 *)param);
+	kfree(param);
 
 	return ret;
 
@@ -2193,7 +2193,7 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
 			ret = -EOPNOTSUPP ;
 		}
 
-		kfree((u8 *)pwep);
+		kfree(pwep);
 
 		if (ret < 0)
 			goto exit;
@@ -2646,7 +2646,7 @@ static int rtw_cfg80211_add_monitor_if (struct adapter *padapter, char *name, st
 
 out:
 	if (ret && mon_wdev) {
-		kfree((u8 *)mon_wdev);
+		kfree(mon_wdev);
 		mon_wdev = NULL;
 	}
 
@@ -3502,7 +3502,7 @@ void rtw_wdev_free(struct wireless_dev *wdev)
 
 	wiphy_free(wdev->wiphy);
 
-	kfree((u8 *)wdev);
+	kfree(wdev);
 }
 
 void rtw_wdev_unregister(struct wireless_dev *wdev)
drivers/staging/rtl8723bs/os_dep/os_intfs.c +1 -1
index ec3a754..5044f73 100644
@@ -1142,7 +1142,7 @@ void rtw_ndev_destructor(struct net_device *ndev)
 	DBG_871X(FUNC_NDEV_FMT "\n", FUNC_NDEV_ARG(ndev));
 
 	if (ndev->ieee80211_ptr)
-		kfree((u8 *)ndev->ieee80211_ptr);
+		kfree(ndev->ieee80211_ptr);
 }
 
 void rtw_dev_unload(struct adapter *padapter)
Signature · 1 line
2.7.4
Acked-by on v1 1/1
#1 lore raw
Quoted 1 line · Nachammai Karuppiah

Remove typecast in the call to kfree as it is not needed.

Review

Quoted 9 lines

Issue found using the below coccinelle script,

@@
type t1;
expression e;
@@

(quoted diff) +1 -1
-kfree((t1 *)e);
+kfree(e);

One might consider that a slight improvement would be to declare expression * e; rather than expression e;, ie to ensure that e is a pointer. But it's a bit of a tradeoff, because if you specify type information, then Coccinelle has to find the type. If it can't find the type, some changes will be overlooked. Still it could be good to try both approaches. If both approaches give the same results, you can be more confident that everything is ok.

On the other hand, it would be pretty odd for an argument of kmalloc not to be of pointer type.

julia

Quoted 76 lines
---
 drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 10 +++++-----
 drivers/staging/rtl8723bs/os_dep/os_intfs.c       |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +5 -5
index 67d56f3..8555f52 100644
@@ -165,7 +165,7 @@ static void rtw_spt_band_free(struct ieee80211_supported_band *spt_band)
 			+ sizeof(struct ieee80211_channel)*RTW_2G_CHANNELS_NUM
 			+ sizeof(struct ieee80211_rate)*RTW_G_RATES_NUM;
 	}
-	kfree((u8 *)spt_band);
+	kfree(spt_band);
 }
 
 static const struct ieee80211_txrx_stypes
@@ -1156,7 +1156,7 @@ static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev,
 	}
 
 addkey_end:
-	kfree((u8 *)param);
+	kfree(param);
 
 	return ret;
 
@@ -2193,7 +2193,7 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
 			ret = -EOPNOTSUPP ;
 		}
 
-		kfree((u8 *)pwep);
+		kfree(pwep);
 
 		if (ret < 0)
 			goto exit;
@@ -2646,7 +2646,7 @@ static int rtw_cfg80211_add_monitor_if (struct adapter *padapter, char *name, st
 
 out:
 	if (ret && mon_wdev) {
-		kfree((u8 *)mon_wdev);
+		kfree(mon_wdev);
 		mon_wdev = NULL;
 	}
 
@@ -3502,7 +3502,7 @@ void rtw_wdev_free(struct wireless_dev *wdev)
 
 	wiphy_free(wdev->wiphy);
 
-	kfree((u8 *)wdev);
+	kfree(wdev);
 }
 
 void rtw_wdev_unregister(struct wireless_dev *wdev)
drivers/staging/rtl8723bs/os_dep/os_intfs.c +1 -2
index ec3a754..5044f73 100644
@@ -1142,7 +1142,7 @@ void rtw_ndev_destructor(struct net_device *ndev)
 	DBG_871X(FUNC_NDEV_FMT "\n", FUNC_NDEV_ARG(ndev));
 
 	if (ndev->ieee80211_ptr)
-		kfree((u8 *)ndev->ieee80211_ptr);
+		kfree(ndev->ieee80211_ptr);
 }
 
 void rtw_dev_unload(struct adapter *padapter)
--

2.7.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 view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1570511353-64646-1-git-send-email-nachukannan%40gmail.com.

#2 lore raw
Quoted 17 lines · Julia Lawall
Quoted 1 line · Nachammai Karuppiah

Remove typecast in the call to kfree as it is not needed.

Quoted 7 lines

Issue found using the below coccinelle script,

@@
type t1;
expression e;
@@

Quoted 11 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-kfree((t1 *)e);
+kfree(e);

One might consider that a slight improvement would be to declare expression * e; rather than expression e;, ie to ensure that e is a pointer. But it's a bit of a tradeoff, because if you specify type information, then Coccinelle has to find the type. If it can't find the type, some changes will be overlooked. Still it could be good to try both approaches. If both approaches give the same results, you can be more confident that everything is ok.

Thanks for the suggestion. I used expression *e for other sub directories in rtl8723bs and it covered all cases once I used the right options (-I and --recursive-includes).
Both scripts gave the same result.

Quoted 3 lines

On the other hand, it would be pretty odd for an argument of kmalloc not to be of pointer type.

Yeah, I assumed and expected the script to only remove the typecast but not to check if the parameter itself was a pointer. Thanks for your insights.

Quoted 83 lines

julia

Quoted 71 lines
---
 drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 10 +++++-----
 drivers/staging/rtl8723bs/os_dep/os_intfs.c       |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c +5 -5
index 67d56f3..8555f52 100644
@@ -165,7 +165,7 @@ static void rtw_spt_band_free(struct ieee80211_supported_band *spt_band)
                      + sizeof(struct ieee80211_channel)*RTW_2G_CHANNELS_NUM
                      + sizeof(struct ieee80211_rate)*RTW_G_RATES_NUM;
      }
-     kfree((u8 *)spt_band);
+     kfree(spt_band);
 }
 
 static const struct ieee80211_txrx_stypes
@@ -1156,7 +1156,7 @@ static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev,
      }
 
 addkey_end:
-     kfree((u8 *)param);
+     kfree(param);
 
      return ret;
 
@@ -2193,7 +2193,7 @@ static int cfg80211_rtw_connect(struct wiphy *wiphy, struct net_device *ndev,
                      ret = -EOPNOTSUPP ;
              }
 
-             kfree((u8 *)pwep);
+             kfree(pwep);
 
              if (ret < 0)
                      goto exit;
@@ -2646,7 +2646,7 @@ static int rtw_cfg80211_add_monitor_if (struct adapter *padapter, char *name, st
 
 out:
      if (ret && mon_wdev) {
-             kfree((u8 *)mon_wdev);
+             kfree(mon_wdev);
              mon_wdev = NULL;
      }
 
@@ -3502,7 +3502,7 @@ void rtw_wdev_free(struct wireless_dev *wdev)
 
      wiphy_free(wdev->wiphy);
 
-     kfree((u8 *)wdev);
+     kfree(wdev);
 }
 
 void rtw_wdev_unregister(struct wireless_dev *wdev)
drivers/staging/rtl8723bs/os_dep/os_intfs.c +1 -2
index ec3a754..5044f73 100644
@@ -1142,7 +1142,7 @@ void rtw_ndev_destructor(struct net_device *ndev)
      DBG_871X(FUNC_NDEV_FMT "\n", FUNC_NDEV_ARG(ndev));
 
      if (ndev->ieee80211_ptr)
-             kfree((u8 *)ndev->ieee80211_ptr);
+             kfree(ndev->ieee80211_ptr);
 }
 
 void rtw_dev_unload(struct adapter *padapter)
--

2.7.4

Quoted 5 lines

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1570511353-64646-1-git-send-email-nachukannan%40gmail.com.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/alpine.DEB.2.21.1910080750290.2638%40hadrien.