[PATCH 2/3] iio: dummy: convert events to device-managed handlers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux