diff mbox

[OPW,kernel] Staging:vt6656: Replace some kzalloc calls with kcalloc in iwctl.c

Message ID 20140308160536.GA15781@winterfell
State New, archived
Headers show

Commit Message

Iulia Manda March 8, 2014, 4:05 p.m. UTC
This replacement is justified by the fact that kcalloc could prevent integer
overflow resulted from the multiplications used in kzalloc.

The semantic patch that showed this suggestion is kzalloc.cocci 

Signed-off-by: Iulia Manda <iulia.manda21@gmail.com>
---
 drivers/staging/vt6656/iwctl.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Nick Kossifidis March 13, 2014, 4:18 p.m. UTC | #1
2014-03-08 16:05 GMT+00:00 Iulia Manda <iulia.manda21@gmail.com>:
> This replacement is justified by the fact that kcalloc could prevent integer
> overflow resulted from the multiplications used in kzalloc.
>
> The semantic patch that showed this suggestion is kzalloc.cocci
>
> Signed-off-by: Iulia Manda <iulia.manda21@gmail.com>

Acked-by: Nick Kossifidis <mickflemm@gmail.com>
Waskiewicz Jr, Peter P March 17, 2014, 12:37 a.m. UTC | #2
On Sat, 2014-03-08 at 18:05 +0200, Iulia Manda wrote:
> This replacement is justified by the fact that kcalloc could prevent integer
> overflow resulted from the multiplications used in kzalloc.
> 
> The semantic patch that showed this suggestion is kzalloc.cocci 
> 
> Signed-off-by: Iulia Manda <iulia.manda21@gmail.com>

This was also applied earlier.

> ---
>  drivers/staging/vt6656/iwctl.c |    4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/vt6656/iwctl.c b/drivers/staging/vt6656/iwctl.c
> index 60264a6..bedc810 100644
> --- a/drivers/staging/vt6656/iwctl.c
> +++ b/drivers/staging/vt6656/iwctl.c
> @@ -725,10 +725,10 @@ int iwctl_giwaplist(struct net_device *dev, struct iw_request_info *info,
>  	if (!wrq->pointer)
>  		return -EINVAL;
>  
> -	sock = kzalloc(sizeof(struct sockaddr) * IW_MAX_AP, GFP_KERNEL);
> +	sock = kcalloc(IW_MAX_AP, sizeof(struct sockaddr), GFP_KERNEL);
>  	if (sock == NULL)
>  		return -ENOMEM;
> -	qual = kzalloc(sizeof(struct iw_quality) * IW_MAX_AP, GFP_KERNEL);
> +	qual = kcalloc(IW_MAX_AP, sizeof(struct iw_quality), GFP_KERNEL);
>  	if (qual == NULL) {
>  		kfree(sock);
>  		return -ENOMEM;
> -- 
> 1.7.10.4
>
diff mbox

Patch

diff --git a/drivers/staging/vt6656/iwctl.c b/drivers/staging/vt6656/iwctl.c
index 60264a6..bedc810 100644
--- a/drivers/staging/vt6656/iwctl.c
+++ b/drivers/staging/vt6656/iwctl.c
@@ -725,10 +725,10 @@  int iwctl_giwaplist(struct net_device *dev, struct iw_request_info *info,
 	if (!wrq->pointer)
 		return -EINVAL;
 
-	sock = kzalloc(sizeof(struct sockaddr) * IW_MAX_AP, GFP_KERNEL);
+	sock = kcalloc(IW_MAX_AP, sizeof(struct sockaddr), GFP_KERNEL);
 	if (sock == NULL)
 		return -ENOMEM;
-	qual = kzalloc(sizeof(struct iw_quality) * IW_MAX_AP, GFP_KERNEL);
+	qual = kcalloc(IW_MAX_AP, sizeof(struct iw_quality), GFP_KERNEL);
 	if (qual == NULL) {
 		kfree(sock);
 		return -ENOMEM;