linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <jic23@kernel.org>, Alexandru Ardelean <alexandru.ardelean@analog.com>
Subject: [PATCH 2/3] iio: dummy: convert events to device-managed handlers
Date: Thu, 3 Dec 2020 11:50:04 +0200	[thread overview]
Message-ID: <20201203095005.72252-2-alexandru.ardelean@analog.com> (raw)
In-Reply-To: <20201203095005.72252-1-alexandru.ardelean@analog.com>

This change converts the iio_simple_dummy_events_register() function to use
device-managed functions/equivalents.
The iio_dummy_evgen_release_irq() function needs to be carried over a
devm_add_action_or_reset() handler.

With this the iio_simple_dummy_events_unregister() function can be removed,
and so can it's usage/call.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/dummy/iio_simple_dummy.c        |  8 +---
 drivers/iio/dummy/iio_simple_dummy.h        |  9 +---
 drivers/iio/dummy/iio_simple_dummy_events.c | 53 +++++++++------------
 3 files changed, 26 insertions(+), 44 deletions(-)

diff --git a/drivers/iio/dummy/iio_simple_dummy.c b/drivers/iio/dummy/iio_simple_dummy.c
index 2a2e62f780a1..a746b34ae7a3 100644
--- a/drivers/iio/dummy/iio_simple_dummy.c
+++ b/drivers/iio/dummy/iio_simple_dummy.c
@@ -626,13 +626,13 @@ static struct iio_sw_device *iio_dummy_probe(const char *name)
 	/* Specify that device provides sysfs type interfaces */
 	indio_dev->modes = INDIO_DIRECT_MODE;
 
-	ret = iio_simple_dummy_events_register(indio_dev);
+	ret = iio_simple_dummy_events_register(parent, indio_dev);
 	if (ret < 0)
 		return ERR_PTR(ret);
 
 	ret = iio_simple_dummy_configure_buffer(indio_dev);
 	if (ret < 0)
-		goto error_unregister_events;
+		return ERR_PTR(ret);
 
 	ret = iio_device_register(indio_dev);
 	if (ret < 0)
@@ -643,8 +643,6 @@ static struct iio_sw_device *iio_dummy_probe(const char *name)
 	return swd;
 error_unconfigure_buffer:
 	iio_simple_dummy_unconfigure_buffer(indio_dev);
-error_unregister_events:
-	iio_simple_dummy_events_unregister(indio_dev);
 	return ERR_PTR(ret);
 }
 
@@ -672,8 +670,6 @@ static int iio_dummy_remove(struct iio_sw_device *swd)
 	/* Buffered capture related cleanup */
 	iio_simple_dummy_unconfigure_buffer(indio_dev);
 
-	iio_simple_dummy_events_unregister(indio_dev);
-
 	return 0;
 }
 
diff --git a/drivers/iio/dummy/iio_simple_dummy.h b/drivers/iio/dummy/iio_simple_dummy.h
index a91622ac54e0..b1ca6e97ed3f 100644
--- a/drivers/iio/dummy/iio_simple_dummy.h
+++ b/drivers/iio/dummy/iio_simple_dummy.h
@@ -76,21 +76,16 @@ int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
 				       enum iio_event_info info, int val,
 				       int val2);
 
-int iio_simple_dummy_events_register(struct iio_dev *indio_dev);
-void iio_simple_dummy_events_unregister(struct iio_dev *indio_dev);
+int iio_simple_dummy_events_register(struct device *parent, struct iio_dev *indio_dev);
 
 #else /* Stubs for when events are disabled at compile time */
 
 static inline int
-iio_simple_dummy_events_register(struct iio_dev *indio_dev)
+iio_simple_dummy_events_register(struct device *parent, struct iio_dev *indio_dev)
 {
 	return 0;
 }
 
-static inline void
-iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
-{}
-
 #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/
 
 /**
diff --git a/drivers/iio/dummy/iio_simple_dummy_events.c b/drivers/iio/dummy/iio_simple_dummy_events.c
index 63a2b844be50..8f51fe5cbdfc 100644
--- a/drivers/iio/dummy/iio_simple_dummy_events.c
+++ b/drivers/iio/dummy/iio_simple_dummy_events.c
@@ -222,6 +222,13 @@ static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
 	return IRQ_HANDLED;
 }
 
+static void iio_simple_dummy_events_release_irq(void *data)
+{
+	struct iio_dummy_state *st = data;
+
+	iio_dummy_evgen_release_irq(st->event_irq);
+}
+
 /**
  * iio_simple_dummy_events_register() - setup interrupt handling for events
  * @indio_dev: device instance data
@@ -233,44 +240,28 @@ static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
  * no way forms part of this example. Just assume that events magically
  * appear via the provided interrupt.
  */
-int iio_simple_dummy_events_register(struct iio_dev *indio_dev)
+int iio_simple_dummy_events_register(struct device *parent,
+				     struct iio_dev *indio_dev)
 {
 	struct iio_dummy_state *st = iio_priv(indio_dev);
 	int ret;
 
 	/* Fire up event source - normally not present */
 	st->event_irq = iio_dummy_evgen_get_irq();
-	if (st->event_irq < 0) {
-		ret = st->event_irq;
-		goto error_ret;
-	}
-	st->regs = iio_dummy_evgen_get_regs(st->event_irq);
-
-	ret = request_threaded_irq(st->event_irq,
-				   &iio_simple_dummy_get_timestamp,
-				   &iio_simple_dummy_event_handler,
-				   IRQF_ONESHOT,
-				   "iio_simple_event",
-				   indio_dev);
-	if (ret < 0)
-		goto error_free_evgen;
-	return 0;
+	if (st->event_irq < 0)
+		return st->event_irq;
 
-error_free_evgen:
-	iio_dummy_evgen_release_irq(st->event_irq);
-error_ret:
-	return ret;
-}
+	ret = devm_add_action_or_reset(parent,
+				       iio_simple_dummy_events_release_irq, st);
+	if (ret)
+		return ret;
 
-/**
- * iio_simple_dummy_events_unregister() - tidy up interrupt handling on remove
- * @indio_dev: device instance data
- */
-void iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
-{
-	struct iio_dummy_state *st = iio_priv(indio_dev);
+	st->regs = iio_dummy_evgen_get_regs(st->event_irq);
 
-	free_irq(st->event_irq, indio_dev);
-	/* Not part of normal driver */
-	iio_dummy_evgen_release_irq(st->event_irq);
+	return devm_request_threaded_irq(parent, st->event_irq,
+					 &iio_simple_dummy_get_timestamp,
+					 &iio_simple_dummy_event_handler,
+					 IRQF_ONESHOT,
+					 "iio_simple_event",
+					 indio_dev);
 }
-- 
2.27.0


  reply	other threads:[~2020-12-03  9:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03  9:50 [PATCH 1/3] iio: dummy: convert all simple allocation devm_ variants Alexandru Ardelean
2020-12-03  9:50 ` Alexandru Ardelean [this message]
2020-12-03  9:50 ` [PATCH 3/3] iio: dummy: use devm_iio_triggered_buffer_setup() for buffer setup Alexandru Ardelean
2020-12-05 16:36 ` [PATCH 1/3] iio: dummy: convert all simple allocation devm_ variants Jonathan Cameron
2020-12-07  7:22   ` Alexandru Ardelean
2020-12-13 14:22     ` 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=20201203095005.72252-2-alexandru.ardelean@analog.com \
    --to=alexandru.ardelean@analog.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@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).