2017-09-14 12:48:20

by Srishti Sharma

[permalink] [raw]
Subject: [PATCH v2] Staging: ccree: Use kcalloc instead of kzalloc

Use kcalloc instead of kzalloc to check for overflow before
multiplication. Done using the following semantic patch by
coccinelle.

http://coccinelle.lip6.fr/rules/kzalloc.cocci

Signed-off-by: Srishti Sharma <[email protected]>
---
Changes in v2:
- eliminate parentheses around the first argument

drivers/staging/ccree/ssi_sysfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/ccree/ssi_sysfs.c b/drivers/staging/ccree/ssi_sysfs.c
index 0655658..f7e0c502 100644
--- a/drivers/staging/ccree/ssi_sysfs.c
+++ b/drivers/staging/ccree/ssi_sysfs.c
@@ -376,7 +376,7 @@ static int sys_init_dir(struct sys_dir *sys_dir, struct ssi_drvdata *drvdata,
return -ENOMEM;
/* allocate memory for directory's attributes list */
sys_dir->sys_dir_attr_list =
- kzalloc(sizeof(struct attribute *) * (num_of_attrs + 1),
+ kcalloc(num_of_attrs + 1, sizeof(struct attribute *),
GFP_KERNEL);

if (!(sys_dir->sys_dir_attr_list)) {
--
2.7.4


2017-09-14 12:55:19

by Julia Lawall

[permalink] [raw]
Subject: Re: [Outreachy kernel] [PATCH v2] Staging: ccree: Use kcalloc instead of kzalloc



On Thu, 14 Sep 2017, Srishti Sharma wrote:

> Use kcalloc instead of kzalloc to check for overflow before
> multiplication. Done using the following semantic patch by
> coccinelle.
>
> http://coccinelle.lip6.fr/rules/kzalloc.cocci
>
> Signed-off-by: Srishti Sharma <[email protected]>

Acked-by: Julia Lawall <[email protected]>

> ---
> Changes in v2:
> - eliminate parentheses around the first argument
>
> drivers/staging/ccree/ssi_sysfs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/ccree/ssi_sysfs.c b/drivers/staging/ccree/ssi_sysfs.c
> index 0655658..f7e0c502 100644
> --- a/drivers/staging/ccree/ssi_sysfs.c
> +++ b/drivers/staging/ccree/ssi_sysfs.c
> @@ -376,7 +376,7 @@ static int sys_init_dir(struct sys_dir *sys_dir, struct ssi_drvdata *drvdata,
> return -ENOMEM;
> /* allocate memory for directory's attributes list */
> sys_dir->sys_dir_attr_list =
> - kzalloc(sizeof(struct attribute *) * (num_of_attrs + 1),
> + kcalloc(num_of_attrs + 1, sizeof(struct attribute *),
> GFP_KERNEL);
>
> if (!(sys_dir->sys_dir_attr_list)) {
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1505393293-5941-1-git-send-email-srishtishar%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>