linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] staging: wilc1000: coreconfigurator.c: remove WILC_MALLOC
@ 2015-07-23 11:19 Chaehyun Lim
  2015-07-23 11:19 ` [PATCH 2/3] staging: wilc1000: coreconfigurator.c: add kmalloc error check Chaehyun Lim
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Chaehyun Lim @ 2015-07-23 11:19 UTC (permalink / raw)
  To: gregkh
  Cc: johnny.kim, rachel.kim, dean.lee, chris.park, linux-wireless,
	devel, Chaehyun Lim

Use kmalloc and kmalloc_array instead of WILC_MALLOC.

Signed-off-by: Chaehyun Lim <chaehyun.lim@gmail.com>
---
 drivers/staging/wilc1000/coreconfigurator.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/wilc1000/coreconfigurator.c b/drivers/staging/wilc1000/coreconfigurator.c
index b069614..7e2b2ab41 100644
--- a/drivers/staging/wilc1000/coreconfigurator.c
+++ b/drivers/staging/wilc1000/coreconfigurator.c
@@ -674,7 +674,7 @@ s32 CoreConfiguratorInit(void)
 	sema_init(&SemHandleSendPkt, 1);
 	sema_init(&SemHandlePktResp, 0);
 
-	gps8ConfigPacket = (s8 *)WILC_MALLOC(MAX_PACKET_BUFF_SIZE);
+	gps8ConfigPacket = kmalloc(MAX_PACKET_BUFF_SIZE, GFP_ATOMIC);
 	if (gps8ConfigPacket == NULL) {
 		PRINT_ER("failed in gps8ConfigPacket allocation\n");
 		s32Error = WILC_NO_MEM;
@@ -811,7 +811,7 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
 		u32 u32Tsf_Lo;
 		u32 u32Tsf_Hi;
 
-		pstrNetworkInfo = (tstrNetworkInfo *)WILC_MALLOC(sizeof(tstrNetworkInfo));
+		pstrNetworkInfo = kmalloc(sizeof(tstrNetworkInfo), GFP_ATOMIC);
 		WILC_memset((void *)(pstrNetworkInfo), 0, sizeof(tstrNetworkInfo));
 
 		pstrNetworkInfo->s8rssi = pu8WidVal[0];
@@ -862,7 +862,7 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
 		u16IEsLen = u16RxLen - (MAC_HDR_LEN + TIME_STAMP_LEN + BEACON_INTERVAL_LEN + CAP_INFO_LEN);
 
 		if (u16IEsLen > 0) {
-			pstrNetworkInfo->pu8IEs = (u8 *)WILC_MALLOC(u16IEsLen);
+			pstrNetworkInfo->pu8IEs = kmalloc(u16IEsLen, GFP_ATOMIC);
 			WILC_memset((void *)(pstrNetworkInfo->pu8IEs), 0, u16IEsLen);
 
 			WILC_memcpy(pstrNetworkInfo->pu8IEs, pu8IEs, u16IEsLen);
@@ -929,7 +929,7 @@ s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
 	u8 *pu8IEs = 0;
 	u16 u16IEsLen = 0;
 
-	pstrConnectRespInfo = (tstrConnectRespInfo *)WILC_MALLOC(sizeof(tstrConnectRespInfo));
+	pstrConnectRespInfo = kmalloc(sizeof(tstrConnectRespInfo), GFP_ATOMIC);
 	WILC_memset((void *)(pstrConnectRespInfo), 0, sizeof(tstrConnectRespInfo));
 
 	/* u16AssocRespLen = pu8Buffer[0]; */
@@ -949,7 +949,7 @@ s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
 		pu8IEs = &pu8Buffer[CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN];
 		u16IEsLen = u16AssocRespLen - (CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN);
 
-		pstrConnectRespInfo->pu8RespIEs = (u8 *)WILC_MALLOC(u16IEsLen);
+		pstrConnectRespInfo->pu8RespIEs = kmalloc(u16IEsLen, GFP_ATOMIC);
 		WILC_memset((void *)(pstrConnectRespInfo->pu8RespIEs), 0, u16IEsLen);
 
 		WILC_memcpy(pstrConnectRespInfo->pu8RespIEs, pu8IEs, u16IEsLen);
@@ -1018,7 +1018,8 @@ s32 ParseSurveyResults(u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZ
 		}
 	}
 
-	pstrSurveyResults = (wid_site_survey_reslts_s *)WILC_MALLOC(u32SurveyResultsCount * sizeof(wid_site_survey_reslts_s));
+	pstrSurveyResults = kmalloc_array(u32SurveyResultsCount,
+				sizeof(wid_site_survey_reslts_s), GFP_ATOMIC);
 	if (pstrSurveyResults == NULL) {
 		u32SurveyResultsCount = 0;
 		WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] staging: wilc1000: coreconfigurator.c: add kmalloc error check
  2015-07-23 11:19 [PATCH 1/3] staging: wilc1000: coreconfigurator.c: remove WILC_MALLOC Chaehyun Lim
@ 2015-07-23 11:19 ` Chaehyun Lim
  2015-07-23 11:31   ` Dan Carpenter
  2015-07-23 17:19   ` Joe Perches
  2015-07-23 11:19 ` [PATCH 3/3] staging: wilc1000: coreconfigurator.c: fix " Chaehyun Lim
  2015-07-23 21:52 ` [PATCH 1/3] staging: wilc1000: coreconfigurator.c: remove WILC_MALLOC Greg KH
  2 siblings, 2 replies; 6+ messages in thread
