Refactor the portion of __request_region() done whilst holding the resource_lock into a separate function to allow callers to hold the lock.
Unified · Split
| @@ -1160,31 +1160,16 @@ struct address_space *iomem_get_mapping(void) · 1159 unmodified lines | ||
| 1160 | 1160 | return smp_load_acquire(&iomem_inode)->i_mapping; |
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 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, | |
| 1172 | 1164 | resource_size_t start, resource_size_t n, |
| 1173 | 1165 | const char *name, int flags) |
| 1174 | 1166 | { |
| 1175 | 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 | 1169 | res->name = name; |
| 1183 | 1170 | res->start = start; |
| 1184 | 1171 | res->end = start + n - 1; |
| 1185 | 1172 | |
| 1186 | − write_lock(&resource_lock); | |
| 1187 | − | |
| 1188 | 1173 | for (;;) { |
| 1189 | 1174 | struct resource *conflict; |
| 1190 | 1175 | |
| @@ -1220,13 +1205,40 @@ struct resource * __request_region(struct resource *parent, · 29 unmodified lines | ||
| 1220 | 1205 | continue; |
| 1221 | 1206 | } |
| 1222 | 1207 | /* Uhhuh, that didn't work out.. */ |
| 1223 | − free_resource(res); | |
| 1224 | − res = NULL; | |
| 1225 | − break; | |
| 1208 | + return -EBUSY; | |
| 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 | + */ | |
| 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); | |
| 1227 | 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 | 1242 | revoke_iomem(res); |
| 1231 | 1243 | |
| 1232 | 1244 | return res; |