Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1500418 > unrolled thread

[PATCH 01/18] [media] RedRat3: Use kcalloc() in two functions

Started bySF Markus Elfring <elfring@users.sourceforge.net>
First post2016-10-13 18:30 +0200
Last post2016-10-14 07:50 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 01/18] [media] RedRat3: Use kcalloc() in two functions SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-13 18:30 +0200
    Re: [PATCH 01/18] [media] RedRat3: Use kcalloc() in two functions Joe Perches <joe@perches.com> - 2016-10-13 18:40 +0200
      Re: [media] RedRat3: Use kcalloc() in two functions? SF Markus Elfring <elfring@users.sourceforge.net> - 2016-10-14 07:50 +0200

#1500418 — [PATCH 01/18] [media] RedRat3: Use kcalloc() in two functions

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-13 18:30 +0200
Subject[PATCH 01/18] [media] RedRat3: Use kcalloc() in two functions
Message-ID<srR3j-5Qh-15@gated-at.bofh.it>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 13 Oct 2016 08:35:57 +0200

* Multiplications for the size determination of memory allocations
  indicated that array data structures should be processed.
  Thus use the corresponding function "kcalloc".

  This issue was detected by using the Coccinelle software.

* Replace the specification of data types by pointer dereferences
  to make the corresponding size determination a bit safer according to
  the Linux coding style convention.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/media/rc/redrat3.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
index 8d7df6d..d89958b 100644
--- a/drivers/media/rc/redrat3.c
+++ b/drivers/media/rc/redrat3.c
@@ -549,7 +549,7 @@ static void redrat3_get_firmware_rev(struct redrat3_dev *rr3)
 	int rc = 0;
 	char *buffer;
 
-	buffer = kzalloc(sizeof(char) * (RR3_FW_VERSION_LEN + 1), GFP_KERNEL);
+	buffer = kcalloc(RR3_FW_VERSION_LEN + 1, sizeof(*buffer), GFP_KERNEL);
 	if (!buffer) {
 		dev_err(rr3->dev, "Memory allocation failure\n");
 		return;
@@ -741,7 +741,9 @@ static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
 	/* rr3 will disable rc detector on transmit */
 	rr3->transmitting = true;
 
-	sample_lens = kzalloc(sizeof(int) * RR3_DRIVER_MAXLENS, GFP_KERNEL);
+	sample_lens = kcalloc(RR3_DRIVER_MAXLENS,
+			      sizeof(*sample_lens),
+			      GFP_KERNEL);
 	if (!sample_lens) {
 		ret = -ENOMEM;
 		goto out;
-- 
2.10.1

[toc] | [next] | [standalone]


#1500438

FromJoe Perches <joe@perches.com>
Date2016-10-13 18:40 +0200
Message-ID<srRcZ-5TH-13@gated-at.bofh.it>
In reply to#1500418
On Thu, 2016-10-13 at 18:18 +0200, SF Markus Elfring wrote:
> diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
[]
> @@ -549,7 +549,7 @@ static void redrat3_get_firmware_rev(struct redrat3_dev *rr3)
>  	int rc = 0;
>  	char *buffer;
>  
> -	buffer = kzalloc(sizeof(char) * (RR3_FW_VERSION_LEN + 1), GFP_KERNEL);
> +	buffer = kcalloc(RR3_FW_VERSION_LEN + 1, sizeof(*buffer), GFP_KERNEL);
>  	if (!buffer) {
>  		dev_err(rr3->dev, "Memory allocation failure\n");
>  		return;,

Markus, please stop being _so_ mechanical and use your
brain a little too.  By definition, sizeof(char) == 1.

This _really_ should be kzalloc(RR3_FW_VERSION_LEN + 1,...)

[toc] | [prev] | [next] | [standalone]


#1500702 — Re: [media] RedRat3: Use kcalloc() in two functions?

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-10-14 07:50 +0200
SubjectRe: [media] RedRat3: Use kcalloc() in two functions?
Message-ID<ss3xv-5Bi-11@gated-at.bofh.it>
In reply to#1500438
> Markus, please stop being _so_ mechanical and use your
> brain a little too.  By definition, sizeof(char) == 1.
> 
> This _really_ should be kzalloc(RR3_FW_VERSION_LEN + 1,...)

Do you expect that function call examples like the following will be equivalent?

	zbuffer = kzalloc(123, …);
	cbuffer = kcalloc(123, 1, …);

Regards,
Markus

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web