mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-07 13:43:51 +00:00
resources: Add device-managed request/release_resource()
Provide device-managed implementations of the request_resource() and release_resource() functions. Upon failure to request a resource, the new devm_request_resource() function will output an error message for consistent error reporting. Signed-off-by: Thierry Reding <treding@nvidia.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Acked-by: Tejun Heo <tj@kernel.org>
This commit is contained in:
parent
52addcf9d6
commit
8d38821cbc
@ -264,8 +264,10 @@ IIO
|
||||
IO region
|
||||
devm_release_mem_region()
|
||||
devm_release_region()
|
||||
devm_release_resource()
|
||||
devm_request_mem_region()
|
||||
devm_request_region()
|
||||
devm_request_resource()
|
||||
|
||||
IOMAP
|
||||
devm_ioport_map()
|
||||
|
@ -215,6 +215,11 @@ static inline int __deprecated check_region(resource_size_t s,
|
||||
|
||||
/* Wrappers for managed devices */
|
||||
struct device;
|
||||
|
||||
extern int devm_request_resource(struct device *dev, struct resource *root,
|
||||
struct resource *new);
|
||||
extern void devm_release_resource(struct device *dev, struct resource *new);
|
||||
|
||||
#define devm_request_region(dev,start,n,name) \
|
||||
__devm_request_region(dev, &ioport_resource, (start), (n), (name))
|
||||
#define devm_request_mem_region(dev,start,n,name) \
|
||||
|
@ -1248,6 +1248,76 @@ int release_mem_region_adjustable(struct resource *parent,
|
||||
/*
|
||||
* Managed region resource
|
||||
*/
|
||||
static void devm_resource_release(struct device *dev, void *ptr)
|
||||
{
|
||||
struct resource **r = ptr;
|
||||
|
||||
release_resource(*r);
|
||||
}
|
||||
|
||||
/**
|
||||
* devm_request_resource() - request and reserve an I/O or memory resource
|
||||
* @dev: device for which to request the resource
|
||||
* @root: root of the resource tree from which to request the resource
|
||||
* @new: descriptor of the resource to request
|
||||
*
|
||||
* This is a device-managed version of request_resource(). There is usually
|
||||
* no need to release resources requested by this function explicitly since
|
||||
* that will be taken care of when the device is unbound from its driver.
|
||||
* If for some reason the resource needs to be released explicitly, because
|
||||
* of ordering issues for example, drivers must call devm_release_resource()
|
||||
* rather than the regular release_resource().
|
||||
*
|
||||
* When a conflict is detected between any existing resources and the newly
|
||||
* requested resource, an error message will be printed.
|
||||
*
|
||||
* Returns 0 on success or a negative error code on failure.
|
||||
*/
|
||||
int devm_request_resource(struct device *dev, struct resource *root,
|
||||
struct resource *new)
|
||||
{
|
||||
struct resource *conflict, **ptr;
|
||||
|
||||
ptr = devres_alloc(devm_resource_release, sizeof(*ptr), GFP_KERNEL);
|
||||
if (!ptr)
|
||||
return -ENOMEM;
|
||||
|
||||
*ptr = new;
|
||||
|
||||
conflict = request_resource_conflict(root, new);
|
||||
if (conflict) {
|
||||
dev_err(dev, "resource collision: %pR conflicts with %s %pR\n",
|
||||
new, conflict->name, conflict);
|
||||
devres_free(ptr);
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
devres_add(dev, ptr);
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(devm_request_resource);
|
||||
|
||||
static int devm_resource_match(struct device *dev, void *res, void *data)
|
||||
{
|
||||
struct resource **ptr = res;
|
||||
|
||||
return *ptr == data;
|
||||
}
|
||||
|
||||
/**
|
||||
* devm_release_resource() - release a previously requested resource
|
||||
* @dev: device for which to release the resource
|
||||
* @new: descriptor of the resource to release
|
||||
*
|
||||
* Releases a resource previously requested using devm_request_resource().
|
||||
*/
|
||||
void devm_release_resource(struct device *dev, struct resource *new)
|
||||
{
|
||||
WARN_ON(devres_release(dev, devm_resource_release, devm_resource_match,
|
||||
new));
|
||||
}
|
||||
EXPORT_SYMBOL(devm_release_resource);
|
||||
|
||||
struct region_devres {
|
||||
struct resource *parent;
|
||||
resource_size_t start;
|
||||
|
Loading…
Reference in New Issue
Block a user