From: Sachin Kamat <sachin.kamat@linaro.org>
To: linux-iio@vger.kernel.org
Cc: jic23@kernel.org, lars@metafoo.de, sachin.kamat@linaro.org
Subject: [PATCH 01/33] iio: core: Implement devm_iio_device_{register,unregister}
Date: Tue, 29 Oct 2013 17:09:24 +0530 [thread overview]
Message-ID: <1383046796-329-2-git-send-email-sachin.kamat@linaro.org> (raw)
In-Reply-To: <1383046796-329-1-git-send-email-sachin.kamat@linaro.org>
Add device managed devm_iio_device_{register,unregister}()
to automatically unregister IIO drivers thus leading to
simplified IIO driver code.
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Tested-by: Lars-Peter Clausen <lars@metafoo.de>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
---
Documentation/driver-model/devres.txt | 2 ++
drivers/iio/industrialio-core.c | 59 +++++++++++++++++++++++++++++++++
include/linux/iio/iio.h | 3 ++
3 files changed, 64 insertions(+)
diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
index fcb34a5..ffeab1d 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -242,6 +242,8 @@ IIO
devm_iio_device_free()
devm_iio_trigger_alloc()
devm_iio_trigger_free()
+ devm_iio_device_register()
+ devm_iio_device_unregister()
IO region
devm_request_region()
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 18f72e3..1c280b5 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1161,6 +1161,65 @@ void iio_device_unregister(struct iio_dev *indio_dev)
mutex_unlock(&indio_dev->info_exist_lock);
}
EXPORT_SYMBOL(iio_device_unregister);
+
+static void devm_iio_device_unreg(struct device *dev, void *res)
+{
+ iio_device_unregister(*(struct iio_dev **)res);
+}
+
+/**
+ * devm_iio_device_register - Resource-managed iio_device_register()
+ * @dev: Device to allocate iio_dev for
+ * @indio_dev: Device structure filled by the device driver
+ *
+ * Managed iio_device_register. The IIO device registered with this
+ * function is automatically unregistered on driver detach. This function
+ * calls iio_device_register() internally. Refer to that function for more
+ * information.
+ *
+ * If an iio_dev registered with this function needs to be unregistered
+ * separately, devm_iio_device_unregister() must be used.
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev)
+{
+ struct iio_dev **ptr;
+ int ret;
+
+ ptr = devres_alloc(devm_iio_device_unreg, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return -ENOMEM;
+
+ *ptr = indio_dev;
+ ret = iio_device_register(indio_dev);
+ if (!ret)
+ devres_add(dev, ptr);
+ else
+ devres_free(ptr);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(devm_iio_device_register);
+
+/**
+ * devm_iio_device_unregister - Resource-managed iio_device_unregister()
+ * @dev: Device this iio_dev belongs to
+ * @indio_dev: the iio_dev associated with the device
+ *
+ * Unregister iio_dev registered with devm_iio_device_register().
+ */
+void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev)
+{
+ int rc;
+
+ rc = devres_release(dev, devm_iio_device_unreg,
+ devm_iio_device_match, indio_dev);
+ WARN_ON(rc);
+}
+EXPORT_SYMBOL_GPL(devm_iio_device_unregister);
+
subsys_initcall(iio_init);
module_exit(iio_exit);
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 256a90a..a8cabda 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -510,6 +510,9 @@ int iio_device_register(struct iio_dev *indio_dev);
**/
void iio_device_unregister(struct iio_dev *indio_dev);
+int devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev);
+void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev);
+
/**
* iio_push_event() - try to add event to the list for userspace reading
* @indio_dev: IIO device structure
--
1.7.9.5
next prev parent reply other threads:[~2013-10-29 11:39 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-29 11:39 [PATCH Resend 00/33] iio: Implement and use devm_iio_device_register Sachin Kamat
2013-10-29 11:39 ` Sachin Kamat [this message]
2013-11-09 17:44 ` [PATCH 01/33] iio: core: Implement devm_iio_device_{register,unregister} Jonathan Cameron
2013-10-29 11:39 ` [PATCH 02/33] iio: core: Move kernel doc to the right location Sachin Kamat
2013-11-09 17:45 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 03/33] iio: accel: kxsd9: Use devm_iio_device_register Sachin Kamat
2013-11-09 17:47 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 04/33] iio: adc: mcp3422: " Sachin Kamat
2013-11-09 17:54 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 05/33] iio: adc: twl6030-gpadc: " Sachin Kamat
2013-11-23 13:26 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 06/33] iio: adc: viperboard: " Sachin Kamat
2013-11-23 13:31 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 07/33] iio: dac: ad5421: " Sachin Kamat
2013-11-23 13:34 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 08/33] iio: dac: ad5755: " Sachin Kamat
2013-11-23 13:35 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 09/33] iio: dac: max517: " Sachin Kamat
2013-11-23 13:37 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 10/33] iio: dac: mcp4725: " Sachin Kamat
2013-11-23 13:39 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 11/33] iio: gyro: adis16130: " Sachin Kamat
2013-11-23 13:43 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 12/33] iio: gyro: adxrs450: " Sachin Kamat
2013-11-23 13:45 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 13/33] iio: light: vcnl4000: " Sachin Kamat
2013-11-23 13:48 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 14/33] staging: iio: adis16220: " Sachin Kamat
2013-11-23 18:01 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 15/33] staging: iio: ad7816: " Sachin Kamat
2013-11-23 18:04 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 16/33] staging: iio: lpc32xx_adc: " Sachin Kamat
2013-11-23 18:06 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 17/33] staging: iio: addac: " Sachin Kamat
2013-11-23 18:08 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 18/33] staging: iio: ad7150: " Sachin Kamat
2013-11-23 18:10 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 19/33] staging: iio: ad7746: " Sachin Kamat
2013-11-23 18:12 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 20/33] staging: iio: ad5930: " Sachin Kamat
2013-11-23 18:14 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 21/33] staging: iio: ad9850: " Sachin Kamat
2013-11-23 18:15 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 22/33] staging: iio: ad9852: " Sachin Kamat
2013-11-23 18:17 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 23/33] staging: iio: ad9910: " Sachin Kamat
2013-11-23 18:18 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 24/33] staging: iio: ad9951: " Sachin Kamat
2013-11-23 18:19 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 25/33] staging: iio: adis16060: " Sachin Kamat
2013-11-23 18:22 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 26/33] staging: iio: isl29018: " Sachin Kamat
2013-11-23 18:24 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 27/33] staging: iio: isl29028: " Sachin Kamat
2013-11-23 18:28 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 28/33] staging: iio: tsl2583: " Sachin Kamat
2013-11-23 18:30 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 29/33] staging: iio: tsl2x7x_core: " Sachin Kamat
2013-11-23 18:31 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 30/33] staging: iio: ade7854: " Sachin Kamat
2013-11-23 18:33 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 31/33] staging: iio: ad2s1200: " Sachin Kamat
2013-11-23 18:36 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 32/33] staging: iio: ad2s90: " Sachin Kamat
2013-11-23 18:37 ` Jonathan Cameron
2013-10-29 11:39 ` [PATCH 33/33] staging: iio: ad7152: " Sachin Kamat
2013-11-23 18:39 ` Jonathan Cameron
2013-10-29 13:11 ` [PATCH Resend 00/33] iio: Implement and use devm_iio_device_register Jonathan Cameron
2013-10-30 8:31 ` Sachin Kamat
2013-10-30 17:12 ` Jonathan Cameron
2013-11-23 18:43 ` Jonathan Cameron
2013-11-27 4:40 ` Sachin Kamat
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=1383046796-329-2-git-send-email-sachin.kamat@linaro.org \
--to=sachin.kamat@linaro.org \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).