linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio:core: In map_array_register() cleanup in case of error
@ 2020-10-11 12:41 Lino Sanfilippo
  2020-10-11 15:07 ` Jonathan Cameron
  0 siblings, 1 reply; 10+ messages in thread
From: Lino Sanfilippo @ 2020-10-11 12:41 UTC (permalink / raw)
  To: jic23; +Cc: knaack.h, lars, pmeerw, linux-iio, linux-kernel, Lino Sanfilippo

In function map_array_register() properly rewind in case of error.
Furthermore save an extra label by using a break instead of goto to leave
the concerning loop.

Signed-off-by: Lino Sanfilippo <LinoSanfilippo@gmx.de>
---
 drivers/iio/inkern.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index 5a8351c..0735cc4 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -28,6 +28,7 @@ int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps)
 {
 	int i = 0, ret = 0;
 	struct iio_map_internal *mapi;
+	struct list_head *pos, *tmp;

 	if (maps == NULL)
 		return 0;
@@ -37,14 +38,22 @@ int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps)
 		mapi = kzalloc(sizeof(*mapi), GFP_KERNEL);
 		if (mapi == NULL) {
 			ret = -ENOMEM;
-			goto error_ret;
+			break;
 		}
 		mapi->map = &maps[i];
 		mapi->indio_dev = indio_dev;
 		list_add_tail(&mapi->l, &iio_map_list);
 		i++;
 	}
-error_ret:
+
+	if (ret) { /* undo */
+		while (i--) {
+			mapi = list_last_entry(&iio_map_list,
+					       struct iio_map_internal, l);
+			list_del(&mapi->l);
+			kfree(mapi);
+		}
+	}
 	mutex_unlock(&iio_map_list_lock);

 	return ret;
--
2.7.4


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

end of thread, other threads:[~2020-10-18 18:22 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-11 12:41 [PATCH] iio:core: In map_array_register() cleanup in case of error Lino Sanfilippo
2020-10-11 15:07 ` Jonathan Cameron
2020-10-11 18:05   ` Lino Sanfilippo
2020-10-11 18:22   ` [PATCH v2] " Lino Sanfilippo
2020-10-16 15:09     ` Andy Shevchenko
2020-10-18  1:11       ` Lino Sanfilippo
2020-10-18  1:11         ` [PATCH 1/2] iio:core: Introduce unlocked version of iio_map_array_unregister() Lino Sanfilippo
2020-10-18 18:21           ` Andy Shevchenko
2020-10-18  1:11         ` [PATCH 2/2] iio:core: In iio_map_array_register() cleanup in case of error Lino Sanfilippo
2020-10-18  9:56       ` [PATCH v2] iio:core: In map_array_register() " Jonathan Cameron

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