History

kernel/resource: refactor __request_region to allow external locking

Refactor the portion of __request_region() done whilst holding the resource_lock into a separate function to allow callers to hold the lock.

Alistair Popple committed 5 years ago

Commit 63cdafe1 parent d486ccb1 file · +32 −20Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/resource.c+32−20
@@ -1160,31 +1160,16 @@ struct address_space *iomem_get_mapping(void) · 1159 unmodified lines
11601160 return smp_load_acquire(&iomem_inode)->i_mapping;
11611161 }
11621162
1163−/**
1164− * __request_region - create a new busy resource region
1165− * @parent: parent resource descriptor
1166− * @start: resource start address
1167− * @n: resource region size
1168− * @name: reserving caller's ID string
1169− * @flags: IO resource flags
1170− */
1171−struct resource * __request_region(struct resource *parent,
1163+static int __request_region_locked(struct resource *res, struct resource *parent,
11721164 resource_size_t start, resource_size_t n,
11731165 const char *name, int flags)
11741166 {
11751167 DECLARE_WAITQUEUE(wait, current);
1176− struct resource *res = alloc_resource(GFP_KERNEL);
1177− struct resource *orig_parent = parent;
1178−
1179− if (!res)
1180− return NULL;
11811168
11821169 res->name = name;
11831170 res->start = start;
11841171 res->end = start + n - 1;
11851172
1186− write_lock(&resource_lock);
1187−
11881173 for (;;) {
11891174 struct resource *conflict;
11901175
@@ -1220,13 +1205,40 @@ struct resource * __request_region(struct resource *parent, · 29 unmodified lines
12201205 continue;
12211206 }
12221207 /* Uhhuh, that didn't work out.. */
1223− free_resource(res);
1224− res = NULL;
1225− break;
1208+ return -EBUSY;
12261209 }
1210+
1211+ return 0;
1212+}
1213+
1214+/**
1215+ * __request_region - create a new busy resource region
1216+ * @parent: parent resource descriptor
1217+ * @start: resource start address
1218+ * @n: resource region size
1219+ * @name: reserving caller's ID string
1220+ * @flags: IO resource flags
1221+ */
1222+struct resource *__request_region(struct resource *parent,
1223+ resource_size_t start, resource_size_t n,
1224+ const char *name, int flags)
1225+{
1226+ struct resource *res = alloc_resource(GFP_KERNEL);
1227+ int ret;
1228+
1229+ if (!res)
1230+ return NULL;
1231+
1232+ write_lock(&resource_lock);
1233+ ret = __request_region_locked(res, parent, start, n, name, flags);
12271234 write_unlock(&resource_lock);
12281235
1229− if (res && orig_parent == &iomem_resource)
1236+ if (ret) {
1237+ free_resource(res);
1238+ return NULL;
1239+ }
1240+
1241+ if (parent == &iomem_resource)
12301242 revoke_iomem(res);
12311243
12321244 return res;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t