[PATCH 1/2] devm: add helper devm_add_action_or_reset()

Sudip Mukherjee
2015-12-23T12:27:19Z

Add a helper function devm_add_action_or_reset() which will internally
call devm_add_action(). But if devm_add_action() fails then it will
execute the action mentioned and return the error code.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
---

Next patch of the series will use this helper. And from a first glance
more use of this helper will be there.

include/linux/device.h | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/include/linux/device.h b/include/linux/device.h
index f627ba2..f2455d0 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -682,6 +682,18 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
int devm_add_action(struct device *dev, void (*action)(void *), void *data);
void devm_remove_action(struct device *dev, void (*action)(void *), void *data);

+static inline int devm_add_action_or_reset(struct device *dev,
+ void (*action)(void *), void *data)
+{
+ int ret;
+
+ ret = devm_add_action(dev, action, data);
+ if (ret)
+ action(data);
+
+ return ret;
+}
+
struct device_dma_parameters {
/*
* a low level driver may set these to teach IOMMU code about
--
1.9.1