Skip to content

Commit f5e5631

Browse files
andy-shevBartosz Golaszewski
authored andcommitted
devres: Move devm_*_action*() APIs to devres.h
We have a newly created header linux/device/devres.h that gathers device managed APIs, so users won't need to include entire device.h for only these ones. Move devm_*_action*() APIs to devres.h as well. Reviewed-by: Raag Jadav <raag.jadav@intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Zijun Hu <quic_zijuhu@quicinc.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Link: https://lore.kernel.org/r/20250220162238.2738038-2-andriy.shevchenko@linux.intel.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
1 parent 0af2f6b commit f5e5631

File tree

2 files changed

+39
-38
lines changed

2 files changed

+39
-38
lines changed

include/linux/device.h

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -281,44 +281,6 @@ int __must_check device_create_bin_file(struct device *dev,
281281
void device_remove_bin_file(struct device *dev,
282282
const struct bin_attribute *attr);
283283

284-
/* allows to add/remove a custom action to devres stack */
285-
int devm_remove_action_nowarn(struct device *dev, void (*action)(void *), void *data);
286-
287-
/**
288-
* devm_remove_action() - removes previously added custom action
289-
* @dev: Device that owns the action
290-
* @action: Function implementing the action
291-
* @data: Pointer to data passed to @action implementation
292-
*
293-
* Removes instance of @action previously added by devm_add_action().
294-
* Both action and data should match one of the existing entries.
295-
*/
296-
static inline
297-
void devm_remove_action(struct device *dev, void (*action)(void *), void *data)
298-
{
299-
WARN_ON(devm_remove_action_nowarn(dev, action, data));
300-
}
301-
302-
void devm_release_action(struct device *dev, void (*action)(void *), void *data);
303-
304-
int __devm_add_action(struct device *dev, void (*action)(void *), void *data, const char *name);
305-
#define devm_add_action(dev, action, data) \
306-
__devm_add_action(dev, action, data, #action)
307-
308-
static inline int __devm_add_action_or_reset(struct device *dev, void (*action)(void *),
309-
void *data, const char *name)
310-
{
311-
int ret;
312-
313-
ret = __devm_add_action(dev, action, data, name);
314-
if (ret)
315-
action(data);
316-
317-
return ret;
318-
}
319-
#define devm_add_action_or_reset(dev, action, data) \
320-
__devm_add_action_or_reset(dev, action, data, #action)
321-
322284
/**
323285
* devm_alloc_percpu - Resource-managed alloc_percpu
324286
* @dev: Device to allocate per-cpu memory for

include/linux/device/devres.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/overflow.h>
99
#include <linux/stdarg.h>
1010
#include <linux/types.h>
11+
#include <asm/bug.h>
1112

1213
struct device;
1314
struct device_node;
@@ -126,4 +127,42 @@ void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int in
126127

127128
#endif
128129

130+
/* allows to add/remove a custom action to devres stack */
131+
int devm_remove_action_nowarn(struct device *dev, void (*action)(void *), void *data);
132+
133+
/**
134+
* devm_remove_action() - removes previously added custom action
135+
* @dev: Device that owns the action
136+
* @action: Function implementing the action
137+
* @data: Pointer to data passed to @action implementation
138+
*
139+
* Removes instance of @action previously added by devm_add_action().
140+
* Both action and data should match one of the existing entries.
141+
*/
142+
static inline
143+
void devm_remove_action(struct device *dev, void (*action)(void *), void *data)
144+
{
145+
WARN_ON(devm_remove_action_nowarn(dev, action, data));
146+
}
147+
148+
void devm_release_action(struct device *dev, void (*action)(void *), void *data);
149+
150+
int __devm_add_action(struct device *dev, void (*action)(void *), void *data, const char *name);
151+
#define devm_add_action(dev, action, data) \
152+
__devm_add_action(dev, action, data, #action)
153+
154+
static inline int __devm_add_action_or_reset(struct device *dev, void (*action)(void *),
155+
void *data, const char *name)
156+
{
157+
int ret;
158+
159+
ret = __devm_add_action(dev, action, data, name);
160+
if (ret)
161+
action(data);
162+
163+
return ret;
164+
}
165+
#define devm_add_action_or_reset(dev, action, data) \
166+
__devm_add_action_or_reset(dev, action, data, #action)
167+
129168
#endif /* _DEVICE_DEVRES_H_ */

0 commit comments

Comments
 (0)