diff mbox series

[v2,2/3] devres: Add devm_is_action_added() helper

Message ID 20250220162238.2738038-3-andriy.shevchenko@linux.intel.com
State New
Headers show
Series [v2,1/3] devres: Move devm_*_action*() APIs to devres.h | expand

Commit Message

Andy Shevchenko Feb. 20, 2025, 4:20 p.m. UTC
In some code we would like to know if the action in device managed resources
was added by devm_add_action() family of calls. Introduce a helper for that.

Reviewed-by: Raag Jadav <raag.jadav@intel.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/base/devres.c         | 11 +++++++++++
 include/linux/device/devres.h |  2 ++
 2 files changed, 13 insertions(+)

Comments

Zijun Hu Feb. 21, 2025, 3:34 a.m. UTC | #1
On 2/21/2025 12:20 AM, Andy Shevchenko wrote:
> In some code we would like to know if the action in device managed resources
> was added by devm_add_action() family of calls. Introduce a helper for that.
> 
> Reviewed-by: Raag Jadav <raag.jadav@intel.com>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/base/devres.c         | 11 +++++++++++
>  include/linux/device/devres.h |  2 ++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/drivers/base/devres.c b/drivers/base/devres.c
> index 93e7779ef21e..7c2babfa9396 100644
> --- a/drivers/base/devres.c
> +++ b/drivers/base/devres.c
> @@ -749,6 +749,17 @@ int __devm_add_action(struct device *dev, void (*action)(void *), void *data, co
>  }
>  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
>   * @dev: Device that owns the action
> diff --git a/include/linux/device/devres.h b/include/linux/device/devres.h
> index 9cd1787ef28e..ae696d10faff 100644
> --- a/include/linux/device/devres.h
> +++ b/include/linux/device/devres.h
> @@ -165,4 +165,6 @@ static inline int __devm_add_action_or_reset(struct device *dev, void (*action)(
>  #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_ */

Reviewed-by: Zijun Hu <quic_zijuhu@quicinc.com>
diff mbox series

Patch

diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index 93e7779ef21e..7c2babfa9396 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -749,6 +749,17 @@  int __devm_add_action(struct device *dev, void (*action)(void *), void *data, co
 }
 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
  * @dev: Device that owns the action
diff --git a/include/linux/device/devres.h b/include/linux/device/devres.h
index 9cd1787ef28e..ae696d10faff 100644
--- a/include/linux/device/devres.h
+++ b/include/linux/device/devres.h
@@ -165,4 +165,6 @@  static inline int __devm_add_action_or_reset(struct device *dev, void (*action)(
 #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_ */