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]
Date:   Thu, 8 Dec 2016 12:33:02 +0100
From:   SF Markus Elfring <elfring@...rs.sourceforge.net>
To:     devel@...verdev.osuosl.org, Chris Cesare <chris.cesare@...il.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        H Hartley Sweeten <hsweeten@...ionengravers.com>,
        Ian Abbott <abbotti@....co.uk>
Cc:     LKML <linux-kernel@...r.kernel.org>,
        kernel-janitors@...r.kernel.org
Subject: [PATCH 1/5] staging: comedi: serial2002: Combine four kcalloc() calls
 into one in serial2002_setup_subdevs()

From: Markus Elfring <elfring@...rs.sourceforge.net>
Date: Thu, 8 Dec 2016 07:37:29 +0100

The function "kcalloc" was called in three cases by the function
"serial2002_setup_subdevs" without checking immediately if it failed.
This issue was detected by using the Coccinelle software.

* Perform the desired memory allocation (and release at the end) by a single
  function call instead.

* Adjust a jump target so that a redundant check is avoided.

Fixes: 623a73926c7012e3bb132e225621890207f5c611 ("staging: comedi: serial2002: split up serial_2002_open()")

Signed-off-by: Markus Elfring <elfring@...rs.sourceforge.net>
---
 drivers/staging/comedi/drivers/serial2002.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/comedi/drivers/serial2002.c b/drivers/staging/comedi/drivers/serial2002.c
index 0d33e520f635..9542f4f8afe0 100644
--- a/drivers/staging/comedi/drivers/serial2002.c
+++ b/drivers/staging/comedi/drivers/serial2002.c
@@ -392,6 +392,7 @@ static int serial2002_setup_subdevice(struct comedi_subdevice *s,
 static int serial2002_setup_subdevs(struct comedi_device *dev)
 {
 	struct serial2002_private *devpriv = dev->private;
+	struct config_t *array;
 	struct config_t *di_cfg;
 	struct config_t *do_cfg;
 	struct config_t *ai_cfg;
@@ -402,15 +403,17 @@ static int serial2002_setup_subdevs(struct comedi_device *dev)
 	int i;
 
 	/* Allocate the temporary structs to hold the configuration data */
-	di_cfg = kcalloc(32, sizeof(*cfg), GFP_KERNEL);
-	do_cfg = kcalloc(32, sizeof(*cfg), GFP_KERNEL);
-	ai_cfg = kcalloc(32, sizeof(*cfg), GFP_KERNEL);
-	ao_cfg = kcalloc(32, sizeof(*cfg), GFP_KERNEL);
-	if (!di_cfg || !do_cfg || !ai_cfg || !ao_cfg) {
+	array = kcalloc(4 * 32, sizeof(*cfg), GFP_KERNEL);
+	if (!array) {
 		result = -ENOMEM;
-		goto err_alloc_configs;
+		goto check_tty;
 	}
 
+	di_cfg = array;
+	do_cfg = array + 1 * 32;
+	ai_cfg = array + 2 * 32;
+	ao_cfg = array + 3 * 32;
+
 	/* Read the configuration from the connected device */
 	serial2002_tty_setspeed(devpriv->tty, devpriv->speed);
 	serial2002_poll_channel(devpriv->tty, 31);
@@ -534,13 +537,10 @@ static int serial2002_setup_subdevs(struct comedi_device *dev)
 		}
 	}
 
-err_alloc_configs:
-	kfree(di_cfg);
-	kfree(do_cfg);
-	kfree(ai_cfg);
-	kfree(ao_cfg);
+	kfree(array);
 
 	if (result) {
+check_tty:
 		if (devpriv->tty) {
 			filp_close(devpriv->tty, NULL);
 			devpriv->tty = NULL;
-- 
2.11.0

Powered by blists - more mailing lists