mirror of
https://github.com/opnsense/src.git
synced 2026-06-05 06:42:56 -04:00
new-bus: Add resource_validate_map_request function
This helper function for BUS_MAP_RESOURCE performs common argument validation. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D42723
This commit is contained in:
parent
8c4ee0b22c
commit
19f073c612
2 changed files with 36 additions and 1 deletions
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -317,6 +317,8 @@ struct driver {
|
|||
KOBJ_CLASS_FIELDS;
|
||||
};
|
||||
|
||||
struct resource;
|
||||
|
||||
/**
|
||||
* @brief A resource mapping.
|
||||
*/
|
||||
|
|
@ -341,12 +343,14 @@ void resource_init_map_request_impl(struct resource_map_request *_args,
|
|||
size_t _sz);
|
||||
#define resource_init_map_request(rmr) \
|
||||
resource_init_map_request_impl((rmr), sizeof(*(rmr)))
|
||||
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);
|
||||
|
||||
/*
|
||||
* Definitions for drivers which need to keep simple lists of resources
|
||||
* for their child devices.
|
||||
*/
|
||||
struct resource;
|
||||
|
||||
/**
|
||||
* @brief An entry for a single resource in a resource list.
|
||||
|
|
|
|||
Loading…
Reference in a new issue