From: Chaehyun Lim @ 2015-07-23 11:19 UTC (permalink / raw)
  To: gregkh
  Cc: johnny.kim, rachel.kim, dean.lee, chris.park, linux-wireless,
	devel, Chaehyun Lim

Add error check if memory allocation is failed.

Signed-off-by: Chaehyun Lim <chaehyun.lim@gmail.com>
---
 drivers/staging/wilc1000/coreconfigurator.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/staging/wilc1000/coreconfigurator.c b/drivers/staging/wilc1000/coreconfigurator.c
index 7e2b2ab41..b51c15f 100644
--- a/drivers/staging/wilc1000/coreconfigurator.c
+++ b/drivers/staging/wilc1000/coreconfigurator.c
@@ -812,6 +812,9 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
 		u32 u32Tsf_Hi;
 
 		pstrNetworkInfo = kmalloc(sizeof(tstrNetworkInfo), GFP_ATOMIC);
+		if (pstrNetworkInfo == NULL)
+			return -ENOMEM;
+
 		WILC_memset((void *)(pstrNetworkInfo), 0, sizeof(tstrNetworkInfo));
 
 		pstrNetworkInfo->s8rssi = pu8WidVal[0];
@@ -863,6 +866,9 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
 
 		if (u16IEsLen > 0) {
 			pstrNetworkInfo->pu8IEs = kmalloc(u16IEsLen, GFP_ATOMIC);
+			if (pstrNetworkInfo->pu8IEs == NULL)
+				return -ENOMEM;
+
 			WILC_memset((void *)(pstrNetworkInfo->pu8IEs), 0, u16IEsLen);
 
 			WILC_memcpy(pstrNetworkInfo->pu8IEs, pu8IEs, u16IEsLen);
@@ -930,6 +936,9 @@ s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
 	u16 u16IEsLen = 0;
 
 	pstrConnectRespInfo = kmalloc(sizeof(tstrConnectRespInfo), GFP_ATOMIC);
+	if (pstrConnectRespInfo == NULL)
+		return -ENOMEM;
+
 	WILC_memset((void *)(pstrConnectRespInfo), 0, sizeof(tstrConnectRespInfo));
 
 	/* u16AssocRespLen = pu8Buffer[0]; */
@@ -950,6 +959,9 @@ s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
 		u16IEsLen = u16AssocRespLen - (CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN);
 
 		pstrConnectRespInfo->pu8RespIEs = kmalloc(u16IEsLen, GFP_ATOMIC);
+		if (pstrConnectRespInfo->pu8RespIEs == NULL)
+			return -ENOMEM;
+
 		WILC_memset((void *)(pstrConnectRespInfo->pu8RespIEs), 0, u16IEsLen);
 
 		WILC_memcpy(pstrConnectRespInfo->pu8RespIEs, pu8IEs, u16IEsLen);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] staging: wilc1000: coreconfigurator.c: fix kmalloc error check
  2015-07-23 11:19 [PATCH 1/3] staging: wilc1000: coreconfigurator.c: remove WILC_MALLOC Chaehyun Lim
  2015-07-23 11:19 ` [PATCH 2/3] staging: wilc1000: coreconfigurator.c: add kmalloc error check Chaehyun Lim
@ 2015-07-23 11:19 ` Chaehyun Lim
  2015-07-23 21:52 ` [PATCH 1/3] staging: wilc1000: coreconfigurator.c: remove WILC_MALLOC Greg KH
  2 siblings, 0 replies; 6+ messages in thread
From: Chaehyun Lim @ 2015-07-23 11:19 UTC (permalink / raw)
  To: gregkh
  Cc: johnny.kim, rachel.kim, dean.lee, chris.park, linux-wireless,
	devel, Chaehyun Lim

Return -ENOMEM if memory allocation is failed.

Signed-off-by: Chaehyun Lim <chaehyun.lim@gmail.com>
---
 drivers/staging/wilc1000/coreconfigurator.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/wilc1000/coreconfigurator.c b/drivers/staging/wilc1000/coreconfigurator.c
index b51c15f..eca21bf 100644
--- a/drivers/staging/wilc1000/coreconfigurator.c
+++ b/drivers/staging/wilc1000/coreconfigurator.c
@@ -675,11 +675,8 @@ s32 CoreConfiguratorInit(void)
 	sema_init(&SemHandlePktResp, 0);
 
 	gps8ConfigPacket = kmalloc(MAX_PACKET_BUFF_SIZE, GFP_ATOMIC);
-	if (gps8ConfigPacket == NULL) {
-		PRINT_ER("failed in gps8ConfigPacket allocation\n");
-		s32Error = WILC_NO_MEM;
-		goto _fail_;
-	}
+	if (gps8ConfigPacket == NULL)
+		return -ENOMEM;
 
 	WILC_memset((void *)gps8ConfigPacket, 0, MAX_PACKET_BUFF_SIZE);
 
@@ -1032,10 +1029,8 @@ s32 ParseSurveyResults(u8 ppu8RcvdSiteSurveyResults[][MAX_SURVEY_RESULT_FRAG_SIZ
 
 	pstrSurveyResults = kmalloc_array(u32SurveyResultsCount,
 				sizeof(wid_site_survey_reslts_s), GFP_ATOMIC);
-	if (pstrSurveyResults == NULL) {
-		u32SurveyResultsCount = 0;
-		WILC_ERRORREPORT(s32Error, WILC_NO_MEM);
-	}
+	if (pstrSurveyResults == NULL)
+		return -ENOMEM;
 
 	WILC_memset((void *)(pstrSurveyResults), 0, u32SurveyResultsCount * sizeof(wid_site_survey_reslts_s));
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] staging: wilc1000: coreconfigurator.c: add kmalloc error check
  2015-07-23 11:19 ` [PATCH 2/3] staging: wilc1000: coreconfigurator.c: add kmalloc error check Chaehyun Lim
