Immutable tag for the driver core tree to pull from

devres: Move devm_*_action*() APIs to devres.h
 devres: Add devm_is_action_added() helper
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEFp3rbAvDxGAT0sefEacuoBRx13IFAmgPMD4ACgkQEacuoBRx
 13KP1Q//RV+2Nk8YDBj30kkqKzFy3SSNidLxW4CsV80H3mNbhWL/8BnEbR04i6Bd
 N7FFuyrGjmIjjJmV20eRbsPSFbGmnwElmOokwkHeEX+9BSOyyyRjoP0FtD8lw6uP
 3idM5nU1k+EJHojk7Cevw1Mz/MAq+QindQeABjYkwvYSonVXieI3OKSPDAxzRKxU
 gxYh5lDPs2nrNmVmQtP36pJMlBDHZUayhwci+g8wh4wtkjzYLKfuQWBVD8dKALRf
 N6at3je5zFF3FSvP1zs7O7iZu3mC/GvVE6NSUzWu0XTeqhqRsT58FKQ7DHX5KbQN
 opgY6sAiD6WSLv30YcdYcH8XxUVPsezibW4mNuhF5AK3vsnbMKTzrCKOWK1ijTJP
 bdFI0yN5FuDJjpieCcWeDovovlZE2unTgn831pplncIHOF3sTUIOnC65sqO4Oawh
 oQsLkZH9Dq3u+GH4pgo+w7MVgnI5YoUMcod2uHbIpXCaz240DLWtzv5mU1lEA3Pz
 kCbNOmSDgjV7SDIw624xGBk3Iw+XnzFlDiq+mCqK6DEPLt4VK/3BBcgTMGmDdt8K
 VSx8OKARpTWbjXp6wUVWuaEZrMZRqwUqAVqBXy6MqXK6RGsXum5G2iPzr/LsLFOo
 sX5dtw03ZtUXHuD9IV08yqQoUleKq3K0bNCM5PRCuGe5cUZQsmA=
 =1HCW
 -----END PGP SIGNATURE-----

Merge tag 'gpiod-devm-is-action-added-for-v6.16-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/brgl/linux into driver-core-next

Immutable tag for the driver core tree to pull from

devres: Move devm_*_action*() APIs to devres.h
devres: Add devm_is_action_added() helper

* tag 'gpiod-devm-is-action-added-for-v6.16-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/brgl/linux:
  devres: Add devm_is_action_added() helper
  devres: Move devm_*_action*() APIs to devres.h
This commit is contained in:
Greg Kroah-Hartman 2025-04-28 10:18:29 +02:00
commit 0e4965c80e
3 changed files with 52 additions and 38 deletions

View file

@ -759,6 +759,17 @@ int __devm_add_action(struct device *dev, void (*action)(void *), void *data, co
} }
EXPORT_SYMBOL_GPL(__devm_add_action); EXPORT_SYMBOL_GPL(__devm_add_action);
bool devm_is_action_added(struct device *dev, void (*action)(void *), void *data)
{
struct action_devres devres = {
.data = data,
.action = action,
};
return devres_find(dev, devm_action_release, devm_action_match, &devres);
}
EXPORT_SYMBOL_GPL(devm_is_action_added);
/** /**
* devm_remove_action_nowarn() - removes previously added custom action * devm_remove_action_nowarn() - removes previously added custom action
* @dev: Device that owns the action * @dev: Device that owns the action

View file

@ -281,44 +281,6 @@ int __must_check device_create_bin_file(struct device *dev,
void device_remove_bin_file(struct device *dev, void device_remove_bin_file(struct device *dev,
const struct bin_attribute *attr); const struct bin_attribute *attr);
/* 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 inline
void 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)
/** /**
* devm_alloc_percpu - Resource-managed alloc_percpu * devm_alloc_percpu - Resource-managed alloc_percpu
* @dev: Device to allocate per-cpu memory for * @dev: Device to allocate per-cpu memory for

View file

@ -8,6 +8,7 @@
#include <linux/overflow.h> #include <linux/overflow.h>
#include <linux/stdarg.h> #include <linux/stdarg.h>
#include <linux/types.h> #include <linux/types.h>
#include <asm/bug.h>
struct device; struct device;
struct device_node; struct device_node;
@ -126,4 +127,44 @@ void __iomem *devm_of_iomap(struct device *dev, struct device_node *node, int in
#endif #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 inline
void 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_ */ #endif /* _DEVICE_DEVRES_H_ */