diff options
author | John Baldwin <jhb@FreeBSD.org> | 2023-11-23 17:06:24 +0000 |
---|---|---|
committer | John Baldwin <jhb@FreeBSD.org> | 2023-11-23 17:06:24 +0000 |
commit | 19f073c612afa0111d216e5ccab9525bfc97ec32 (patch) | |
tree | 5ed55f5ec6139fd80b85696fe00fe87e7ee4899b /sys/kern/subr_bus.c | |
parent | 8c4ee0b22c98fc1e208dd133f617bd329cd10728 (diff) | |
download | src-19f073c612afa0111d216e5ccab9525bfc97ec32.tar.gz src-19f073c612afa0111d216e5ccab9525bfc97ec32.zip |
Diffstat (limited to 'sys/kern/subr_bus.c')
-rw-r--r-- | sys/kern/subr_bus.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 648394abd026..80fe182eab56 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -2715,6 +2715,37 @@ resource_init_map_request_impl(struct resource_map_request *args, size_t sz) args->memattr = VM_MEMATTR_DEVICE; } +int +resource_validate_map_request(struct resource *r, + struct resource_map_request *in, struct resource_map_request *out, + rman_res_t *startp, rman_res_t *lengthp) +{ + rman_res_t end, length, start; + + /* + * This assumes that any callers of this function are compiled + * into the kernel and use the same version of the structure + * as this file. + */ + MPASS(out->size == sizeof(struct resource_map_request)); + + if (in != NULL) + bcopy(in, out, imin(in->size, out->size)); + start = rman_get_start(r) + out->offset; + if (out->length == 0) + length = rman_get_size(r); + else + length = out->length; + end = start + length - 1; + if (start > rman_get_end(r) || start < rman_get_start(r)) + return (EINVAL); + if (end > rman_get_end(r) || end < start) + return (EINVAL); + *lengthp = length; + *startp = start; + return (0); +} + /** * @brief Initialise a resource list. * |