@ 2015-07-23 11:31   ` Dan Carpenter
  2015-07-23 17:19   ` Joe Perches
  1 sibling, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2015-07-23 11:31 UTC (permalink / raw)
  To: Chaehyun Lim
  Cc: gregkh, rachel.kim, dean.lee, chris.park, devel, linux-wireless,
	johnny.kim

On Thu, Jul 23, 2015 at 08:19:18PM +0900, Chaehyun Lim wrote:
> Add error check if memory allocation is failed.
> 
> Signed-off-by: Chaehyun Lim <chaehyun.lim@gmail.com>
> ---
>  drivers/staging/wilc1000/coreconfigurator.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/staging/wilc1000/coreconfigurator.c b/drivers/staging/wilc1000/coreconfigurator.c
> index 7e2b2ab41..b51c15f 100644
> --- a/drivers/staging/wilc1000/coreconfigurator.c
> +++ b/drivers/staging/wilc1000/coreconfigurator.c
> @@ -812,6 +812,9 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
>  		u32 u32Tsf_Hi;
>  
>  		pstrNetworkInfo = kmalloc(sizeof(tstrNetworkInfo), GFP_ATOMIC);
> +		if (pstrNetworkInfo == NULL)
> +			return -ENOMEM;

Run your patches through checkpatch.pl --strict.  These days we prefer:

		if (!pstrNetworkInfo)
			return -ENOMEM;

