staging: wilc1000: fix uninitialized variablie warning
PATCH 1/2 staging: wilc1000: fix uninitialized variablie warning
When building this driver, I got a warning as below:
host_interface.c: In function ‘host_int_add_beacon’:
host_interface.c:7116:16: warning: ‘*((void *)&strHostIFmsg+8).pu8Head’ may be used uninitialized in this function [-Wmaybe-uninitialized]
--- drivers/staging/wilc1000/host_interface.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/staging/wilc1000/host_interface.c +6 -2
@@ -7131,8 +7131,11 @@ s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval, pstrSetBeaconParam->u32DTIMPeriod = u32DTIMPeriod; pstrSetBeaconParam->u32HeadLen = u32HeadLen; pstrSetBeaconParam->pu8Head = (u8 *)WILC_MALLOC (u32HeadLen); -if (pstrSetBeaconParam->pu8Head ==NULL ) -WILC_ERRORREPORT (s32Error,WILC_NO_MEM ); +if (pstrSetBeaconParam->pu8Head ==NULL ) { +PRINT_ER ("Failed to allocated memory\n" ); + s32Error =WILC_NO_MEM ; + goto _fail_; + }WILC_memcpy (pstrSetBeaconParam->pu8Head, pu8Head, u32HeadLen); pstrSetBeaconParam->u32TailLen = u32TailLen;
@@ -7159,6 +7162,7 @@ s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval,WILC_FREE (pstrSetBeaconParam->pu8Tail); } +_fail_:return s32Error; }
Signature · 1 line
1.9.1
PATCH 2/2 staging: wilc1000: fix memory allocation error check
Remove WILC_ERRORREPORT macro. If memory allocation is failed, jump to a label to return this function with WILC_NO_MEM.
--- drivers/staging/wilc1000/host_interface.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/staging/wilc1000/host_interface.c +5 -2
@@ -7142,8 +7142,11 @@ s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval,/* Bug 4599 : if tail length = 0 skip allocating & copying */ if (u32TailLen >0 ) { pstrSetBeaconParam->pu8Tail = (u8 *)WILC_MALLOC (u32TailLen); -if (pstrSetBeaconParam->pu8Tail ==NULL ) -WILC_ERRORREPORT (s32Error,WILC_NO_MEM ); +if (pstrSetBeaconParam->pu8Tail ==NULL ) { +PRINT_ER ("Failed to allocate memory\n" ); + s32Error =WILC_NO_MEM ; + goto _fail_; + }WILC_memcpy (pstrSetBeaconParam->pu8Tail, pu8Tail, u32TailLen); }else { pstrSetBeaconParam->pu8Tail =NULL ;
Signature · 1 line
1.9.1
Hi Chaehyun,
Quoted 16 lines · Chaehyun Lim
When building this driver, I got a warning as below:
host_interface.c: In function ‘host_int_add_beacon’:
host_interface.c:7116:16: warning: ‘*((void *)&strHostIFmsg+8).pu8Head’ may be used uninitialized in this function [-Wmaybe-uninitialized]Signed-off-by Chaehyun Lim <[email protected]>--- drivers/staging/wilc1000/host_interface.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)drivers/staging/wilc1000/host_interface.c +0
-0
drivers/staging/wilc1000/host_interface.c s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval, · line 7137
Quoted 9 lines
drivers/staging/wilc1000/host_interface.c +4
-2@@ -7131,8 +7131,11 @@ s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval, pstrSetBeaconParam->u32DTIMPeriod = u32DTIMPeriod; pstrSetBeaconParam->u32HeadLen = u32HeadLen; pstrSetBeaconParam->pu8Head = (u8 *)WILC_MALLOC (u32HeadLen); -if (pstrSetBeaconParam->pu8Head ==NULL ) -WILC_ERRORREPORT (s32Error,WILC_NO_MEM ); +if (pstrSetBeaconParam->pu8Head ==NULL ) { +PRINT_ER ("Failed to allocated memory\n" ); + s32Error =WILC_NO_MEM ; + goto _fail_;
Why not just return WILC_NO_MEM here instead of jumping to the return below?
drivers/staging/wilc1000/host_interface.c s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval, · line 7168
Quoted 12 lines
drivers/staging/wilc1000/host_interface.c +2
-0+ }WILC_memcpy (pstrSetBeaconParam->pu8Head, pu8Head, u32HeadLen); pstrSetBeaconParam->u32TailLen = u32TailLen;@@ -7159,6 +7162,7 @@ s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval,WILC_FREE (pstrSetBeaconParam->pu8Tail); } +_fail_:return s32Error; }
Thanks,
Signature · 4 lines
Julian Calaby Email: [email protected] Profile: http://www.google.com/profiles/julian.calaby/
Greg KH
maintainerRe: [PATCH 2/2] staging: wilc1000: fix memory allocation error check
In reply to Chaehyun LimQuoted 13 lines · Chaehyun Lim
Remove
WILC_ERRORREPORTmacro. If memory allocation is failed, jump to a label to return this function withWILC_NO_MEM.Signed-off-by Chaehyun Lim <[email protected]>--- drivers/staging/wilc1000/host_interface.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/staging/wilc1000/host_interface.c +0
-0
drivers/staging/wilc1000/host_interface.c s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval, · line 7146
Quoted 7 lines
drivers/staging/wilc1000/host_interface.c +2
-2@@ -7142,8 +7142,11 @@ s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval,/* Bug 4599 : if tail length = 0 skip allocating & copying */ if (u32TailLen >0 ) { pstrSetBeaconParam->pu8Tail = (u8 *)WILC_MALLOC (u32TailLen); -if (pstrSetBeaconParam->pu8Tail ==NULL ) -WILC_ERRORREPORT (s32Error,WILC_NO_MEM ); +if (pstrSetBeaconParam->pu8Tail ==NULL ) { +PRINT_ER ("Failed to allocate memory\n" );
This message is redundant, the core already just told the user this, so it's not needed to tell them this again.
And as an aside, the mess in WILC_MALLOC() needs to go as well, that's horrid, and wrong :(
thanks,
greg k-h
Re: [PATCH 2/2] staging: wilc1000: fix memory allocation error check
Quoted 25 lines · Greg KH
Quoted 13 lines · Chaehyun Lim
Remove
WILC_ERRORREPORTmacro. If memory allocation is failed, jump to a label to return this function withWILC_NO_MEM.Signed-off-by Chaehyun Lim <[email protected]>--- drivers/staging/wilc1000/host_interface.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/staging/wilc1000/host_interface.c +0
-0drivers/staging/wilc1000/host_interface.c s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval, · line 7146
Quoted 7 lines
drivers/staging/wilc1000/host_interface.c +2
-2@@ -7142,8 +7142,11 @@ s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval,/* Bug 4599 : if tail length = 0 skip allocating & copying */ if (u32TailLen >0 ) { pstrSetBeaconParam->pu8Tail = (u8 *)WILC_MALLOC (u32TailLen); -if (pstrSetBeaconParam->pu8Tail ==NULL ) -WILC_ERRORREPORT (s32Error,WILC_NO_MEM ); +if (pstrSetBeaconParam->pu8Tail ==NULL ) { +PRINT_ER ("Failed to allocate memory\n" );This message is redundant, the core already just told the user this, so it's not needed to tell them this again.
Quoted 2 lines
And as an aside, the mess in
WILC_MALLOC()needs to go as well, that's horrid, and wrong :(
Thank you for your comment. You think WILC_MALLOC() should be changed. Could you give me a direction how this function should be changed?
thanks,
Chaehyun Lim
Quoted 4 lines
thanks,
greg k-h
Greg KH
maintainerRe: [PATCH 2/2] staging: wilc1000: fix memory allocation error check
Quoted 26 lines · Chaehyun Lim
Quoted 25 lines · Greg KH
Quoted 13 lines · Chaehyun Lim
Remove
WILC_ERRORREPORTmacro. If memory allocation is failed, jump to a label to return this function withWILC_NO_MEM.Signed-off-by Chaehyun Lim <[email protected]>--- drivers/staging/wilc1000/host_interface.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/staging/wilc1000/host_interface.c +0
-0drivers/staging/wilc1000/host_interface.c s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval, · line 7146
Quoted 7 lines
drivers/staging/wilc1000/host_interface.c +2
-2@@ -7142,8 +7142,11 @@ s32 host_int_add_beacon(WILC_WFIDrvHandle hWFIDrv, u32 u32Interval,/* Bug 4599 : if tail length = 0 skip allocating & copying */ if (u32TailLen >0 ) { pstrSetBeaconParam->pu8Tail = (u8 *)WILC_MALLOC (u32TailLen); -if (pstrSetBeaconParam->pu8Tail ==NULL ) -WILC_ERRORREPORT (s32Error,WILC_NO_MEM ); +if (pstrSetBeaconParam->pu8Tail ==NULL ) { +PRINT_ER ("Failed to allocate memory\n" );This message is redundant, the core already just told the user this, so it's not needed to tell them this again.
Quoted 5 lines
Quoted 2 lines
And as an aside, the mess in
WILC_MALLOC()needs to go as well, that's horrid, and wrong :(Thank you for your comment. You think
WILC_MALLOC()should be changed. Could you give me a direction how this function should be changed?
Hm, let me turn the question around, why do you think it should be there at all?
thanks,
greg k-h