From 21cfbbfb868a29cf881904db50d0a130d94fe451 Mon Sep 17 00:00:00 2001 From: jhb Date: Fri, 24 Jun 2011 13:41:46 +0000 Subject: [PATCH] MFC 221218: Change rman_manage_region() to actually honor the rm_start and rm_end constraints on the rman and reject attempts to manage a region that is out of range. - Fix various places that set rm_end incorrectly (to ~0 or ~0u instead of ~0ul). - To preserve existing behavior, change rman_init() to set rm_start and rm_end to allow managing the full range (0 to ~0ul) if they are not set by the caller when rman_init() is called. git-svn-id: svn://svn.freebsd.org/base/stable/8@223500 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/arm/arm/nexus.c | 4 ++-- sys/ia64/ia64/nexus.c | 2 +- sys/kern/subr_rman.c | 4 ++++ sys/mips/mips/mainbus.c | 2 +- sys/mips/mips/nexus.c | 2 +- sys/mips/rmi/pcibus.c | 6 +++--- sys/mips/rmi/xlr_pci.c | 4 ++-- sys/x86/x86/nexus.c | 2 +- 8 files changed, 15 insertions(+), 11 deletions(-) diff --git a/sys/arm/arm/nexus.c b/sys/arm/arm/nexus.c index 306c641e2..f4597837e 100644 --- a/sys/arm/arm/nexus.c +++ b/sys/arm/arm/nexus.c @@ -110,10 +110,10 @@ nexus_probe(device_t dev) device_quiet(dev); /* suppress attach message for neatness */ mem_rman.rm_start = 0; - mem_rman.rm_end = ~0u; + mem_rman.rm_end = ~0ul; mem_rman.rm_type = RMAN_ARRAY; mem_rman.rm_descr = "I/O memory addresses"; - if (rman_init(&mem_rman) || rman_manage_region(&mem_rman, 0, ~0u)) + if (rman_init(&mem_rman) || rman_manage_region(&mem_rman, 0, ~0)) panic("nexus_probe mem_rman"); return (0); diff --git a/sys/ia64/ia64/nexus.c b/sys/ia64/ia64/nexus.c index 43d06323b..8e71b1e7d 100644 --- a/sys/ia64/ia64/nexus.c +++ b/sys/ia64/ia64/nexus.c @@ -174,7 +174,7 @@ nexus_probe(device_t dev) panic("nexus_probe port_rman"); mem_rman.rm_start = 0; - mem_rman.rm_end = ~0u; + mem_rman.rm_end = ~0ul; mem_rman.rm_type = RMAN_ARRAY; mem_rman.rm_descr = "I/O memory addresses"; if (rman_init(&mem_rman) diff --git a/sys/kern/subr_rman.c b/sys/kern/subr_rman.c index f63e4f2bc..a546b9cc4 100644 --- a/sys/kern/subr_rman.c +++ b/sys/kern/subr_rman.c @@ -138,6 +138,8 @@ rman_init(struct rman *rm) mtx_init(&rman_mtx, "rman head", NULL, MTX_DEF); } + if (rm->rm_start == 0 && rm->rm_end == 0) + rm->rm_end = ~0ul; if (rm->rm_type == RMAN_UNINIT) panic("rman_init"); if (rm->rm_type == RMAN_GAUGE) @@ -162,6 +164,8 @@ rman_manage_region(struct rman *rm, u_long start, u_long end) DPRINTF(("rman_manage_region: <%s> request: start %#lx, end %#lx\n", rm->rm_descr, start, end)); + if (start < rm->rm_start || end > rm->rm_end) + return EINVAL; r = int_alloc_resource(M_NOWAIT); if (r == NULL) return ENOMEM; diff --git a/sys/mips/mips/mainbus.c b/sys/mips/mips/mainbus.c index 587b409a3..b68b74bc3 100644 --- a/sys/mips/mips/mainbus.c +++ b/sys/mips/mips/mainbus.c @@ -146,7 +146,7 @@ mainbus_probe(device_t dev) panic("mainbus_probe port_rman"); mem_rman.rm_start = 0; - mem_rman.rm_end = ~0u; + mem_rman.rm_end = ~0ul; mem_rman.rm_type = RMAN_ARRAY; mem_rman.rm_descr = "I/O memory addresses"; if (rman_init(&mem_rman) || rman_manage_region(&mem_rman, 0, ~0)) diff --git a/sys/mips/mips/nexus.c b/sys/mips/mips/nexus.c index 227446618..b51357d75 100644 --- a/sys/mips/mips/nexus.c +++ b/sys/mips/mips/nexus.c @@ -151,7 +151,7 @@ nexus_probe(device_t dev) } mem_rman.rm_start = 0; - mem_rman.rm_end = ~0u; + mem_rman.rm_end = ~0ul; mem_rman.rm_type = RMAN_ARRAY; mem_rman.rm_descr = "Memory addresses"; if (rman_init(&mem_rman) != 0 || diff --git a/sys/mips/rmi/pcibus.c b/sys/mips/rmi/pcibus.c index ac664d3b4..a379bfe7c 100644 --- a/sys/mips/rmi/pcibus.c +++ b/sys/mips/rmi/pcibus.c @@ -25,7 +25,7 @@ */ #include -__FBSDID("$FreeBSD: src/sys/alpha/pci/pcibus.c,v 1.36 2005/01/05 20:05:52 imp Exp $"); +__FBSDID("$FreeBSD$"); #include "opt_isa.h" @@ -229,7 +229,7 @@ pci_init_resources(void) panic("pci_init_resources irq_rman"); port_rman.rm_start = 0; - port_rman.rm_end = ~0u; + port_rman.rm_end = ~0ul; port_rman.rm_type = RMAN_ARRAY; port_rman.rm_descr = "I/O ports"; if (rman_init(&port_rman) @@ -237,7 +237,7 @@ pci_init_resources(void) panic("pci_init_resources port_rman"); mem_rman.rm_start = 0; - mem_rman.rm_end = ~0u; + mem_rman.rm_end = ~0ul; mem_rman.rm_type = RMAN_ARRAY; mem_rman.rm_descr = "I/O memory"; if (rman_init(&mem_rman) diff --git a/sys/mips/rmi/xlr_pci.c b/sys/mips/rmi/xlr_pci.c index 3204691be..2dfec9bfe 100644 --- a/sys/mips/rmi/xlr_pci.c +++ b/sys/mips/rmi/xlr_pci.c @@ -133,7 +133,7 @@ xlr_pci_init_resources(void) panic("pci_init_resources irq_rman"); port_rman.rm_start = 0; - port_rman.rm_end = ~0u; + port_rman.rm_end = ~0ul; port_rman.rm_type = RMAN_ARRAY; port_rman.rm_descr = "I/O ports"; if (rman_init(&port_rman) @@ -141,7 +141,7 @@ xlr_pci_init_resources(void) panic("pci_init_resources port_rman"); mem_rman.rm_start = 0; - mem_rman.rm_end = ~0u; + mem_rman.rm_end = ~0ul; mem_rman.rm_type = RMAN_ARRAY; mem_rman.rm_descr = "I/O memory"; if (rman_init(&mem_rman) diff --git a/sys/x86/x86/nexus.c b/sys/x86/x86/nexus.c index e046c4667..0092142fe 100644 --- a/sys/x86/x86/nexus.c +++ b/sys/x86/x86/nexus.c @@ -266,7 +266,7 @@ nexus_init_resources(void) panic("nexus_init_resources port_rman"); mem_rman.rm_start = 0; - mem_rman.rm_end = ~0u; + mem_rman.rm_end = ~0ul; mem_rman.rm_type = RMAN_ARRAY; mem_rman.rm_descr = "I/O memory addresses"; if (rman_init(&mem_rman) -- 2.45.0