Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86/x86 kmem_free() the address returned by kmem_al...



details:   https://anonhg.NetBSD.org/src/rev/a8cd3dceb768
branches:  trunk
changeset: 340835:a8cd3dceb768
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sun Oct 04 17:52:50 2015 +0000

description:
kmem_free() the address returned by kmem_alloc().  found by Brainy.
use the newly aligned location if we needed it.  found by kre.

diffstat:

 sys/arch/x86/x86/cpu_ucode_intel.c |  15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)

diffs (60 lines):

diff -r 51174fe98f6a -r a8cd3dceb768 sys/arch/x86/x86/cpu_ucode_intel.c
--- a/sys/arch/x86/x86/cpu_ucode_intel.c        Sun Oct 04 12:10:51 2015 +0000
+++ b/sys/arch/x86/x86/cpu_ucode_intel.c        Sun Oct 04 17:52:50 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_ucode_intel.c,v 1.8 2015/05/12 00:00:35 msaitoh Exp $ */
+/* $NetBSD: cpu_ucode_intel.c,v 1.9 2015/10/04 17:52:50 mrg Exp $ */
 /*
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.8 2015/05/12 00:00:35 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_ucode_intel.c,v 1.9 2015/10/04 17:52:50 mrg Exp $");
 
 #include "opt_xen.h"
 #include "opt_cpu_ucode.h"
@@ -111,6 +111,7 @@
        uint32_t ucodetarget, oucodeversion, nucodeversion;
        int platformid;
        struct intel1_ucode_header *uh;
+       void *uha;
        size_t newbufsize = 0;
        int rv = 0;
 
@@ -126,12 +127,12 @@
        if ((uintptr_t)(sc->sc_blob) & 15) {
                /* Make the buffer 16 byte aligned */
                newbufsize = sc->sc_blobsize + 15;
-               uh = kmem_alloc(newbufsize, KM_SLEEP);
-               if (uh == NULL) {
+               uha = kmem_alloc(newbufsize, KM_SLEEP);
+               if (uha == NULL) {
                        printf("%s: memory allocation failed\n", __func__);
                        return EINVAL;
                }
-               uh = (struct intel1_ucode_header *)roundup2((uintptr_t)uh, 16);
+               uh = (struct intel1_ucode_header *)roundup2((uintptr_t)uha, 16);
                /* Copy to the new area */
                memcpy(uh, sc->sc_blob, sc->sc_blobsize);
        }
@@ -144,7 +145,7 @@
                rv = EEXIST; /* ??? */
                goto out;
        }
-       wrmsr(MSR_BIOS_UPDT_TRIG, (uintptr_t)(sc->sc_blob) + 48);
+       wrmsr(MSR_BIOS_UPDT_TRIG, (uintptr_t)uh + 48);
        intel_getcurrentucode(&nucodeversion, &platformid);
 
        kpreempt_enable();
@@ -158,7 +159,7 @@
               oucodeversion, nucodeversion);
 out:
        if (newbufsize != 0)
-               kmem_free(uh, newbufsize);
+               kmem_free(uha, newbufsize);
        return rv;
 }
 #endif /* ! XEN */



Home | Main Index | Thread Index | Old Index