These patches are nice otherwise.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] staging: wilc1000: coreconfigurator.c: add kmalloc error check
  2015-07-23 11:19 ` [PATCH 2/3] staging: wilc1000: coreconfigurator.c: add kmalloc error check Chaehyun Lim
  2015-07-23 11:31   ` Dan Carpenter
@ 2015-07-23 17:19   ` Joe Perches
  1 sibling, 0 replies; 6+ messages in thread
From: Joe Perches @ 2015-07-23 17:19 UTC (permalink / raw)
  To: Chaehyun Lim
  Cc: gregkh, johnny.kim, rachel.kim, dean.lee, chris.park,
	linux-wireless, devel

On Thu, 2015-07-23 at 20:19 +0900, Chaehyun Lim wrote:
> Add error check if memory allocation is failed.

trivia:

> diff --git a/drivers/staging/wilc1000/coreconfigurator.c b/drivers/staging/wilc1000/coreconfigurator.c
[]
> @@ -812,6 +812,9 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
>  		u32 u32Tsf_Hi;
>  
>  		pstrNetworkInfo = kmalloc(sizeof(tstrNetworkInfo), GFP_ATOMIC);
> +		if (pstrNetworkInfo == NULL)
> +			return -ENOMEM;
> +
>  		WILC_memset((void *)(pstrNetworkInfo), 0, sizeof(tstrNetworkInfo));
>  
>  		pstrNetworkInfo->s8rssi = pu8WidVal[0];
> @@ -863,6 +866,9 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
>  
>  		if (u16IEsLen > 0) {
>  			pstrNetworkInfo->pu8IEs = kmalloc(u16IEsLen, GFP_ATOMIC);
> +			if (pstrNetworkInfo->pu8IEs == NULL)
> +				return -ENOMEM;
> +
>  			WILC_memset((void *)(pstrNetworkInfo->pu8IEs), 0, u16IEsLen);
>  
>  			WILC_memcpy(pstrNetworkInfo->pu8IEs, pu8IEs, u16IEsLen);
> @@ -930,6 +936,9 @@ s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
>  	u16 u16IEsLen = 0;
>  
>  	pstrConnectRespInfo = kmalloc(sizeof(tstrConnectRespInfo), GFP_ATOMIC);
> +	if (pstrConnectRespInfo == NULL)
> +		return -ENOMEM;
> +
>  	WILC_memset((void *)(pstrConnectRespInfo), 0, sizeof(tstrConnectRespInfo));
>  
>  	/* u16AssocRespLen = pu8Buffer[0]; */

These could use kzalloc

> @@ -950,6 +959,9 @@ s32 ParseAssocRespInfo(u8 *pu8Buffer, u32 u32BufferLen,
>  		u16IEsLen = u16AssocRespLen - (CAP_INFO_LEN + STATUS_CODE_LEN + AID_LEN);
>  
>  		pstrConnectRespInfo->pu8RespIEs = kmalloc(u16IEsLen, GFP_ATOMIC);
> +		if (pstrConnectRespInfo->pu8RespIEs == NULL)
> +			return -ENOMEM;
> +
>  		WILC_memset((void *)(pstrConnectRespInfo->pu8RespIEs), 0, u16IEsLen);
>  
>  		WILC_memcpy(pstrConnectRespInfo->pu8RespIEs, pu8IEs, u16IEsLen);

And this one could use kmemdup



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] staging: wilc1000: coreconfigurator.c: remove WILC_MALLOC
  2015-07-23 11:19 [PATCH 1/3] staging: wilc1000: coreconfigurator.c: remove WILC_MALLOC Chaehyun Lim
  2015-07-23 11:19 ` [PATCH 2/3] staging: wilc1000: coreconfigurator.c: add kmalloc error check Chaehyun Lim
  2015-07-23 11:19 ` [PATCH 3/3] staging: wilc1000: coreconfigurator.c: fix " Chaehyun Lim
@ 2015-07-23 21:52 ` Greg KH
  2 siblings, 0 replies; 6+ messages in thread
