Something went wrong. Try again.
Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186/* SPDX-License-Identifier: GPL-2.0 */#ifndef _DEVICE_DEVRES_H_#define _DEVICE_DEVRES_H_
#include <linux/err.h>#include <linux/gfp_types.h>#include <linux/numa.h>#include <linux/overflow.h>#include <linux/stdarg.h>#include <linux/types.h>#include <asm/bug.h>#include <asm/percpu.h>
struct device;struct device_node;struct resource;
/* device resource management */typedef void (*dr_release_t)(struct device *dev, void *res);typedef int (*dr_match_t)(struct device *dev, void *res, void *match_data);
void * __malloc__devres_alloc_node(dr_release_t release, size_t size, gfp_t gfp, int nid, const char *name);#define devres_alloc(release, size, gfp) \ __devres_alloc_node(release, size, gfp, NUMA_NO_NODE, #release)#define devres_alloc_node(release, size, gfp, nid) \ __devres_alloc_node(release, size, gfp, nid, #release)
void devres_free(void *res);void devres_add(struct device *dev, void *res);void *devres_find(struct device *dev, dr_release_t release, dr_match_t match, void *match_data);void *devres_get(struct device *dev, void *new_res, dr_match_t match, void *match_data);void *devres_remove(struct device *dev, dr_release_t release, dr_match_t match, void *match_data);int devres_destroy(struct device *dev, dr_release_t release, dr_match_t match, void *match_data);int devres_release(struct device *dev, dr_release_t release, dr_match_t match, void *match_data);
/* devres group */void * __must_check devres_open_group(struct device *dev, void *id, gfp_t gfp);void devres_close_group(struct device *dev, void *id);void devres_remove_group(struct device *dev, void *id);int devres_release_group(struct device *dev, void *id);
/* managed devm_k.alloc/kfree for device drivers */void * __alloc_size(2)devm_kmalloc(struct device *dev, size_t size, gfp_t gfp);void * __must_check __realloc_size(3)devm_krealloc(struct device *dev, void *ptr, size_t size, gfp_t gfp);static inline void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp){ return devm_kmalloc(dev, size, gfp | __GFP_ZERO);}static inline void *devm_kmalloc_array(struct device *dev, size_t n, size_t size, gfp_t flags){ size_t bytes;
if (unlikely(check_mul_overflow(n, size, &bytes))) return NULL;
return devm_kmalloc(dev, bytes, flags);}static inline void *devm_kcalloc(struct device *dev, size_t n, size_t size, gfp_t flags){ return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO);}static inline __realloc_size(3, 4) void * __must_checkdevm_krealloc_array(struct device *dev, void *p, size_t new_n, size_t new_size, gfp_t flags){ size_t bytes;
if (unlikely(check_mul_overflow(new_n, new_size, &bytes))) return NULL;
return devm_krealloc(dev, p, bytes, flags);}
void devm_kfree(struct device *dev, const void *p);
void * __realloc_size(3)devm_kmemdup(struct device *dev, const void *src, size_t len, gfp_t gfp);const void *devm_kmemdup_const(struct device *dev, const void *src, size_t len, gfp_t gfp);static inline void *devm_kmemdup_array(struct device *dev, const void *src, size_t n, size_t size, gfp_t flags){ return devm_kmemdup(dev, src, size_mul(size, n), flags);}
char * __mallocdevm_kstrdup(struct device *dev, const char *s, gfp_t gfp);const char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp);char * __printf(3, 0) __mallocdevm_kvasprintf(struct device *dev, gfp_t gfp, const char *fmt, va_list ap);char * __printf(3, 4) __mallocdevm_kasprintf(struct device *dev, gfp_t gfp, const char *fmt, ...);
/** * devm_alloc_percpu - Resource-managed alloc_percpu * @dev: Device to allocate per-cpu memory for * @type: Type to allocate per-cpu memory for * * Managed alloc_percpu. Per-cpu memory allocated with this function is * automatically freed on driver detach. * * RETURNS: * Pointer to allocated memory on success, NULL on failure. */#define devm_alloc_percpu(dev, type) \ ((typeof(type) __percpu *)__devm_alloc_percpu((dev), sizeof(type), __alignof__(type)))
void __percpu *__devm_alloc_percpu(struct device *dev, size_t size, size_t align);
unsigned long devm_get_free_pages(struct device *dev, gfp_t gfp_mask, unsigned int order);void devm_free_pages(struct device *dev, unsigned long addr);
#ifdef CONFIG_HAS_IOMEM
void __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res);void __iomem *devm_ioremap_resource_wc(struct device *dev, const struct resource *res);
void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index, resource_size_t *size);#else
static inlinevoid __iomem *devm_ioremap_resource(struct device *dev, const struct resource *res){ return IOMEM_ERR_PTR(-EINVAL);}
static inlinevoid __iomem *devm_ioremap_resource_wc(struct device *dev, const struct resource *res){ return IOMEM_ERR_PTR(-EINVAL);}
static inlinevoid __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int index, resource_size_t *size){ return IOMEM_ERR_PTR(-EINVAL);}
#endif
/* allows to add/remove a custom action to devres stack */int devm_remove_action_nowarn(struct device *dev, void (*action)(void *), void *data);
/** * devm_remove_action() - removes previously added custom action * @dev: Device that owns the action * @action: Function implementing the action * @data: Pointer to data passed to @action implementation * * Removes instance of @action previously added by devm_add_action(). * Both action and data should match one of the existing entries. */static inlinevoid devm_remove_action(struct device *dev, void (*action)(void *), void *data){ WARN_ON(devm_remove_action_nowarn(dev, action, data));}
void devm_release_action(struct device *dev, void (*action)(void *), void *data);
int __devm_add_action(struct device *dev, void (*action)(void *), void *data, const char *name);#define devm_add_action(dev, action, data) \ __devm_add_action(dev, action, data, #action)
static inline int __devm_add_action_or_reset(struct device *dev, void (*action)(void *), void *data, const char *name){ int ret;
ret = __devm_add_action(dev, action, data, name); if (ret) action(data);
return ret;}#define devm_add_action_or_reset(dev, action, data) \ __devm_add_action_or_reset(dev, action, data, #action)
bool devm_is_action_added(struct device *dev, void (*action)(void *), void *data);
#endif /* _DEVICE_DEVRES_H_ */