Skip to content

Commit 66f1207

Browse files
Bjorn Helgaasjbarnes993
authored andcommitted
resources: add interfaces that return conflict information
request_resource() and insert_resource() only return success or failure, which no information about what existing resource conflicted with the proposed new reservation. This patch adds request_resource_conflict() and insert_resource_conflict(), which return the conflicting resource. Callers may use this for better error messages or to adjust the new resource and retry the request. Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent 7c9e2b1 commit 66f1207

2 files changed

Lines changed: 39 additions & 7 deletions

File tree

‎include/linux/ioport.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,14 @@ struct resource_list {
112112
extern struct resource ioport_resource;
113113
extern struct resource iomem_resource;
114114

115+
extern struct resource *request_resource_conflict(struct resource *root, struct resource *new);
115116
extern int request_resource(struct resource *root, struct resource *new);
116117
extern int release_resource(struct resource *new);
117118
void release_child_resources(struct resource *new);
118119
extern void reserve_region_with_split(struct resource *root,
119120
resource_size_t start, resource_size_t end,
120121
const char *name);
122+
extern struct resource *insert_resource_conflict(struct resource *parent, struct resource *new);
121123
extern int insert_resource(struct resource *parent, struct resource *new);
122124
extern void insert_resource_expand_to_fit(struct resource *root, struct resource *new);
123125
extern int allocate_resource(struct resource *root, struct resource *new,

‎kernel/resource.c‎

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,34 @@ void release_child_resources(struct resource *r)
219219
}
220220

221221
/**
222-
* request_resource - request and reserve an I/O or memory resource
222+
* request_resource_conflict - request and reserve an I/O or memory resource
223223
* @root: root resource descriptor
224224
* @new: resource descriptor desired by caller
225225
*
226-
* Returns 0 for success, negative error code on error.
226+
* Returns 0 for success, conflict resource on error.
227227
*/
228-
int request_resource(struct resource *root, struct resource *new)
228+
struct resource *request_resource_conflict(struct resource *root, struct resource *new)
229229
{
230230
struct resource *conflict;
231231

232232
write_lock(&resource_lock);
233233
conflict = __request_resource(root, new);
234234
write_unlock(&resource_lock);
235+
return conflict;
236+
}
237+
238+
/**
239+
* request_resource - request and reserve an I/O or memory resource
240+
* @root: root resource descriptor
241+
* @new: resource descriptor desired by caller
242+
*
243+
* Returns 0 for success, negative error code on error.
244+
*/
245+
int request_resource(struct resource *root, struct resource *new)
246+
{
247+
struct resource *conflict;
248+
249+
conflict = request_resource_conflict(root, new);
235250
return conflict ? -EBUSY : 0;
236251
}
237252

@@ -474,25 +489,40 @@ static struct resource * __insert_resource(struct resource *parent, struct resou
474489
}
475490

476491
/**
477-
* insert_resource - Inserts a resource in the resource tree
492+
* insert_resource_conflict - Inserts resource in the resource tree
478493
* @parent: parent of the new resource
479494
* @new: new resource to insert
480495
*
481-
* Returns 0 on success, -EBUSY if the resource can't be inserted.
496+
* Returns 0 on success, conflict resource if the resource can't be inserted.
482497
*
483-
* This function is equivalent to request_resource when no conflict
498+
* This function is equivalent to request_resource_conflict when no conflict
484499
* happens. If a conflict happens, and the conflicting resources
485500
* entirely fit within the range of the new resource, then the new
486501
* resource is inserted and the conflicting resources become children of
487502
* the new resource.
488503
*/
489-
int insert_resource(struct resource *parent, struct resource *new)
504+
struct resource *insert_resource_conflict(struct resource *parent, struct resource *new)
490505
{
491506
struct resource *conflict;
492507

493508
write_lock(&resource_lock);
494509
conflict = __insert_resource(parent, new);
495510
write_unlock(&resource_lock);
511+
return conflict;
512+
}
513+
514+
/**
515+
* insert_resource - Inserts a resource in the resource tree
516+
* @parent: parent of the new resource
517+
* @new: new resource to insert
518+
*
519+
* Returns 0 on success, -EBUSY if the resource can't be inserted.
520+
*/
521+
int insert_resource(struct resource *parent, struct resource *new)
522+
{
523+
struct resource *conflict;
524+
525+
conflict = insert_resource_conflict(parent, new);
496526
return conflict ? -EBUSY : 0;
497527
}
498528

0 commit comments

Comments
 (0)