|
26 | 26 | #include <linux/atomic.h> |
27 | 27 | #include <linux/uidgid.h> |
28 | 28 | #include <linux/gfp.h> |
29 | | -#include <linux/overflow.h> |
30 | 29 | #include <linux/device/bus.h> |
31 | 30 | #include <linux/device/class.h> |
| 31 | +#include <linux/device/devres.h> |
32 | 32 | #include <linux/device/driver.h> |
33 | 33 | #include <linux/cleanup.h> |
34 | 34 | #include <asm/device.h> |
@@ -281,123 +281,6 @@ int __must_check device_create_bin_file(struct device *dev, |
281 | 281 | void device_remove_bin_file(struct device *dev, |
282 | 282 | const struct bin_attribute *attr); |
283 | 283 |
|
284 | | -/* device resource management */ |
285 | | -typedef void (*dr_release_t)(struct device *dev, void *res); |
286 | | -typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data); |
287 | | - |
288 | | -void *__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, |
289 | | - int nid, const char *name) __malloc; |
290 | | -#define devres_alloc(release, size, gfp) \ |
291 | | - __devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release) |
292 | | -#define devres_alloc_node(release, size, gfp, nid) \ |
293 | | - __devres_alloc_node(release, size, gfp, nid, #release) |
294 | | - |
295 | | -void devres_for_each_res(struct device *dev, dr_release_t release, |
296 | | - dr_match_t match, void *match_data, |
297 | | - void (*fn)(struct device *, void *, void *), |
298 | | - void *data); |
299 | | -void devres_free(void *res); |
300 | | -void devres_add(struct device *dev, void *res); |
301 | | -void *devres_find(struct device *dev, dr_release_t release, |
302 | | - dr_match_t match, void *match_data); |
303 | | -void *devres_get(struct device *dev, void *new_res, |
304 | | - dr_match_t match, void *match_data); |
305 | | -void *devres_remove(struct device *dev, dr_release_t release, |
306 | | - dr_match_t match, void *match_data); |
307 | | -int devres_destroy(struct device *dev, dr_release_t release, |
308 | | - dr_match_t match, void *match_data); |
309 | | -int devres_release(struct device *dev, dr_release_t release, |
310 | | - dr_match_t match, void *match_data); |
311 | | - |
312 | | -/* devres group */ |
313 | | -void * __must_check devres_open_group(struct device *dev, void *id, gfp_t gfp); |
314 | | -void devres_close_group(struct device *dev, void *id); |
315 | | -void devres_remove_group(struct device *dev, void *id); |
316 | | -int devres_release_group(struct device *dev, void *id); |
317 | | - |
318 | | -/* managed devm_k.alloc/kfree for device drivers */ |
319 | | -void *devm_kmalloc(struct device *dev, size_t size, gfp_t gfp) __alloc_size(2); |
320 | | -void *devm_krealloc(struct device *dev, void *ptr, size_t size, |
321 | | - gfp_t gfp) __must_check __realloc_size(3); |
322 | | -__printf(3, 0) char *devm_kvasprintf(struct device *dev, gfp_t gfp, |
323 | | - const char *fmt, va_list ap) __malloc; |
324 | | -__printf(3, 4) char *devm_kasprintf(struct device *dev, gfp_t gfp, |
325 | | - const char *fmt, ...) __malloc; |
326 | | -static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp) |
327 | | -{ |
328 | | - return devm_kmalloc(dev, size, gfp | __GFP_ZERO); |
329 | | -} |
330 | | -static inline void *devm_kmalloc_array(struct device *dev, |
331 | | - size_t n, size_t size, gfp_t flags) |
332 | | -{ |
333 | | - size_t bytes; |
334 | | - |
335 | | - if (unlikely(check_mul_overflow(n, size, &bytes))) |
336 | | - return NULL; |
337 | | - |
338 | | - return devm_kmalloc(dev, bytes, flags); |
339 | | -} |
340 | | -static inline void *devm_kcalloc(struct device *dev, |
341 | | - size_t n, size_t size, gfp_t flags) |
342 | | -{ |
343 | | - return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); |
344 | | -} |
345 | | -static inline __realloc_size(3, 4) void * __must_check |
346 | | -devm_krealloc_array(struct device *dev, void *p, size_t new_n, size_t new_size, gfp_t flags) |
347 | | -{ |
348 | | - size_t bytes; |
349 | | - |
350 | | - if (unlikely(check_mul_overflow(new_n, new_size, &bytes))) |
351 | | - return NULL; |
352 | | - |
353 | | - return devm_krealloc(dev, p, bytes, flags); |
354 | | -} |
355 | | - |
356 | | -void devm_kfree(struct device *dev, const void *p); |
357 | | -char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; |
358 | | -const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp); |
359 | | -void *devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp) |
360 | | - __realloc_size(3); |
361 | | - |
362 | | -unsigned long devm_get_free_pages(struct device *dev, |
363 | | - gfp_t gfp_mask, unsigned int order); |
364 | | -void devm_free_pages(struct device *dev, unsigned long addr); |
365 | | - |
366 | | -#ifdef CONFIG_HAS_IOMEM |
367 | | -void __iomem *devm_ioremap_resource(struct device *dev, |
368 | | - const struct resource *res); |
369 | | -void __iomem *devm_ioremap_resource_wc(struct device *dev, |
370 | | - const struct resource *res); |
371 | | - |
372 | | -void __iomem *devm_of_iomap(struct device *dev, |
373 | | - struct device_node *node, int index, |
374 | | - resource_size_t *size); |
375 | | -#else |
376 | | - |
377 | | -static inline |
378 | | -void __iomem *devm_ioremap_resource(struct device *dev, |
379 | | - const struct resource *res) |
380 | | -{ |
381 | | - return ERR_PTR(-EINVAL); |
382 | | -} |
383 | | - |
384 | | -static inline |
385 | | -void __iomem *devm_ioremap_resource_wc(struct device *dev, |
386 | | - const struct resource *res) |
387 | | -{ |
388 | | - return ERR_PTR(-EINVAL); |
389 | | -} |
390 | | - |
391 | | -static inline |
392 | | -void __iomem *devm_of_iomap(struct device *dev, |
393 | | - struct device_node *node, int index, |
394 | | - resource_size_t *size) |
395 | | -{ |
396 | | - return ERR_PTR(-EINVAL); |
397 | | -} |
398 | | - |
399 | | -#endif |
400 | | - |
401 | 284 | /* allows to add/remove a custom action to devres stack */ |
402 | 285 | int devm_remove_action_nowarn(struct device *dev, void (*action)(void *), void *data); |
403 | 286 |
|
|
0 commit comments