lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1602440546-2376-1-git-send-email-LinoSanfilippo@gmx.de>
Date:   Sun, 11 Oct 2020 20:22:26 +0200
From:   Lino Sanfilippo <LinoSanfilippo@....de>
To:     jic23@...nel.org
Cc:     knaack.h@....de, lars@...afoo.de, pmeerw@...erw.net,
        linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org,
        Lino Sanfilippo <LinoSanfilippo@....de>
Subject: [PATCH v2] iio:core: In map_array_register() cleanup in case of error

In function map_array_register() properly rewind in case of error.
Furthermore remove the now superfluous initialization of "ret" with 0.

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

diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
index 5a8351c..9dedc30 100644
--- a/drivers/iio/inkern.c
+++ b/drivers/iio/inkern.c
@@ -26,7 +26,7 @@ static DEFINE_MUTEX(iio_map_list_lock);

 int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps)
 {
-	int i = 0, ret = 0;
+	int i = 0, ret;
 	struct iio_map_internal *mapi;

 	if (maps == NULL)
@@ -44,7 +44,18 @@ int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps)
 		list_add_tail(&mapi->l, &iio_map_list);
 		i++;
 	}
+	mutex_unlock(&iio_map_list_lock);
+
+	return 0;
+
 error_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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