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


Groups > linux.kernel > #1476002 > unrolled thread

[PATCH] x86/amd_nb: Use kmalloc_array() in amd_cache_gart()

Started bySF Markus Elfring <elfring@users.sourceforge.net>
First post2016-09-04 21:20 +0200
Last post2016-09-04 21:30 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] x86/amd_nb: Use kmalloc_array() in amd_cache_gart() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-04 21:20 +0200
    Re: [PATCH] x86/amd_nb: Use kmalloc_array() in amd_cache_gart() Joe Perches <joe@perches.com> - 2016-09-04 21:30 +0200

#1476002 — [PATCH] x86/amd_nb: Use kmalloc_array() in amd_cache_gart()

FromSF Markus Elfring <elfring@users.sourceforge.net>
Date2016-09-04 21:20 +0200
Subject[PATCH] x86/amd_nb: Use kmalloc_array() in amd_cache_gart()
Message-ID<sdL7s-1tY-3@gated-at.bofh.it>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sun, 4 Sep 2016 21:01:47 +0200

* 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 type 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>
---
 arch/x86/kernel/amd_nb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index 4fdf623..e2e3e8a 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -226,7 +226,9 @@ static void amd_cache_gart(void)
 	if (!amd_nb_has_feature(AMD_NB_GART))
 		return;
 
-	flush_words = kmalloc(amd_nb_num() * sizeof(u32), GFP_KERNEL);
+	flush_words = kmalloc_array(amd_nb_num(),
+				    sizeof(*flush_words),
+				    GFP_KERNEL);
 	if (!flush_words) {
 		amd_northbridges.flags &= ~AMD_NB_GART;
 		pr_notice("Cannot initialize GART flush words, GART support disabled\n");
-- 
2.9.3

[toc] | [next] | [standalone]


#1476003

FromJoe Perches <joe@perches.com>
Date2016-09-04 21:30 +0200
Message-ID<sdLh7-1yo-5@gated-at.bofh.it>
In reply to#1476002
On Sun, 2016-09-04 at 21:08 +0200, SF Markus Elfring wrote:

> * 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 type by a pointer dereference
>   to make the corresponding size determination a bit safer according to
>   the Linux coding style convention.
[]
> diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
[]
> @@ -226,7 +226,9 @@ static void amd_cache_gart(void)
>  	if (!amd_nb_has_feature(AMD_NB_GART))
>  		return;
>  
> -	flush_words = kmalloc(amd_nb_num() * sizeof(u32), GFP_KERNEL);
> +	flush_words = kmalloc_array(amd_nb_num(),
> +				    sizeof(*flush_words),
> +				    GFP_KERNEL);

Markus, this sort of change really isn't very useful.

amd_nb_num is a u16 and is really just a count of
northbridges in the system.

It'll never be a particular high number that could
possibly overflow a size_t of num * sizeof(u32).

Detecting an inconsistency is different than an issue
that has any real significance.

Please stop blindly converting these from one form to
another.  Please inspect these potential changes
first and find instances where this conversion could
actually matter before sending auto-generated patches.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web