Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/atari/vme Check if mapped bus_space regions are act...



details:   https://anonhg.NetBSD.org/src/rev/910f7a18ce57
branches:  trunk
changeset: 753129:910f7a18ce57
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Tue Mar 16 18:50:14 2010 +0000

description:
Check if mapped bus_space regions are actually valid
before trying to access them.

Fixes trap panic when SMC_TT board is not installed. (oops)

diffstat:

 sys/arch/atari/vme/if_we_vme.c |  33 +++++++++++++++++++++++++++++++--
 1 files changed, 31 insertions(+), 2 deletions(-)

diffs (79 lines):

diff -r 2da5f5e4e62b -r 910f7a18ce57 sys/arch/atari/vme/if_we_vme.c
--- a/sys/arch/atari/vme/if_we_vme.c    Tue Mar 16 17:58:57 2010 +0000
+++ b/sys/arch/atari/vme/if_we_vme.c    Tue Mar 16 18:50:14 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_we_vme.c,v 1.1 2010/03/13 16:30:03 tsutsui Exp $    */
+/*     $NetBSD: if_we_vme.c,v 1.2 2010/03/16 18:50:14 tsutsui Exp $    */
 
 /*-
  * Copyright (c) 1997, 1998, 2010 The NetBSD Foundation, Inc.
@@ -50,7 +50,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_we_vme.c,v 1.1 2010/03/13 16:30:03 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_we_vme.c,v 1.2 2010/03/16 18:50:14 tsutsui Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -110,6 +110,8 @@
     bus_size_t);
 static void    smctt_bus_space_write_1(bus_space_tag_t, bus_space_handle_t,
     bus_size_t, uint8_t);
+static int     smctt_bus_space_peek_1(bus_space_tag_t, bus_space_handle_t,
+    bus_size_t);
 
 struct we_vme_softc {
        struct we_softc sc_we;
@@ -155,6 +157,7 @@
        /* XXX setup only simple byte functions used in MI we(4) driver */
        asict->abs_r_1 = smctt_bus_space_read_1;
        asict->abs_w_1 = smctt_bus_space_write_1;
+       asict->abs_p_1 = smctt_bus_space_peek_1;
 
        /*
         * Only 16 bit accesses are allowed for memory space on SMC_TT,
@@ -182,6 +185,11 @@
            (vaddr_t)bus_space_vaddr(asict, asich1) -
            (vaddr_t)bus_space_vaddr(asict, asich);
 
+       /* check if register regions are valid */
+       if (bus_space_peek_1(asict, asich, WE_PROM + 0) == 0 ||
+           bus_space_peek_1(asict, asich, WE_PROM + 1) == 0)
+               goto out;
+
        /*
         * Attempt to do a checksum over the station address PROM.
         * If it fails, it's probably not an SMC_TT board.
@@ -248,6 +256,10 @@
        }
        memh_valid = true;
 
+       /* check if memory region is valid */
+       if (bus_space_peek_2(memt, memh, 0) == 0)
+               goto out;
+
        /*
         * Check the assigned interrupt number from the card.
         */
@@ -421,3 +433,20 @@
                *(volatile uint8_t *)(bh + reg) = val;
        }
 }
+
+static int
+smctt_bus_space_peek_1(bus_space_tag_t bt, bus_space_handle_t bh,
+    bus_size_t reg)
+{
+       uint8_t *va;
+
+       if ((reg & 0x01) != 0) {
+               /* odd address space */
+               va = (uint8_t *)(bh + bt->stride + (reg & ~0x01));
+       } else {
+               /* even address space */
+               va = (uint8_t *)(bh + reg);
+       }
+
+       return !badbaddr(va, sizeof(uint8_t));
+}



Home | Main Index | Thread Index | Old Index