Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci change pci_conf_print() to allocate memory for t...



details:   https://anonhg.NetBSD.org/src/rev/93442107cf99
branches:  trunk
changeset: 933749:93442107cf99
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Sat May 30 10:43:46 2020 +0000

description:
change pci_conf_print() to allocate memory for the regs dynamically
instead of on-stack

diffstat:

 sys/dev/pci/pci_subr.c |  22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)

diffs (76 lines):

diff -r 0cf0c9bf5c72 -r 93442107cf99 sys/dev/pci/pci_subr.c
--- a/sys/dev/pci/pci_subr.c    Sat May 30 10:27:29 2020 +0000
+++ b/sys/dev/pci/pci_subr.c    Sat May 30 10:43:46 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci_subr.c,v 1.223 2020/04/10 18:32:00 christos Exp $  */
+/*     $NetBSD: pci_subr.c,v 1.224 2020/05/30 10:43:46 jdolecek Exp $  */
 
 /*
  * Copyright (c) 1997 Zubin D. Dittia.  All rights reserved.
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.223 2020/04/10 18:32:00 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_subr.c,v 1.224 2020/05/30 10:43:46 jdolecek Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pci.h"
@@ -52,6 +52,11 @@
 #include <sys/systm.h>
 #include <sys/intr.h>
 #include <sys/module.h>
+#include <sys/kmem.h>
+
+#define MALLOC(sz)     kmem_alloc(sz, KM_SLEEP)
+#define FREE(p, sz)    kmem_free(p, sz)
+
 #else
 #include <pci.h>
 #include <stdarg.h>
@@ -59,6 +64,10 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
+#define MALLOC(sz)     malloc(sz)
+#define FREE(p, sz)    free(p)
+
 #endif
 
 #include <dev/pci/pcireg.h>
@@ -4810,7 +4819,7 @@
 #endif
     )
 {
-       pcireg_t regs[o2i(PCI_EXTCONF_SIZE)];
+       pcireg_t *regs;
        int off, capoff, endoff, hdrtype;
        const char *type_name;
 #ifdef _KERNEL
@@ -4819,6 +4828,8 @@
        void (*type_printfn)(const pcireg_t *);
 #endif
 
+       regs = MALLOC(PCI_EXTCONF_SIZE);
+
        printf("PCI configuration registers:\n");
 
        for (off = 0; off < PCI_EXTCONF_SIZE; off += 4) {
@@ -4915,7 +4926,7 @@
 
        if (regs[o2i(PCI_EXTCAPLIST_BASE)] == 0xffffffff ||
            regs[o2i(PCI_EXTCAPLIST_BASE)] == 0)
-               return;
+               goto out;
 
        printf("\n");
 #ifdef _KERNEL
@@ -4928,4 +4939,7 @@
        /* Extended Configuration Space, if present */
        printf("  Extended Configuration Space:\n");
        pci_conf_print_regs(regs, PCI_EXTCAPLIST_BASE, PCI_EXTCONF_SIZE);
+
+out:
+       FREE(regs, PCI_EXTCONF_SIZE);
 }



Home | Main Index | Thread Index | Old Index