linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] staging: iio_simple_dummy: fix init
@ 2015-05-26 22:19 Vladimirs Ambrosovs
  2015-05-26 22:19 ` [PATCH 2/2] staging: iio_simple_dummy: zero check param Vladimirs Ambrosovs
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Vladimirs Ambrosovs @ 2015-05-26 22:19 UTC (permalink / raw)
  To: jic23, knaack.h, lars, pmeerw, gregkh, driverdev-devel, linux-iio
  Cc: Vladimirs Ambrosovs

This patch fixes the init function for the iio_simple_dummy driver.
The main issues were absence of kfree for the allocated array, and no
devices being removed in case the probe function fails, running in a loop.

The iio_dummy_remove function was also changed:
	* The return value was changed to void
	* The check for return value of iio_simple_dummy_events_unregister()
The reason for this changes is that, as per implementation,
events_unregister function always returns 0, so we are safe not to check
return value. As a result the return value for iio_dummy_remove function
becomes useless as well, hence return value type change.

Signed-off-by: Vladimirs Ambrosovs <rodriguez.twister@gmail.com>
---
 drivers/staging/iio/iio_simple_dummy.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/iio/iio_simple_dummy.c b/drivers/staging/iio/iio_simple_dummy.c
index b47bf9f..88fbb4f 100644
--- a/drivers/staging/iio/iio_simple_dummy.c
+++ b/drivers/staging/iio/iio_simple_dummy.c
@@ -665,9 +665,8 @@ error_ret:
  *
  * Parameters follow those of iio_dummy_probe for buses.
  */
-static int iio_dummy_remove(int index)
+static void iio_dummy_remove(int index)
 {
-	int ret;
 	/*
 	 * Get a pointer to the device instance iio_dev structure
 	 * from the bus subsystem. E.g.
@@ -685,15 +684,14 @@ static int iio_dummy_remove(int index)
 	/* Buffered capture related cleanup */
 	iio_simple_dummy_unconfigure_buffer(indio_dev);
 
-	ret = iio_simple_dummy_events_unregister(indio_dev);
-	if (ret)
-		goto error_ret;
+	/*
+	 * Tidy up interrupt handling
+	 * Always returns 0, so not checking for return value
+	 */
+	iio_simple_dummy_events_unregister(indio_dev);
 
 	/* Free all structures */
 	iio_device_free(indio_dev);
-
-error_ret:
-	return ret;
 }
 
 /**
@@ -722,9 +720,17 @@ static __init int iio_dummy_init(void)
 	for (i = 0; i < instances; i++) {
 		ret = iio_dummy_probe(i);
 		if (ret < 0)
-			return ret;
+			goto error_probe;
 	}
 	return 0;
+
+error_probe:
+	/* Free devices registered before error */
+	while (i--)
+		iio_dummy_remove(i);
+
+	kfree(iio_dummy_devs);
+	return ret;
 }
 module_init(iio_dummy_init);
 
-- 
2.4.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-05-29 19:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-26 22:19 [PATCH 1/2] staging: iio_simple_dummy: fix init Vladimirs Ambrosovs
2015-05-26 22:19 ` [PATCH 2/2] staging: iio_simple_dummy: zero check param Vladimirs Ambrosovs
2015-05-27  8:25   ` Dan Carpenter
2015-05-27 22:12     ` Vladimirs Ambrosovs
2015-05-28  6:59       ` Dan Carpenter
2015-05-29 19:38         ` Vladimirs Ambrosovs
2015-05-27  6:21 ` [PATCH 1/2] staging: iio_simple_dummy: fix init Daniel Baluta
2015-05-27 17:24   ` Vladimirs Ambrosovs
2015-05-27 17:29     ` Dan Carpenter
2015-05-28  5:31       ` Daniel Baluta
2015-05-27  8:23 ` Dan Carpenter

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).