staging: rtl8723bs: Remove useless led_blink_hdl()
PATCH 1/1 staging: rtl8723bs: Remove useless led_blink_hdl()
Removed the led_blink_hdl() function (declaration and definition). Declared dummy_function() in include/rtw_mlme_ext.h and defined it in core/rtw_cmd.c. Changed the second parameter of GEN_MLME_EXT_HANDLER macro to make use of dummy_function().
--- drivers/staging/rtl8723bs/core/rtw_cmd.c | 4 +++- drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 9 --------- drivers/staging/rtl8723bs/include/rtw_mlme_ext.h | 3 ++- 3 files changed, 5 insertions(+), 11 deletions(-)
drivers/staging/rtl8723bs/core/rtw_cmd.c +3 -1
@@ -87,6 +87,8 @@ static struct _cmd_callback rtw_cmd_callback[] = { {GEN_CMD_CODE(_RunInThreadCMD), NULL},/*64*/ }; +u8 dummy_functioni (struct adapter *var0,u8 *var1) {return 0 ; } +static struct cmd_hdl wlancmds[] = { GEN_DRV_CMD_HANDLER(0, NULL) /*0*/ GEN_DRV_CMD_HANDLER(0, NULL)
@@ -150,7 +152,7 @@ static struct cmd_hdl wlancmds[] = { GEN_MLME_EXT_HANDLER(0, h2c_msg_hdl) /*58*/ GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelPlan_param), set_chplan_hdl) /*59*/ - GEN_MLME_EXT_HANDLER(sizeof(struct LedBlink_param), led_blink_hdl) /*60*/ + GEN_MLME_EXT_HANDLER(sizeof(struct LedBlink_param), dummy_function) /*60*/ GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelSwitch_param), set_csa_hdl) /*61*/GEN_MLME_EXT_HANDLER (sizeof (struct TDLSoption_param ), tdls_hdl)/*62*/
drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0 -9
@@ -6189,15 +6189,6 @@ u8 set_chplan_hdl(struct adapter *padapter, unsigned char *pbuf)return H2C_SUCCESS ; } -u8 led_blink_hdl (struct adapter *padapter,unsigned char *pbuf) -{ - -if (!pbuf) -return H2C_PARAMETERS_ERROR ; - -return H2C_SUCCESS ; -} -u8 set_csa_hdl (struct adapter *padapter,unsigned char *pbuf) {return H2C_REJECTED ;
drivers/staging/rtl8723bs/include/rtw_mlme_ext.h +2 -1
@@ -745,11 +745,12 @@ u8 chk_bmc_sleepq_hdl(struct adapter *padapter, unsigned char *pbuf);u8 tx_beacon_hdl (struct adapter *padapter,unsigned char *pbuf);u8 set_ch_hdl (struct adapter *padapter,u8 *pbuf);u8 set_chplan_hdl (struct adapter *padapter,unsigned char *pbuf); -u8 led_blink_hdl (struct adapter *padapter,unsigned char *pbuf);u8 set_csa_hdl (struct adapter *padapter,unsigned char *pbuf);/* Kurt: Handling DFS channel switch announcement ie. */ u8 tdls_hdl (struct adapter *padapter,unsigned char *pbuf);u8 run_in_thread_hdl (struct adapter *padapter,u8 *pbuf); +/* Dummy function used to fill elements of an array of function pointers */ +u8 dummy_function (struct adapter *,u8 *);#define GEN_DRV_CMD_HANDLER (size, cmd) {size, &cmd ## _hdl},#define GEN_MLME_EXT_HANDLER (size, cmd) {size, cmd},
Signature · 1 line
2.31.1
Quoted 19 lines · Fabio M. De Francesco
Removed the
led_blink_hdl()function (declaration and definition). Declareddummy_function()ininclude/rtw_mlme_ext.hand defined it incore/rtw_cmd.c. Changed the second parameter ofGEN_MLME_EXT_HANDLERmacro to make use ofdummy_function().Reported-by Julia Lawall <[email protected]>Suggested-by Dan Carpenter <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/staging/rtl8723bs/core/rtw_cmd.c | 4 +++- drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 9 --------- drivers/staging/rtl8723bs/include/rtw_mlme_ext.h | 3 ++- 3 files changed, 5 insertions(+), 11 deletions(-)drivers/staging/rtl8723bs/core/rtw_cmd.c +0
-0
drivers/staging/rtl8723bs/core/rtw_cmd.c static struct _cmd_callback rtw_cmd_callback[] = { · line 91
Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_cmd.c +2
-0@@ -87,6 +87,8 @@ static struct _cmd_callback rtw_cmd_callback[] = { {GEN_CMD_CODE(_RunInThreadCMD), NULL},/*64*/ }; +u8 dummy_functioni (struct adapter *var0,u8 *var1) {return 0 ; } +
I think that this won't compile
Quoted 37 lines
drivers/staging/rtl8723bs/core/rtw_cmd.c +1
-1static struct cmd_hdl wlancmds[] = { GEN_DRV_CMD_HANDLER(0, NULL) /*0*/GEN_DRV_CMD_HANDLER (0 ,NULL )@@ -150,7 +152,7 @@ static struct cmd_hdl wlancmds[] = { GEN_MLME_EXT_HANDLER(0, h2c_msg_hdl) /*58*/ GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelPlan_param), set_chplan_hdl) /*59*/ - GEN_MLME_EXT_HANDLER(sizeof(struct LedBlink_param), led_blink_hdl) /*60*/ + GEN_MLME_EXT_HANDLER(sizeof(struct LedBlink_param), dummy_function) /*60*/ GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelSwitch_param), set_csa_hdl) /*61*/GEN_MLME_EXT_HANDLER (sizeof (struct TDLSoption_param ), tdls_hdl)/*62*/ drivers/staging/rtl8723bs/core/rtw_mlme_ext.c +0
-9@@ -6189,15 +6189,6 @@ u8 set_chplan_hdl(struct adapter *padapter, unsigned char *pbuf)return H2C_SUCCESS ; } -u8 led_blink_hdl (struct adapter *padapter,unsigned char *pbuf) -{ - -if (!pbuf) -return H2C_PARAMETERS_ERROR ; - -return H2C_SUCCESS ; -} -u8 set_csa_hdl (struct adapter *padapter,unsigned char *pbuf) {return H2C_REJECTED ;drivers/staging/rtl8723bs/include/rtw_mlme_ext.h +0
-0
drivers/staging/rtl8723bs/include/rtw_mlme_ext.h u8 chk_bmc_sleepq_hdl(struct adapter *padapter, unsigned char *pbuf); · line 753
Quoted 10 lines
drivers/staging/rtl8723bs/include/rtw_mlme_ext.h +2
-1@@ -745,11 +745,12 @@ u8 chk_bmc_sleepq_hdl(struct adapter *padapter, unsigned char *pbuf);u8 tx_beacon_hdl (struct adapter *padapter,unsigned char *pbuf);u8 set_ch_hdl (struct adapter *padapter,u8 *pbuf);u8 set_chplan_hdl (struct adapter *padapter,unsigned char *pbuf); -u8 led_blink_hdl (struct adapter *padapter,unsigned char *pbuf);u8 set_csa_hdl (struct adapter *padapter,unsigned char *pbuf);/* Kurt: Handling DFS channel switch announcement ie. */ u8 tdls_hdl (struct adapter *padapter,unsigned char *pbuf);u8 run_in_thread_hdl (struct adapter *padapter,u8 *pbuf); +/* Dummy function used to fill elements of an array of function pointers */ +u8 dummy_function (struct adapter *,u8 *);
here 'dummy_function' prototype is declared
Quoted 7 lines
drivers/staging/rtl8723bs/include/rtw_mlme_ext.h +0
-0#define GEN_DRV_CMD_HANDLER (size, cmd) {size, &cmd ## _hdl},#define GEN_MLME_EXT_HANDLER (size, cmd) {size, cmd},Signature · 1 line
2.31.1
thank you,
fabio
Greg Kroah-Hartman
maintainerQuoted 4 lines · Fabio M. De Francesco
Removed the
led_blink_hdl()function (declaration and definition). Declareddummy_function()ininclude/rtw_mlme_ext.hand defined it incore/rtw_cmd.c. Changed the second parameter ofGEN_MLME_EXT_HANDLERmacro to make use ofdummy_function().
No no no.
If you want to remove is function declaration and use, then do it properly.
The code is crazy, I agree, but it should not be difficult to just remove this correctly instead of papering over this mess.
Also note that no one actually calls this function if you look at the logic here. It might take some good knowledge of C to unwind this crud, but once done, you should be able to "prove" it's not called and how to remove it correctly.
And no, I'm not going to say how to do it, that's an exercise best left for the reader. But I will hint that this was done in the past, in 2014, in another driver in the tree with a codebase much like this one, so it shouldn't be hard to find an example of it. Only took me a few minutes...
good luck!
greg k-h
Quoted 11 lines · CEST Greg Kroah-Hartman
Quoted 4 lines · Fabio M. De Francesco
Removed the
led_blink_hdl()function (declaration and definition). Declareddummy_function()ininclude/rtw_mlme_ext.hand defined it incore/rtw_cmd.c. Changed the second parameter ofGEN_MLME_EXT_HANDLERmacro to make use ofdummy_function().No no no.
If you want to remove is function declaration and use, then do it properly.
Quoted 9 lines
The code is crazy, I agree, but it should not be difficult to just remove this correctly instead of papering over this mess.
Also note that no one actually calls this function if you look at the logic here.
It might take some good knowledge of C to unwind this crud, but once done, you should be able to "prove" it's not called
Proving that no one actually calls it it's beyond my current knowledge of programming with C.
Matthew W., who is for sure more experienced than I am , wrote that that function pointer in the array is used somewhere else.
Copied and pasted here from his message:
"Here's where the driver calls that function:
$ git grep wlancmds drivers/staging/rtl8723bs/
drivers/staging/rtl8723bs/core/rtw_cmd.c:static struct cmd_hdl wlancmds[] = {
drivers/staging/rtl8723bs/core/rtw_cmd.c: if (pcmd->cmdcode < ARRAY_SIZE(wlancmds)) {
drivers/staging/rtl8723bs/core/rtw_cmd.c: cmd_hdl = wlancmds[pcmd->cmdcode].h2cfuns;Quoted 4 lines
and how to
remove it correctly.
I think that doing it correctly depends on the "prove" which you requested. Doesn't it?
Quoted 4 lines
And no, I'm not going to say how to do it, that's an exercise best left for the reader.
It sounds perfectly reasonable and I agree in full.
Quoted 6 lines
But I will hint that this was done in the past, in
2014, in another driver in the tree with a codebase much like this one, so it shouldn't be hard to find an example of it. Only took me a few minutes...
I'm sure it took you only a few minutes. If this can be accomplished by using grep on git log output I need some time to read this command manual again. I suppose that the search should be made by combining "remove", "function", "drivers/staging", and "2014". At the moment I don't know how to do that.
Notwithstanding I have said all that you read above, you can be sure that I won't give up so easily even if it will take days :)
Quoted 3 lines
good luck!
Thanks,
Fabio
Quoted 2 lines
greg k-h
Quoted 28 lines · Fabio M. De Francesco
Removed the
led_blink_hdl()function (declaration and definition). Declareddummy_function()ininclude/rtw_mlme_ext.hand defined it incore/rtw_cmd.c. Changed the second parameter ofGEN_MLME_EXT_HANDLERmacro to make use ofdummy_function().Reported-by Julia Lawall <[email protected]>Suggested-by Dan Carpenter <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>--- drivers/staging/rtl8723bs/core/rtw_cmd.c | 4 +++- drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 9 --------- drivers/staging/rtl8723bs/include/rtw_mlme_ext.h | 3 ++- 3 files changed, 5 insertions(+), 11 deletions(-)drivers/staging/rtl8723bs/core/rtw_cmd.c +2
-0@@ -87,6 +87,8 @@ static struct _cmd_callback rtw_cmd_callback[] = { {GEN_CMD_CODE(_RunInThreadCMD), NULL},/*64*/ }; +u8 dummy_functioni (struct adapter *var0,u8 *var1) {return 0 ; } +static struct cmd_hdl wlancmds[] = { GEN_DRV_CMD_HANDLER(0, NULL) /*0*/ GEN_DRV_CMD_HANDLER(0, NULL)
drivers/staging/rtl8723bs/core/rtw_cmd.c static struct cmd_hdl wlancmds[] = { · line 155
Quoted 5 lines
drivers/staging/rtl8723bs/core/rtw_cmd.c +1
-1@@ -150,7 +152,7 @@ static struct cmd_hdl wlancmds[] = { GEN_MLME_EXT_HANDLER(0, h2c_msg_hdl) /*58*/ GEN_MLME_EXT_HANDLER(sizeof(struct SetChannelPlan_param), set_chplan_hdl) /*59*/ -GEN_MLME_EXT_HANDLER (sizeof (struct LedBlink_param ), led_blink_hdl)/*60*/ +GEN_MLME_EXT_HANDLER (sizeof (struct LedBlink_param ), dummy_function)/*60*/
No, no. Don't create a dummy function. Do it like so:
GEN_DRV_CMD_HANDLER(0, NULL) /* 60 */
regards,
dan carpenter
Quoted 35 lines · CEST Dan Carpenter
Quoted 34 lines · Fabio M. De Francesco
Removed the
led_blink_hdl()function (declaration and definition). Declareddummy_function()ininclude/rtw_mlme_ext.hand defined it incore/rtw_cmd.c. Changed the second parameter ofGEN_MLME_EXT_HANDLERmacro to make use ofdummy_function().Reported-by Julia Lawall <[email protected]>Suggested-by Dan Carpenter <[email protected]>Signed-off-by Fabio M. De Francesco <[email protected]>---
drivers/staging/rtl8723bs/core/rtw_cmd.c | 4 +++- drivers/staging/rtl8723bs/core/rtw_mlme_ext.c | 9 --------- drivers/staging/rtl8723bs/include/rtw_mlme_ext.h | 3 ++- 3 files changed, 5 insertions(+), 11 deletions(-)(quoted diff) +0
-0
b/drivers/staging/rtl8723bs/core/rtw_cmd.cindex0297fbad7bce..7b6102a2bb2c100644drivers/staging/rtl8723bs/core/rtw_cmd.c +2
-0@@ -87,6 +87,8 @@ static struct _cmd_callback rtw_cmd_callback[] = { {GEN_CMD_CODE(_RunInThreadCMD), NULL},/*64*/ }; +u8 dummy_functioni (struct adapter *var0,u8 *var1) {return 0 ; } +static struct
cmd_hdlwlancmds[] = {drivers/staging/rtl8723bs/core/rtw_cmd.c +0
-0GEN_DRV_CMD_HANDLER(0, NULL) /*0*/GEN_DRV_CMD_HANDLER (0 ,NULL )
Quoted 6 lines
drivers/staging/rtl8723bs/core/rtw_cmd.c static struct cmd_hdl wlancmds[] = { · line 154
Quoted 6 lines
drivers/staging/rtl8723bs/core/rtw_cmd.c +0
-1@@ -150,7 +152,7 @@ static struct cmd_hdl wlancmds[] = { GEN_MLME_EXT_HANDLER(0, h2c_msg_hdl) /*58*/GEN_MLME_EXT_HANDLER (sizeof (struct SetChannelPlan_param ), set_chplan_hdl) /*59*/> - GEN_MLME_EXT_HANDLER(sizeof(struct LedBlink_param),
led_blink_hdl)
Quoted 9 lines
Quoted 2 lines
drivers/staging/rtl8723bs/core/rtw_cmd.c +0
-0/*60*/ + GEN_MLME_EXT_HANDLER(sizeof(struct LedBlink_param),
dummy_function) /*60*/No, no. Don't create a dummy function. Do it like so:
GEN_DRV_CMD_HANDLER(0, NULL) /* 60 */regards,
dan carpenter
I'm replying late because I didn't want to blindly use that solution; I mean that I wanted to understand why I can simply put 0 and NULL into that macro. I had seen it made in other lines that initialize wlancmds[] elements, but I wasn't sure if it could work for the specific slot where the pointer to led_blinck_hdl was supposed to be placed.
Now I think that it is why, in this case, cmd_hdl would be set to NULL by the call to wlancmds[pcmd->cmdcode].h2cfuns and the cmd_hdl() function wouldn't be called because cmd_hdl is tested within an "if" statement.
Therefore a simple GEN_DRV_CMD_HANDLER(0, NULL) at slot number would be the simplest and most obvious solution.
Is the above argument sound?
Thanks for your kind help,
Fabio