From: Greg KH @ 2015-07-23 21:52 UTC (permalink / raw)
  To: Chaehyun Lim
  Cc: rachel.kim, dean.lee, chris.park, devel, linux-wireless,
	johnny.kim

On Thu, Jul 23, 2015 at 08:19:17PM +0900, Chaehyun Lim wrote:
> Use kmalloc and kmalloc_array instead of WILC_MALLOC.
> 
> Signed-off-by: Chaehyun Lim <chaehyun.lim@gmail.com>
> ---
>  drivers/staging/wilc1000/coreconfigurator.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/staging/wilc1000/coreconfigurator.c b/drivers/staging/wilc1000/coreconfigurator.c
> index b069614..7e2b2ab41 100644
> --- a/drivers/staging/wilc1000/coreconfigurator.c
> +++ b/drivers/staging/wilc1000/coreconfigurator.c
> @@ -674,7 +674,7 @@ s32 CoreConfiguratorInit(void)
>  	sema_init(&SemHandleSendPkt, 1);
>  	sema_init(&SemHandlePktResp, 0);
>  
> -	gps8ConfigPacket = (s8 *)WILC_MALLOC(MAX_PACKET_BUFF_SIZE);
> +	gps8ConfigPacket = kmalloc(MAX_PACKET_BUFF_SIZE, GFP_ATOMIC);

I know this is what WILC_MALLOC() did, but should this really be
GFP_ATOMIC?

>  	if (gps8ConfigPacket == NULL) {
>  		PRINT_ER("failed in gps8ConfigPacket allocation\n");
>  		s32Error = WILC_NO_MEM;
> @@ -811,7 +811,7 @@ s32 ParseNetworkInfo(u8 *pu8MsgBuffer, tstrNetworkInfo **ppstrNetworkInfo)
>  		u32 u32Tsf_Lo;
>  		u32 u32Tsf_Hi;
>  
> -		pstrNetworkInfo = (tstrNetworkInfo *)WILC_MALLOC(sizeof(tstrNetworkInfo));
> +		pstrNetworkInfo = kmalloc(sizeof(tstrNetworkInfo), GFP_ATOMIC);

Same here.  And everywhere else you changed this code, please review and
resend.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-07-23 21:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-23 11:19 [PATCH 1/3] staging: wilc1000: coreconfigurator.c: remove WILC_MALLOC Chaehyun Lim
2015-07-23 11:19 ` [PATCH 2/3] staging: wilc1000: coreconfigurator.c: add kmalloc error check Chaehyun Lim
2015-07-23 11:31   ` Dan Carpenter
2015-07-23 17:19   ` Joe Perches
2015-07-23 11:19 ` [PATCH 3/3] staging: wilc1000: coreconfigurator.c: fix " Chaehyun Lim
2015-07-23 21:52 ` [PATCH 1/3] staging: wilc1000: coreconfigurator.c: remove WILC_MALLOC Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).