Re: [Outreachy kernel] [PATCH] Staging: rtl8723bs: core: rtw_cmd: Remove cast to pointer types in kfree
From: Srishti Sharma
Date: Sat Oct 07 2017 - 16:08:55 EST
On Sun, Oct 8, 2017 at 1:36 AM, Julia Lawall <julia.lawall@xxxxxxx> wrote:
>
>
> On Sun, 8 Oct 2017, Srishti Sharma wrote:
>
>> On Sat, Oct 7, 2017 at 11:42 PM, Julia Lawall <julia.lawall@xxxxxxx> wrote:
>> >
>> >
>> > On Sat, 7 Oct 2017, Srishti Sharma wrote:
>> >
>> >> The cast to pointer types in kfree is not needed and can be dropped.
>> >> Done using the following semantic by coccinelle.
>> >>
>> >> @r@
>> >> type T,P;
>> >> T* x;
>> >> @@
>> >>
>> >> kfree(
>> >> -(P *)
>> >> x )
>> >>
>> >> Signed-off-by: Srishti Sharma <srishtishar@xxxxxxxxx>
>> >> ---
>> >> drivers/staging/rtl8723bs/core/rtw_cmd.c | 58 ++++++++++++++++----------------
>> >> 1 file changed, 29 insertions(+), 29 deletions(-)
>> >>
>> >> diff --git a/drivers/staging/rtl8723bs/core/rtw_cmd.c b/drivers/staging/rtl8723bs/core/rtw_cmd.c
>> >> index 1843c44..e71e3ab 100644
>> >> --- a/drivers/staging/rtl8723bs/core/rtw_cmd.c
>> >> +++ b/drivers/staging/rtl8723bs/core/rtw_cmd.c
>> >> @@ -408,7 +408,7 @@ void rtw_free_cmd_obj(struct cmd_obj *pcmd)
>> >> }
>> >>
>> >> /* free cmd_obj */
>> >> - kfree((unsigned char *)pcmd);
>> >> + kfree(pcmd);
>> >> }
>> >>
>> >>
>> >> @@ -619,7 +619,7 @@ u8 rtw_sitesurvey_cmd(struct adapter *padapter, struct ndis_802_11_ssid *ssid,
>> >>
>> >> psurveyPara = rtw_zmalloc(sizeof(struct sitesurvey_parm));
>> >> if (psurveyPara == NULL) {
>> >> - kfree((unsigned char *) ph2c);
>> >> + kfree(ph2c);
>> >> return _FAIL;
>> >> }
>> >>
>> >> @@ -689,7 +689,7 @@ u8 rtw_setdatarate_cmd(struct adapter *padapter, u8 *rateset)
>> >>
>> >> pbsetdataratepara = rtw_zmalloc(sizeof(struct setdatarate_parm));
>> >> if (pbsetdataratepara == NULL) {
>> >> - kfree((u8 *) ph2c);
>> >> + kfree(ph2c);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -707,7 +707,7 @@ void rtw_getbbrfreg_cmdrsp_callback(struct adapter *padapter, struct cmd_obj *p
>> >> {
>> >> /* rtw_free_cmd_obj(pcmd); */
>> >> kfree((unsigned char *) pcmd->parmbuf);
>> >
>> > This case didn't get updated, probably because Coccinelle didn't have
>> > access to enough type information. Try rerunning with --all-includes or
>> > --recursive-includes. You may also need to give some include path
>> > information (-I argument).
>> I tried doing this but it is still not detecting this particular case,
>> for the include path I gave the path of the directory which contains
>> the header file in which struct cmd_obj is defined.
>
> OK, just check the field type manually, and then put a note in your commit
> log saying that you have done that case by hand, due to Coccinelle's not
> having sufficient type information.
Yes, I have checked it , it is a pointer.
Thanks,
Srishti
>
> julia
>
>>
>> Regards,
>> Srishti
>> >
>> > julia
>> >
>> >> - kfree((unsigned char *) pcmd);
>> >> + kfree(pcmd);
>> >> }
>> >>
>> >> u8 rtw_createbss_cmd(struct adapter *padapter)
>> >> @@ -847,7 +847,7 @@ u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork)
>> >> psecnetwork = (struct wlan_bssid_ex *)&psecuritypriv->sec_bss;
>> >> if (psecnetwork == NULL) {
>> >> if (pcmd != NULL)
>> >> - kfree((unsigned char *)pcmd);
>> >> + kfree(pcmd);
>> >>
>> >> res = _FAIL;
>> >>
>> >> @@ -955,7 +955,7 @@ u8 rtw_disassoc_cmd(struct adapter *padapter, u32 deauth_timeout_ms, bool enqueu
>> >> cmdobj = rtw_zmalloc(sizeof(*cmdobj));
>> >> if (cmdobj == NULL) {
>> >> res = _FAIL;
>> >> - kfree((u8 *)param);
>> >> + kfree(param);
>> >> goto exit;
>> >> }
>> >> init_h2fwcmd_w_parm_no_rsp(cmdobj, param, _DisConnect_CMD_);
>> >> @@ -964,7 +964,7 @@ u8 rtw_disassoc_cmd(struct adapter *padapter, u32 deauth_timeout_ms, bool enqueu
>> >> /* no need to enqueue, do the cmd hdl directly and free cmd parameter */
>> >> if (H2C_SUCCESS != disconnect_hdl(padapter, (u8 *)param))
>> >> res = _FAIL;
>> >> - kfree((u8 *)param);
>> >> + kfree(param);
>> >> }
>> >>
>> >> exit:
>> >> @@ -990,7 +990,7 @@ u8 rtw_setopmode_cmd(struct adapter *padapter, enum NDIS_802_11_NETWORK_INFRAST
>> >> if (enqueue) {
>> >> ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
>> >> if (ph2c == NULL) {
>> >> - kfree((u8 *)psetop);
>> >> + kfree(psetop);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -999,7 +999,7 @@ u8 rtw_setopmode_cmd(struct adapter *padapter, enum NDIS_802_11_NETWORK_INFRAST
>> >> res = rtw_enqueue_cmd(pcmdpriv, ph2c);
>> >> } else{
>> >> setopmode_hdl(padapter, (u8 *)psetop);
>> >> - kfree((u8 *)psetop);
>> >> + kfree(psetop);
>> >> }
>> >> exit:
>> >> return res;
>> >> @@ -1042,15 +1042,15 @@ u8 rtw_setstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 unicast_
>> >> if (enqueue) {
>> >> ph2c = rtw_zmalloc(sizeof(struct cmd_obj));
>> >> if (ph2c == NULL) {
>> >> - kfree((u8 *) psetstakey_para);
>> >> + kfree(psetstakey_para);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >>
>> >> psetstakey_rsp = rtw_zmalloc(sizeof(struct set_stakey_rsp));
>> >> if (psetstakey_rsp == NULL) {
>> >> - kfree((u8 *) ph2c);
>> >> - kfree((u8 *) psetstakey_para);
>> >> + kfree(ph2c);
>> >> + kfree(psetstakey_para);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -1061,7 +1061,7 @@ u8 rtw_setstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 unicast_
>> >> res = rtw_enqueue_cmd(pcmdpriv, ph2c);
>> >> } else{
>> >> set_stakey_hdl(padapter, (u8 *)psetstakey_para);
>> >> - kfree((u8 *) psetstakey_para);
>> >> + kfree(psetstakey_para);
>> >> }
>> >> exit:
>> >> return res;
>> >> @@ -1091,15 +1091,15 @@ u8 rtw_clearstakey_cmd(struct adapter *padapter, struct sta_info *sta, u8 enqueu
>> >>
>> >> psetstakey_para = rtw_zmalloc(sizeof(struct set_stakey_parm));
>> >> if (psetstakey_para == NULL) {
>> >> - kfree((u8 *) ph2c);
>> >> + kfree(ph2c);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >>
>> >> psetstakey_rsp = rtw_zmalloc(sizeof(struct set_stakey_rsp));
>> >> if (psetstakey_rsp == NULL) {
>> >> - kfree((u8 *) ph2c);
>> >> - kfree((u8 *) psetstakey_para);
>> >> + kfree(ph2c);
>> >> + kfree(psetstakey_para);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -1136,7 +1136,7 @@ u8 rtw_addbareq_cmd(struct adapter *padapter, u8 tid, u8 *addr)
>> >>
>> >> paddbareq_parm = rtw_zmalloc(sizeof(struct addBaReq_parm));
>> >> if (paddbareq_parm == NULL) {
>> >> - kfree((unsigned char *)ph2c);
>> >> + kfree(ph2c);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -1170,7 +1170,7 @@ u8 rtw_reset_securitypriv_cmd(struct adapter *padapter)
>> >>
>> >> pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
>> >> if (pdrvextra_cmd_parm == NULL) {
>> >> - kfree((unsigned char *)ph2c);
>> >> + kfree(ph2c);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -1205,7 +1205,7 @@ u8 rtw_free_assoc_resources_cmd(struct adapter *padapter)
>> >>
>> >> pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
>> >> if (pdrvextra_cmd_parm == NULL) {
>> >> - kfree((unsigned char *)ph2c);
>> >> + kfree(ph2c);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -1241,7 +1241,7 @@ u8 rtw_dynamic_chk_wk_cmd(struct adapter *padapter)
>> >>
>> >> pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
>> >> if (pdrvextra_cmd_parm == NULL) {
>> >> - kfree((unsigned char *)ph2c);
>> >> + kfree(ph2c);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -1294,7 +1294,7 @@ u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue, u8 swconf
>> >> /* need enqueue, prepare cmd_obj and enqueue */
>> >> pcmdobj = rtw_zmalloc(sizeof(struct cmd_obj));
>> >> if (pcmdobj == NULL) {
>> >> - kfree((u8 *)setChannelPlan_param);
>> >> + kfree(setChannelPlan_param);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -1306,7 +1306,7 @@ u8 rtw_set_chplan_cmd(struct adapter *padapter, u8 chplan, u8 enqueue, u8 swconf
>> >> if (H2C_SUCCESS != set_chplan_hdl(padapter, (unsigned char *)setChannelPlan_param))
>> >> res = _FAIL;
>> >>
>> >> - kfree((u8 *)setChannelPlan_param);
>> >> + kfree(setChannelPlan_param);
>> >> }
>> >>
>> >> /* do something based on res... */
>> >> @@ -1561,7 +1561,7 @@ u8 rtw_lps_ctrl_wk_cmd(struct adapter *padapter, u8 lps_ctrl_type, u8 enqueue)
>> >>
>> >> pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
>> >> if (pdrvextra_cmd_parm == NULL) {
>> >> - kfree((unsigned char *)ph2c);
>> >> + kfree(ph2c);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -1603,7 +1603,7 @@ u8 rtw_dm_in_lps_wk_cmd(struct adapter *padapter)
>> >>
>> >> pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
>> >> if (pdrvextra_cmd_parm == NULL) {
>> >> - kfree((unsigned char *)ph2c);
>> >> + kfree(ph2c);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -1676,7 +1676,7 @@ u8 rtw_dm_ra_mask_wk_cmd(struct adapter *padapter, u8 *psta)
>> >>
>> >> pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
>> >> if (pdrvextra_cmd_parm == NULL) {
>> >> - kfree((unsigned char *)ph2c);
>> >> + kfree(ph2c);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -1727,7 +1727,7 @@ u8 rtw_ps_cmd(struct adapter *padapter)
>> >>
>> >> pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
>> >> if (pdrvextra_cmd_parm == NULL) {
>> >> - kfree((unsigned char *)ppscmd);
>> >> + kfree(ppscmd);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -1799,7 +1799,7 @@ u8 rtw_chk_hi_queue_cmd(struct adapter *padapter)
>> >>
>> >> pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
>> >> if (pdrvextra_cmd_parm == NULL) {
>> >> - kfree((unsigned char *)ph2c);
>> >> + kfree(ph2c);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -1898,7 +1898,7 @@ u8 rtw_c2h_packet_wk_cmd(struct adapter *padapter, u8 *pbuf, u16 length)
>> >>
>> >> pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
>> >> if (pdrvextra_cmd_parm == NULL) {
>> >> - kfree((u8 *)ph2c);
>> >> + kfree(ph2c);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> @@ -1933,7 +1933,7 @@ u8 rtw_c2h_wk_cmd(struct adapter *padapter, u8 *c2h_evt)
>> >>
>> >> pdrvextra_cmd_parm = rtw_zmalloc(sizeof(struct drvextra_cmd_parm));
>> >> if (pdrvextra_cmd_parm == NULL) {
>> >> - kfree((u8 *)ph2c);
>> >> + kfree(ph2c);
>> >> res = _FAIL;
>> >> goto exit;
>> >> }
>> >> --
>> >> 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 outreachy-kernel+unsubscribe@xxxxxxxxxxxxxxxxx
>> >> To post to this group, send email to outreachy-kernel@xxxxxxxxxxxxxxxxx
>> >> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1507380884-10906-1-git-send-email-srishtishar%40gmail.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>> >>
>>
>> --
>> 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 outreachy-kernel+unsubscribe@xxxxxxxxxxxxxxxxx
>> To post to this group, send email to outreachy-kernel@xxxxxxxxxxxxxxxxx
>> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CAB3L5oxHV_buBHqmX3-Tw0UMj7ivBP3btEaRUmUa064Di%2BHUTg%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>>