Source-Changes-HG archive

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

[src/trunk]: src/sys/dev UEFI calls can modify size inputs, so stash them for...



details:   https://anonhg.NetBSD.org/src/rev/c42d09a9a586
branches:  trunk
changeset: 989036:c42d09a9a586
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Oct 10 14:52:30 2021 +0000

description:
UEFI calls can modify size inputs, so stash them for use with kmem_free

diffstat:

 sys/dev/efi.c |  22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diffs (78 lines):

diff -r e87543822a8c -r c42d09a9a586 sys/dev/efi.c
--- a/sys/dev/efi.c     Sun Oct 10 13:03:08 2021 +0000
+++ b/sys/dev/efi.c     Sun Oct 10 14:52:30 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: efi.c,v 1.1 2021/10/10 13:03:09 jmcneill Exp $ */
+/* $NetBSD: efi.c,v 1.2 2021/10/10 14:52:30 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2021 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.1 2021/10/10 13:03:09 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.2 2021/10/10 14:52:30 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -151,6 +151,7 @@
 {
        uint16_t *namebuf;
        void *databuf = NULL;
+       size_t datasize;
        efi_status status;
        int error;
 
@@ -171,9 +172,10 @@
                error = EINVAL;
                goto done;
        }
-       if (var->datasize != 0) {
-               databuf = kmem_alloc(var->datasize, KM_SLEEP);
-               error = copyin(var->data, databuf, var->datasize);
+       datasize = var->datasize;
+       if (datasize != 0) {
+               databuf = kmem_alloc(datasize, KM_SLEEP);
+               error = copyin(var->data, databuf, datasize);
                if (error != 0) {
                        goto done;
                }
@@ -194,7 +196,7 @@
 done:
        kmem_free(namebuf, var->namesize);
        if (databuf != NULL) {
-               kmem_free(databuf, var->datasize);
+               kmem_free(databuf, datasize);
        }
        return error;
 }
@@ -204,6 +206,7 @@
 {
        efi_status status;
        uint16_t *namebuf;
+       size_t namesize;
        int error;
 
        if (var->name == NULL || var->namesize == 0) {
@@ -213,8 +216,9 @@
                return ENOMEM;
        }
 
-       namebuf = kmem_alloc(var->namesize, KM_SLEEP);
-       error = copyin(var->name, namebuf, var->namesize);
+       namesize = var->namesize;
+       namebuf = kmem_alloc(namesize, KM_SLEEP);
+       error = copyin(var->name, namebuf, namesize);
        if (error != 0) {
                goto done;
        }
@@ -231,7 +235,7 @@
        }
 
 done:
-       kmem_free(namebuf, var->namesize);
+       kmem_free(namebuf, namesize);
        return error;
 }
 



Home | Main Index | Thread Index | Old Index