Commit 035c70ae authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Jonathan Cameron

iio: triggers: Use macros to avoid boilerplate assignment of owner.

This trig_ops.owner assignment occurs in all trigger drivers and
can be simply automated using a macro as has been done in many
other places in the kernel.
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: default avatarLars-Peter Clausen <lars@metafoo.de>
parent 63b19547
...@@ -66,10 +66,13 @@ ATTRIBUTE_GROUPS(iio_trig_dev); ...@@ -66,10 +66,13 @@ ATTRIBUTE_GROUPS(iio_trig_dev);
static struct iio_trigger *__iio_trigger_find_by_name(const char *name); static struct iio_trigger *__iio_trigger_find_by_name(const char *name);
int iio_trigger_register(struct iio_trigger *trig_info) int __iio_trigger_register(struct iio_trigger *trig_info,
struct module *this_mod)
{ {
int ret; int ret;
trig_info->owner = this_mod;
/* trig_info->ops is required for the module member */ /* trig_info->ops is required for the module member */
if (!trig_info->ops) if (!trig_info->ops)
return -EINVAL; return -EINVAL;
...@@ -105,7 +108,7 @@ int iio_trigger_register(struct iio_trigger *trig_info) ...@@ -105,7 +108,7 @@ int iio_trigger_register(struct iio_trigger *trig_info)
ida_simple_remove(&iio_trigger_ida, trig_info->id); ida_simple_remove(&iio_trigger_ida, trig_info->id);
return ret; return ret;
} }
EXPORT_SYMBOL(iio_trigger_register); EXPORT_SYMBOL(__iio_trigger_register);
void iio_trigger_unregister(struct iio_trigger *trig_info) void iio_trigger_unregister(struct iio_trigger *trig_info)
{ {
...@@ -663,9 +666,10 @@ static void devm_iio_trigger_unreg(struct device *dev, void *res) ...@@ -663,9 +666,10 @@ static void devm_iio_trigger_unreg(struct device *dev, void *res)
} }
/** /**
* devm_iio_trigger_register - Resource-managed iio_trigger_register() * __devm_iio_trigger_register - Resource-managed iio_trigger_register()
* @dev: device this trigger was allocated for * @dev: device this trigger was allocated for
* @trig_info: trigger to register * @trig_info: trigger to register
* @this_mod: module registering the trigger
* *
* Managed iio_trigger_register(). The IIO trigger registered with this * Managed iio_trigger_register(). The IIO trigger registered with this
* function is automatically unregistered on driver detach. This function * function is automatically unregistered on driver detach. This function
...@@ -678,7 +682,9 @@ static void devm_iio_trigger_unreg(struct device *dev, void *res) ...@@ -678,7 +682,9 @@ static void devm_iio_trigger_unreg(struct device *dev, void *res)
* RETURNS: * RETURNS:
* 0 on success, negative error number on failure. * 0 on success, negative error number on failure.
*/ */
int devm_iio_trigger_register(struct device *dev, struct iio_trigger *trig_info) int __devm_iio_trigger_register(struct device *dev,
struct iio_trigger *trig_info,
struct module *this_mod)
{ {
struct iio_trigger **ptr; struct iio_trigger **ptr;
int ret; int ret;
...@@ -688,7 +694,7 @@ int devm_iio_trigger_register(struct device *dev, struct iio_trigger *trig_info) ...@@ -688,7 +694,7 @@ int devm_iio_trigger_register(struct device *dev, struct iio_trigger *trig_info)
return -ENOMEM; return -ENOMEM;
*ptr = trig_info; *ptr = trig_info;
ret = iio_trigger_register(trig_info); ret = __iio_trigger_register(trig_info, this_mod);
if (!ret) if (!ret)
devres_add(dev, ptr); devres_add(dev, ptr);
else else
...@@ -696,7 +702,7 @@ int devm_iio_trigger_register(struct device *dev, struct iio_trigger *trig_info) ...@@ -696,7 +702,7 @@ int devm_iio_trigger_register(struct device *dev, struct iio_trigger *trig_info)
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(devm_iio_trigger_register); EXPORT_SYMBOL_GPL(__devm_iio_trigger_register);
/** /**
* devm_iio_trigger_unregister - Resource-managed iio_trigger_unregister() * devm_iio_trigger_unregister - Resource-managed iio_trigger_unregister()
......
...@@ -62,6 +62,7 @@ struct iio_trigger_ops { ...@@ -62,6 +62,7 @@ struct iio_trigger_ops {
**/ **/
struct iio_trigger { struct iio_trigger {
const struct iio_trigger_ops *ops; const struct iio_trigger_ops *ops;
struct module *owner;
int id; int id;
const char *name; const char *name;
struct device dev; struct device dev;
...@@ -87,14 +88,14 @@ static inline struct iio_trigger *to_iio_trigger(struct device *d) ...@@ -87,14 +88,14 @@ static inline struct iio_trigger *to_iio_trigger(struct device *d)
static inline void iio_trigger_put(struct iio_trigger *trig) static inline void iio_trigger_put(struct iio_trigger *trig)
{ {
module_put(trig->ops->owner); module_put(trig->owner);
put_device(&trig->dev); put_device(&trig->dev);
} }
static inline struct iio_trigger *iio_trigger_get(struct iio_trigger *trig) static inline struct iio_trigger *iio_trigger_get(struct iio_trigger *trig)
{ {
get_device(&trig->dev); get_device(&trig->dev);
__module_get(trig->ops->owner); __module_get(trig->owner);
return trig; return trig;
} }
...@@ -127,10 +128,16 @@ static inline void *iio_trigger_get_drvdata(struct iio_trigger *trig) ...@@ -127,10 +128,16 @@ static inline void *iio_trigger_get_drvdata(struct iio_trigger *trig)
* iio_trigger_register() - register a trigger with the IIO core * iio_trigger_register() - register a trigger with the IIO core
* @trig_info: trigger to be registered * @trig_info: trigger to be registered
**/ **/
int iio_trigger_register(struct iio_trigger *trig_info); #define iio_trigger_register(trig_info) \
__iio_trigger_register((trig_info), THIS_MODULE)
int devm_iio_trigger_register(struct device *dev, int __iio_trigger_register(struct iio_trigger *trig_info,
struct iio_trigger *trig_info); struct module *this_mod);
#define devm_iio_trigger_register(dev, trig_info) \
__devm_iio_trigger_register((dev), (trig_info), THIS_MODULE)
int __devm_iio_trigger_register(struct device *dev,
struct iio_trigger *trig_info,
struct module *this_mod);
/** /**
* iio_trigger_unregister() - unregister a trigger from the core * iio_trigger_unregister() - unregister a trigger from the core
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment