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
1160 return smp_load_acquire(&iomem_inode)->i_mapping;1160 return smp_load_acquire(&iomem_inode)->i_mapping;
1161}1161}
1162 1162
1163/**1163static int __request_region_locked(struct resource *res, struct resource *parent,
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 */
1171struct resource * __request_region(struct resource *parent,
1172 resource_size_t start, resource_size_t n,1164 resource_size_t start, resource_size_t n,
1173 const char *name, int flags)1165 const char *name, int flags)
1174{1166{
1175 DECLARE_WAITQUEUE(wait, current);1167 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;
1181 1168
1182 res->name = name;1169 res->name = name;
1183 res->start = start;1170 res->start = start;
1184 res->end = start + n - 1;1171 res->end = start + n - 1;
1185 1172
1186 write_lock(&resource_lock);
1187
1188 for (;;) {1173 for (;;) {
1189 struct resource *conflict;1174 struct resource *conflict;
1190 1175
@@ -1220,13 +1205,40 @@ struct resource * __request_region(struct resource *parent, · 29 unmodified lines
1220 continue;1205 continue;
1221 }1206 }
1222 /* Uhhuh, that didn't work out.. */1207 /* Uhhuh, that didn't work out.. */
1223 free_resource(res);1208 return -EBUSY;
1224 res = NULL;
1225 break;
1226 }1209 }
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 */
1222struct 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);
1227 write_unlock(&resource_lock);1234 write_unlock(&resource_lock);
1228 1235
1229 if (res && orig_parent == &iomem_resource)1236 if (ret) {
1237 free_resource(res);
1238 return NULL;
1239 }
1240
1241 if (parent == &iomem_resource)
1230 revoke_iomem(res);1242 revoke_iomem(res);
1231 1243
1232 return res;1244 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