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


Groups > linux.kernel > #1556905 > unrolled thread

[PATCH 01/18] mtd-cfi_cmdset_0001: Use kmalloc_array() in cfi_intelext_partition_fixup()

Started bySF Markus Elfring <elfring@users.sourceforge.net>
First post2017-01-11 21:40 +0100
Last post2017-01-11 23:10 +0100
Articles 2 — 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] mtd-cfi_cmdset_0001: Use kmalloc_array() in  cfi_intelext_partition_fixup() SF Markus Elfring <elfring@users.sourceforge.net> - 2017-01-11 21:40 +0100
    Re: [PATCH 01/18] mtd-cfi_cmdset_0001: Use kmalloc_array() in  cfi_intelext_partition_fixup() Marek Vasut <marek.vasut@gmail.com> - 2017-01-11 23:10 +0100

#1556905 — [PATCH 01/18] mtd-cfi_cmdset_0001: Use kmalloc_array() in cfi_intelext_partition_fixup()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2017-01-11 21:40 +0100
Subject[PATCH 01/18] mtd-cfi_cmdset_0001: Use kmalloc_array() in cfi_intelext_partition_fixup()
Message-ID<sYxQC-34a-31@gated-at.bofh.it>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 10 Jan 2017 18:48:34 +0100

* A multiplication for the size determination of a memory allocation
  indicated that an array data structure should be processed.
  Thus use the corresponding function "kmalloc_array".

  This issue was detected by using the Coccinelle software.

* Replace the specification of a data structure by a pointer dereference
  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/mtd/chips/cfi_cmdset_0001.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index 5e1b68cbcd0a..68227aa74d22 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -746,7 +746,9 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
 		newcfi = kmalloc(sizeof(struct cfi_private) + numvirtchips * sizeof(struct flchip), GFP_KERNEL);
 		if (!newcfi)
 			return -ENOMEM;
-		shared = kmalloc(sizeof(struct flchip_shared) * cfi->numchips, GFP_KERNEL);
+		shared = kmalloc_array(cfi->numchips,
+				       sizeof(*shared),
+				       GFP_KERNEL);
 		if (!shared) {
 			kfree(newcfi);
 			return -ENOMEM;
-- 
2.11.0

[toc] | [next] | [standalone]


#1556973

FromMarek Vasut <marek.vasut@gmail.com>
Date2017-01-11 23:10 +0100
Message-ID<sYzfH-42A-3@gated-at.bofh.it>
In reply to#1556905
On 01/11/2017 09:35 PM, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Tue, 10 Jan 2017 18:48:34 +0100
> 
> * A multiplication for the size determination of a memory allocation
>   indicated that an array data structure should be processed.
>   Thus use the corresponding function "kmalloc_array".
> 
>   This issue was detected by using the Coccinelle software.
> 
> * Replace the specification of a data structure by a pointer dereference
>   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/mtd/chips/cfi_cmdset_0001.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
> index 5e1b68cbcd0a..68227aa74d22 100644
> --- a/drivers/mtd/chips/cfi_cmdset_0001.c
> +++ b/drivers/mtd/chips/cfi_cmdset_0001.c
> @@ -746,7 +746,9 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
>  		newcfi = kmalloc(sizeof(struct cfi_private) + numvirtchips * sizeof(struct flchip), GFP_KERNEL);
>  		if (!newcfi)
>  			return -ENOMEM;
> -		shared = kmalloc(sizeof(struct flchip_shared) * cfi->numchips, GFP_KERNEL);
> +		shared = kmalloc_array(cfi->numchips,
> +				       sizeof(*shared),
> +				       GFP_KERNEL);

You can keep this on a single line, no need for the linebreak. It
doesn't violate the 80-chars per line rule IMO.

>  		if (!shared) {
>  			kfree(newcfi);
>  			return -ENOMEM;
> 


-- 
Best regards,
Marek Vasut

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web