Module Name: src
Committed By: tsutsui
Date: Tue Mar 16 18:50:15 UTC 2010
Modified Files:
src/sys/arch/atari/vme: if_we_vme.c
Log Message:
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)
To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/atari/vme/if_we_vme.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/atari/vme/if_we_vme.c
diff -u src/sys/arch/atari/vme/if_we_vme.c:1.1 src/sys/arch/atari/vme/if_we_vme.c:1.2
--- src/sys/arch/atari/vme/if_we_vme.c:1.1 Sat Mar 13 16:30:03 2010
+++ src/sys/arch/atari/vme/if_we_vme.c Tue Mar 16 18:50:14 2010
@@ -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));
+}