All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] staging: usbip: use kcalloc instead of kzalloc for array allocations
  2014-05-23 10:17 [PATCH] staging: usbip: use kcalloc instead of kzalloc for array allocations Djordje Zekovic
@ 2014-05-23  8:27 ` Richard Weinberger
  2014-05-23 14:18   ` [PATCHv2] " Djordje Zekovic
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Weinberger @ 2014-05-23  8:27 UTC (permalink / raw)
  To: Djordje Zekovic; +Cc: Greg KH, LKML

On Fri, May 23, 2014 at 12:17 PM, Djordje Zekovic <dj@zeko.me> wrote:
> The advantage of kcalloc is, that will prevent integer overflows which could
> result from the multiplication of number of elements and size and it is also
> a bit nicer to read.
>
> Signed-off-by: Djordje Zekovic <dj@zeko.me>
> ---
>  drivers/staging/usbip/stub_tx.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/usbip/stub_tx.c b/drivers/staging/usbip/stub_tx.c
> index 1622563..4994090 100644
> --- a/drivers/staging/usbip/stub_tx.c
> +++ b/drivers/staging/usbip/stub_tx.c
> @@ -179,7 +179,7 @@ static int stub_send_ret_submit(struct stub_device *sdev)
>                 else
>                         iovnum = 2;
>
> -               iov = kzalloc(iovnum * sizeof(struct kvec), GFP_KERNEL);
> +               iov = kcalloc(iovnum * sizeof(struct kvec), GFP_KERNEL);

Does this even build?

static inline void *kcalloc(size_t n, size_t size, gfp_t flags)

-- 
Thanks,
//richard

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

* [PATCH] staging: usbip: use kcalloc instead of kzalloc for array allocations
@ 2014-05-23 10:17 Djordje Zekovic
  2014-05-23  8:27 ` Richard Weinberger
  0 siblings, 1 reply; 4+ messages in thread
From: Djordje Zekovic @ 2014-05-23 10:17 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Djordje Zekovic

The advantage of kcalloc is, that will prevent integer overflows which could
result from the multiplication of number of elements and size and it is also
a bit nicer to read.

Signed-off-by: Djordje Zekovic <dj@zeko.me>
---
 drivers/staging/usbip/stub_tx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/usbip/stub_tx.c b/drivers/staging/usbip/stub_tx.c
index 1622563..4994090 100644
--- a/drivers/staging/usbip/stub_tx.c
+++ b/drivers/staging/usbip/stub_tx.c
@@ -179,7 +179,7 @@ static int stub_send_ret_submit(struct stub_device *sdev)
 		else
 			iovnum = 2;
 
-		iov = kzalloc(iovnum * sizeof(struct kvec), GFP_KERNEL);
+		iov = kcalloc(iovnum * sizeof(struct kvec), GFP_KERNEL);
 
 		if (!iov) {
 			usbip_event_add(&sdev->ud, SDEV_EVENT_ERROR_MALLOC);
-- 
1.8.5.2


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

* [PATCHv2] staging: usbip: use kcalloc instead of kzalloc for array allocations
  2014-05-23  8:27 ` Richard Weinberger
@ 2014-05-23 14:18   ` Djordje Zekovic
  0 siblings, 0 replies; 4+ messages in thread
From: Djordje Zekovic @ 2014-05-23 14:18 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, richard.weinberger, Djordje Zekovic

The advantage of kcalloc is, that will prevent integer overflows which could
result from the multiplication of number of elements and size and it is also
a bit nicer to read.

Signed-off-by: Djordje Zekovic <dj@zeko.me>
---
 v2: Fixed issue regarding kcalloc func signature, noted by 
     Richard Weinberger <richard.weinberger@gmail.com> 

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

diff --git a/drivers/staging/usbip/stub_tx.c b/drivers/staging/usbip/stub_tx.c
index 1622563..f09abb2 100644
--- a/drivers/staging/usbip/stub_tx.c
+++ b/drivers/staging/usbip/stub_tx.c
@@ -179,7 +179,7 @@ static int stub_send_ret_submit(struct stub_device *sdev)
 		else
 			iovnum = 2;
 
-		iov = kzalloc(iovnum * sizeof(struct kvec), GFP_KERNEL);
+		iov = kcalloc(iovnum, sizeof(struct kvec), GFP_KERNEL);
 
 		if (!iov) {
 			usbip_event_add(&sdev->ud, SDEV_EVENT_ERROR_MALLOC);
-- 
1.8.5.2

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

* [PATCH] staging: usbip: use kcalloc instead of kzalloc for array allocations
@ 2014-05-23 12:08 Djordje Zekovic
  0 siblings, 0 replies; 4+ messages in thread
From: Djordje Zekovic @ 2014-05-23 12:08 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, richard.weinberger, Djordje Zekovic

The advantage of kcalloc is, that will prevent integer overflows which could
result from the multiplication of number of elements and size and it is also
a bit nicer to read.

Signed-off-by: Djordje Zekovic <dj@zeko.me>
---
 Fixed: Richard Weinberger <richard.weinberger@gmail.com> pointed to 
 	building issue in his review.
 drivers/staging/usbip/stub_tx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/usbip/stub_tx.c b/drivers/staging/usbip/stub_tx.c
index 1622563..f09abb2 100644
--- a/drivers/staging/usbip/stub_tx.c
+++ b/drivers/staging/usbip/stub_tx.c
@@ -179,7 +179,7 @@ static int stub_send_ret_submit(struct stub_device *sdev)
 		else
 			iovnum = 2;
 
-		iov = kzalloc(iovnum * sizeof(struct kvec), GFP_KERNEL);
+		iov = kcalloc(iovnum, sizeof(struct kvec), GFP_KERNEL);
 
 		if (!iov) {
 			usbip_event_add(&sdev->ud, SDEV_EVENT_ERROR_MALLOC);
-- 
1.8.5.2


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

end of thread, other threads:[~2014-05-23 12:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-23 10:17 [PATCH] staging: usbip: use kcalloc instead of kzalloc for array allocations Djordje Zekovic
2014-05-23  8:27 ` Richard Weinberger
2014-05-23 14:18   ` [PATCHv2] " Djordje Zekovic
2014-05-23 12:08 [PATCH] " Djordje Zekovic

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.