Message ID | 20250220141645.2694039-4-andriy.shevchenko@linux.intel.com |
---|---|
State | New |
Headers | show |
Series | gpiolib: finish conversion to devm_*_action*() APIs | expand |
On Thu, Feb 20, 2025 at 05:30:07PM +0200, Raag Jadav wrote: > On Thu, Feb 20, 2025 at 03:44:59PM +0200, Andy Shevchenko wrote: ... > > +/* Same as devm_remove_action(), but doesn't WARN() if action wasn't added before */ > > +static inline > > +void devm_remove_action_optional(struct device *dev, void (*action)(void *), void *data) > > +{ > > + int ret; > > + > > + ret = devm_remove_action_nowarn(dev, action, data); > > + if (ret == -ENOENT) > > + return; > > + > > + WARN_ON(ret); > > +} > > Trying to wrap my head around this one, can't the user simply do > > if (devm_is_action_added()) > devm_remove_action/_nowarn(); Hmm... Actually it sounds like a good point. I will check (and I like the idea of dropping this patch).
On Thu, Feb 20, 2025 at 05:51:42PM +0200, Raag Jadav wrote: > On Thu, Feb 20, 2025 at 05:40:24PM +0200, Andy Shevchenko wrote: > > On Thu, Feb 20, 2025 at 05:30:07PM +0200, Raag Jadav wrote: > > > On Thu, Feb 20, 2025 at 03:44:59PM +0200, Andy Shevchenko wrote: ... > > > > +/* Same as devm_remove_action(), but doesn't WARN() if action wasn't added before */ > > > > +static inline > > > > +void devm_remove_action_optional(struct device *dev, void (*action)(void *), void *data) > > > > +{ > > > > + int ret; > > > > + > > > > + ret = devm_remove_action_nowarn(dev, action, data); > > > > + if (ret == -ENOENT) > > > > + return; > > > > + > > > > + WARN_ON(ret); > > > > +} > > > > > > Trying to wrap my head around this one, can't the user simply do > > > > > > if (devm_is_action_added()) > > > devm_remove_action/_nowarn(); > > > > Hmm... Actually it sounds like a good point. I will check > > (and I like the idea of dropping this patch). > > And perhaps > > s/devm_is_action_added/devm_action_is_added > > But whichever you think _is best_ ;) I thought about that and that's why I would like to stick to the my variant. Thanks for the review!
diff --git a/include/linux/device/devres.h b/include/linux/device/devres.h index ae696d10faff..4daebbf7f227 100644 --- a/include/linux/device/devres.h +++ b/include/linux/device/devres.h @@ -145,6 +145,19 @@ void devm_remove_action(struct device *dev, void (*action)(void *), void *data) WARN_ON(devm_remove_action_nowarn(dev, action, data)); } +/* Same as devm_remove_action(), but doesn't WARN() if action wasn't added before */ +static inline +void devm_remove_action_optional(struct device *dev, void (*action)(void *), void *data) +{ + int ret; + + ret = devm_remove_action_nowarn(dev, action, data); + if (ret == -ENOENT) + return; + + WARN_ON(ret); +} + 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);
Add a new helper to remove an action that was added via devm_add_action() family of calls, but not warn in the cases where action wasn't found since it is optional and wasn't even added. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> --- include/linux/device/devres.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)