All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: linux-iio@vger.kernel.org
Cc: Jonathan Cameron <jic23@kernel.org>
Subject: [PATCH 02/38] iio: triggers: Use macros to avoid boilerplate assignment of owner.
Date: Mon, 29 May 2017 16:51:18 +0100	[thread overview]
Message-ID: <20170529155154.22580-3-jic23@kernel.org> (raw)
In-Reply-To: <20170529155154.22580-1-jic23@kernel.org>

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: Jonathan Cameron <jic23@kernel.org>
---
 drivers/iio/industrialio-trigger.c | 18 ++++++++++++------
 include/linux/iio/trigger.h        | 19 +++++++++++++------
 2 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index 067e58863592..6863ed5a61da 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -66,10 +66,13 @@ ATTRIBUTE_GROUPS(iio_trig_dev);
 
 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;
 
+	trig_info->owner = this_mod;
+
 	/* trig_info->ops is required for the module member */
 	if (!trig_info->ops)
 		return -EINVAL;
@@ -105,7 +108,7 @@ int iio_trigger_register(struct iio_trigger *trig_info)
 	ida_simple_remove(&iio_trigger_ida, trig_info->id);
 	return ret;
 }
-EXPORT_SYMBOL(iio_trigger_register);
+EXPORT_SYMBOL(__iio_trigger_register);
 
 void iio_trigger_unregister(struct iio_trigger *trig_info)
 {
@@ -662,9 +665,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
  * @trig_info:	trigger to register
+ * @this_mod:   module registering the trigger
  *
  * Managed iio_trigger_register().  The IIO trigger registered with this
  * function is automatically unregistered on driver detach. This function
@@ -677,7 +681,9 @@ static void devm_iio_trigger_unreg(struct device *dev, void *res)
  * RETURNS:
  * 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;
 	int ret;
@@ -687,7 +693,7 @@ int devm_iio_trigger_register(struct device *dev, struct iio_trigger *trig_info)
 		return -ENOMEM;
 
 	*ptr = trig_info;
-	ret = iio_trigger_register(trig_info);
+	ret = __iio_trigger_register(trig_info, this_mod);
 	if (!ret)
 		devres_add(dev, ptr);
 	else
@@ -695,7 +701,7 @@ int devm_iio_trigger_register(struct device *dev, struct iio_trigger *trig_info)
 
 	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()
diff --git a/include/linux/iio/trigger.h b/include/linux/iio/trigger.h
index ea08302f2d7b..2e1800ad265b 100644
--- a/include/linux/iio/trigger.h
+++ b/include/linux/iio/trigger.h
@@ -62,6 +62,7 @@ struct iio_trigger_ops {
  **/
 struct iio_trigger {
 	const struct iio_trigger_ops	*ops;
+	struct module			*owner;
 	int				id;
 	const char			*name;
 	struct device			dev;
@@ -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)
 {
-	module_put(trig->ops->owner);
+	module_put(trig->owner);
 	put_device(&trig->dev);
 }
 
 static inline struct iio_trigger *iio_trigger_get(struct iio_trigger *trig)
 {
 	get_device(&trig->dev);
-	__module_get(trig->ops->owner);
+	__module_get(trig->owner);
 
 	return 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
  * @trig_info:	trigger to be registered
  **/
-int iio_trigger_register(struct iio_trigger *trig_info);
-
-int devm_iio_trigger_register(struct device *dev,
-			      struct iio_trigger *trig_info);
+#define iio_trigger_register(trig_info) \
+	__iio_trigger_register(trig_info, THIS_MODULE)
+int __iio_trigger_register(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
-- 
2.13.0


  parent reply	other threads:[~2017-05-29 15:52 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-29 15:51 [PATCH 00/38] IIO: Drop manual assignment of THIS_MODULE Jonathan Cameron
2017-05-29 15:51 ` [PATCH 01/38] iio: Use macro magic to avoid manual assign of driver_module Jonathan Cameron
2017-06-03  8:37   ` Jonathan Cameron
2017-06-12 16:13   ` Lars-Peter Clausen
2017-05-29 15:51 ` Jonathan Cameron [this message]
2017-05-29 15:51 ` [PATCH 03/38] coccinelle: Add an iio_no_owner semantic patch to drop driver_owner Jonathan Cameron
2017-05-29 15:51 ` [PATCH 04/38] iio:adc: drop assign iio_info.driver_module and iio_trigger_ops.owner Jonathan Cameron
2017-05-29 15:51 ` [PATCH 05/38] iio:accel: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 06/38] iio:amplifiers:ad8366 " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 07/38] iio:chemical: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 08/38] iio:common: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 09/38] iio:counter:104-quad-8 drop assign iio_info.driver_module Jonathan Cameron
2017-05-29 15:51 ` [PATCH 10/38] iio:dac: drop assignment of iio_info.driver_module Jonathan Cameron
2017-05-29 15:51 ` [PATCH 11/38] iio:dummy: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 12/38] iio:frequency: drop assign iio_info.driver_module Jonathan Cameron
2017-05-29 15:51 ` [PATCH 13/38] iio:gyro: drop assign iio_info.driver_module and iio_trigger_ops.owner Jonathan Cameron
2017-05-29 15:51 ` [PATCH 14/38] iio:health: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 15/38] iio:humidity: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 16/38] iio:imu: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 17/38] iio:light: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 18/38] iio:magnetometer: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 19/38] iio:orientation: drop assign iio_info.driver_module Jonathan Cameron
2017-05-29 15:51 ` [PATCH 20/38] iio:dpot: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 21/38] iio:potentiostat:lmp91000 drop assign iio_info.driver_module and iio_trigger_ops.owner Jonathan Cameron
2017-05-29 15:51 ` [PATCH 22/38] iio:pressure: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 23/38] iio:proximity: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 24/38] iio:temperature: drop assignment of iio_info.driver_module Jonathan Cameron
2017-05-29 15:51 ` [PATCH 25/38] iio:triggers: drop assign iio_info.driver_module and iio_trigger_ops.owner Jonathan Cameron
2017-05-29 15:51 ` [PATCH 26/38] staging:iio:accel: drop assignment of iio_info.driver_module Jonathan Cameron
2017-05-29 15:51 ` [PATCH 27/38] staging:iio:adc: drop assign iio_info.driver_module Jonathan Cameron
2017-05-29 15:51 ` [PATCH 28/38] staging:iio:cdc: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 29/38] staging:iio:frequency: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 30/38] staging:iio:gyro:adis16060 " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 31/38] staging:iio:ad5933: " Jonathan Cameron
2017-05-29 15:51 ` [PATCH 32/38] staging:iio:meter: drop assign iio_info.driver_module and iio_trigger_ops.owner Jonathan Cameron
2017-05-29 15:51 ` [PATCH 33/38] iio:resolver: drop assignment of iio_info.driver_module Jonathan Cameron
2017-05-29 15:51 ` [PATCH 34/38] iio:adc: drop assignment of iio_trigger_ops.owner Jonathan Cameron
2017-05-29 15:51 ` [PATCH 35/38] staging:iio:light:tsl2x7x drop assignment of driver_module Jonathan Cameron
2017-05-29 15:51 ` [PATCH 36/38] input: tsc2007 - drop the driver_module assignment in iio interface Jonathan Cameron
     [not found]   ` <20170529155154.22580-37-jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-05-30  2:41     ` Dmitry Torokhov
2017-05-30  2:41       ` Dmitry Torokhov
2017-05-29 15:51 ` [PATCH 37/38] platform/x86: toshiba_acpi: drop assignment of iio_info.driver_module Jonathan Cameron
2017-05-29 17:56   ` Andy Shevchenko
2017-06-07 14:53   ` Azael Avalos
2017-06-11 14:03     ` Jonathan Cameron
2017-05-29 15:51 ` [PATCH 38/38] iio: drop iio_info.driver_module and iio_trigger_ops.owner Jonathan Cameron
2017-06-12 16:16   ` Lars-Peter Clausen
2017-06-24 20:57     ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170529155154.22580-3-jic23@kernel.org \
    --to=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.