All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] AMD Microcode: Prefer vzalloc() over calls to vmalloc()+memset()
@ 2010-10-30 19:23 Jesper Juhl
  2010-10-31 10:08 ` Borislav Petkov
  0 siblings, 1 reply; 6+ messages in thread
From: Jesper Juhl @ 2010-10-30 19:23 UTC (permalink / raw)
  To: linux-kernel; +Cc: Peter Oruba, Andreas Herrmann, amd64-microcode

Hi,

We don't have to do memset() ourselves after vmalloc() when we have 
vzalloc(), so change that in 
arch/x86/kernel/microcode_amd.c::get_next_ucode().

Please CC me on replies.


Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
compile tested only.

 microcode_amd.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
index e1af7c0..d46e805 100644
--- a/arch/x86/kernel/microcode_amd.c
+++ b/arch/x86/kernel/microcode_amd.c
@@ -183,9 +183,8 @@ get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size)
 		return NULL;
 	}
 
-	mc = vmalloc(UCODE_MAX_SIZE);
+	mc = vzalloc(UCODE_MAX_SIZE);
 	if (mc) {
-		memset(mc, 0, UCODE_MAX_SIZE);
 		if (get_ucode_data(mc, buf + UCODE_CONTAINER_SECTION_HDR,
 				   total_size)) {
 			vfree(mc);


-- 
Jesper Juhl <jj@chaosbits.net>             http://www.chaosbits.net/
Plain text mails only, please      http://www.expita.com/nomime.html
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html


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

* Re: [PATCH] AMD Microcode: Prefer vzalloc() over calls to vmalloc()+memset()
  2010-10-30 19:23 [PATCH] AMD Microcode: Prefer vzalloc() over calls to vmalloc()+memset() Jesper Juhl
@ 2010-10-31 10:08 ` Borislav Petkov
  2010-11-01 19:23   ` Jesper Juhl
  0 siblings, 1 reply; 6+ messages in thread
From: Borislav Petkov @ 2010-10-31 10:08 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: linux-kernel, Peter Oruba, Andreas Herrmann, amd64-microcode

On Sat, Oct 30, 2010 at 09:23:14PM +0200, Jesper Juhl wrote:
> We don't have to do memset() ourselves after vmalloc() when we have 
> vzalloc(), so change that in 
> arch/x86/kernel/microcode_amd.c::get_next_ucode().
> 
> Please CC me on replies.
> 
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> ---
> compile tested only.
> 
>  microcode_amd.c |    3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
> index e1af7c0..d46e805 100644
> --- a/arch/x86/kernel/microcode_amd.c
> +++ b/arch/x86/kernel/microcode_amd.c
> @@ -183,9 +183,8 @@ get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size)
>  		return NULL;
>  	}
>  
> -	mc = vmalloc(UCODE_MAX_SIZE);
> +	mc = vzalloc(UCODE_MAX_SIZE);
>  	if (mc) {
> -		memset(mc, 0, UCODE_MAX_SIZE);
>  		if (get_ucode_data(mc, buf + UCODE_CONTAINER_SECTION_HDR,
>  				   total_size)) {
>  			vfree(mc);

Good.

Better yet, you can go a step further and remove one indentation block:

--
	mc = vzalloc(UCODE_MAX_SIZE);
	if (!mc)
		goto out;

	if (get_ucode_data(mc, ...
	...

out:
	return mc;

}
--
making the code even fit in 80 chars width and thus more readable.

Thanks.

-- 
Regards/Gruss,
    Boris.

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

* Re: [PATCH] AMD Microcode: Prefer vzalloc() over calls to vmalloc()+memset()
  2010-10-31 10:08 ` Borislav Petkov
@ 2010-11-01 19:23   ` Jesper Juhl
  2010-11-01 21:27     ` Borislav Petkov
  0 siblings, 1 reply; 6+ messages in thread
From: Jesper Juhl @ 2010-11-01 19:23 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: linux-kernel, Peter Oruba, Andreas Herrmann, amd64-microcode

On Sun, 31 Oct 2010, Borislav Petkov wrote:

> On Sat, Oct 30, 2010 at 09:23:14PM +0200, Jesper Juhl wrote:
> > We don't have to do memset() ourselves after vmalloc() when we have 
> > vzalloc(), so change that in 
> > arch/x86/kernel/microcode_amd.c::get_next_ucode().
> > 
> > Please CC me on replies.
> > 
> > 
> > Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> > ---
> > compile tested only.
> > 
> >  microcode_amd.c |    3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> > 
> > diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
> > index e1af7c0..d46e805 100644
> > --- a/arch/x86/kernel/microcode_amd.c
> > +++ b/arch/x86/kernel/microcode_amd.c
> > @@ -183,9 +183,8 @@ get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size)
> >  		return NULL;
> >  	}
> >  
> > -	mc = vmalloc(UCODE_MAX_SIZE);
> > +	mc = vzalloc(UCODE_MAX_SIZE);
> >  	if (mc) {
> > -		memset(mc, 0, UCODE_MAX_SIZE);
> >  		if (get_ucode_data(mc, buf + UCODE_CONTAINER_SECTION_HDR,
> >  				   total_size)) {
> >  			vfree(mc);
> 
> Good.
> 
> Better yet, you can go a step further and remove one indentation block:
> 
> --
> 	mc = vzalloc(UCODE_MAX_SIZE);
> 	if (!mc)
> 		goto out;
> 
> 	if (get_ucode_data(mc, ...
> 	...
> 
> out:
> 	return mc;
> 
> }
> --
> making the code even fit in 80 chars width and thus more readable.
> 
> Thanks.
> 
Thank you for the feedback I'll prepare a new version of the patch 
incorporating it, then resend it. 

One thing I'm not entirely sure about though is how to credit you with 
your improment to my original patch. Would I simply prepend

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Signed-off-by: Borislav Petkov <bp@alien8.de>

or should I leave just my own Signed-off-by: and then mention you in the 
changelog part of the mail or? 

-- 
Jesper Juhl <jj@chaosbits.net>             http://www.chaosbits.net/
Plain text mails only, please      http://www.expita.com/nomime.html
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html


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

* Re: [PATCH] AMD Microcode: Prefer vzalloc() over calls to vmalloc()+memset()
  2010-11-01 19:23   ` Jesper Juhl
@ 2010-11-01 21:27     ` Borislav Petkov
  2010-11-01 21:44       ` [PATCH v2] " Jesper Juhl
  0 siblings, 1 reply; 6+ messages in thread
From: Borislav Petkov @ 2010-11-01 21:27 UTC (permalink / raw)
  To: Jesper Juhl; +Cc: linux-kernel, Peter Oruba, Andreas Herrmann, amd64-microcode

On Mon, Nov 01, 2010 at 08:23:23PM +0100, Jesper Juhl wrote:
> Thank you for the feedback I'll prepare a new version of the patch 
> incorporating it, then resend it. 
> 
> One thing I'm not entirely sure about though is how to credit you with 
> your improment to my original patch. Would I simply prepend
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> Signed-off-by: Borislav Petkov <bp@alien8.de>
> 
> or should I leave just my own Signed-off-by: and then mention you in the 
> changelog part of the mail or? 

How very considerate of you, but no need. Simply put your SOB in and
I'll ack it.

Thanks.

-- 
Regards/Gruss,
    Boris.

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

* [PATCH v2] AMD Microcode: Prefer vzalloc() over calls to vmalloc()+memset().
  2010-11-01 21:27     ` Borislav Petkov
@ 2010-11-01 21:44       ` Jesper Juhl
  2010-11-02 17:51         ` Borislav Petkov
  0 siblings, 1 reply; 6+ messages in thread
From: Jesper Juhl @ 2010-11-01 21:44 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: linux-kernel, Peter Oruba, Andreas Herrmann, amd64-microcode

On Mon, 1 Nov 2010, Borislav Petkov wrote:

> On Mon, Nov 01, 2010 at 08:23:23PM +0100, Jesper Juhl wrote:
> > Thank you for the feedback I'll prepare a new version of the patch 
> > incorporating it, then resend it. 
> > 
> > One thing I'm not entirely sure about though is how to credit you with 
> > your improment to my original patch. Would I simply prepend
> > 
> > Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> > Signed-off-by: Borislav Petkov <bp@alien8.de>
> > 
> > or should I leave just my own Signed-off-by: and then mention you in the 
> > changelog part of the mail or? 
> 
> How very considerate of you, but no need. Simply put your SOB in and
> I'll ack it.
> 
Ok. I just care a great deal about assigning credit where due, since for 
some of us (me included) the only credit we ever get for our work is the 
small credit attributed to us via the SOB or similar... But, I'll just 
(almost) respin the patch with just my own SOB below.



We don't have to do memset() ourselves after vmalloc() when we have 
vzalloc(), so change that in 
arch/x86/kernel/microcode_amd.c::get_next_ucode().
Thanks to Borislav Petkov for improvement suggestions.


Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 microcode_amd.c |   19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/arch/x86/kernel/microcode_amd.c b/arch/x86/kernel/microcode_amd.c
index e1af7c0..383d4f8 100644
--- a/arch/x86/kernel/microcode_amd.c
+++ b/arch/x86/kernel/microcode_amd.c
@@ -183,16 +183,17 @@ get_next_ucode(const u8 *buf, unsigned int size, unsigned int *mc_size)
 		return NULL;
 	}
 
-	mc = vmalloc(UCODE_MAX_SIZE);
-	if (mc) {
-		memset(mc, 0, UCODE_MAX_SIZE);
-		if (get_ucode_data(mc, buf + UCODE_CONTAINER_SECTION_HDR,
-				   total_size)) {
-			vfree(mc);
-			mc = NULL;
-		} else
-			*mc_size = total_size + UCODE_CONTAINER_SECTION_HDR;
+	mc = vzalloc(UCODE_MAX_SIZE);
+	if (!mc)
+		return NULL;
+
+	if (get_ucode_data(mc, buf + UCODE_CONTAINER_SECTION_HDR, total_size)) {
+		vfree(mc);
+		mc = NULL;
+	} else {
+		*mc_size = total_size + UCODE_CONTAINER_SECTION_HDR;
 	}
+
 	return mc;
 }
 


-- 
Jesper Juhl <jj@chaosbits.net>             http://www.chaosbits.net/
Plain text mails only, please      http://www.expita.com/nomime.html
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html


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

* Re: [PATCH v2] AMD Microcode: Prefer vzalloc() over calls to vmalloc()+memset().
  2010-11-01 21:44       ` [PATCH v2] " Jesper Juhl
@ 2010-11-02 17:51         ` Borislav Petkov
  0 siblings, 0 replies; 6+ messages in thread
From: Borislav Petkov @ 2010-11-02 17:51 UTC (permalink / raw)
  To: Jesper Juhl
  Cc: Borislav Petkov, linux-kernel, Andreas Herrmann, amd64-microcode

On Mon, Nov 01, 2010 at 10:44:34PM +0100, Jesper Juhl wrote:
> We don't have to do memset() ourselves after vmalloc() when we have 
> vzalloc(), so change that in 
> arch/x86/kernel/microcode_amd.c::get_next_ucode().
> Thanks to Borislav Petkov for improvement suggestions.
> 
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>

Acked-by: Borislav Petkov <borislav.petkov@amd.com>

-- 
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632


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

end of thread, other threads:[~2010-11-02 17:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-30 19:23 [PATCH] AMD Microcode: Prefer vzalloc() over calls to vmalloc()+memset() Jesper Juhl
2010-10-31 10:08 ` Borislav Petkov
2010-11-01 19:23   ` Jesper Juhl
2010-11-01 21:27     ` Borislav Petkov
2010-11-01 21:44       ` [PATCH v2] " Jesper Juhl
2010-11-02 17:51         ` Borislav Petkov

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.