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-next>] [day] [month] [year] [list]
Date: Wed, 27 Dec 2023 12:50:50 +0100
From: Markus Elfring <Markus.Elfring@....de>
To: linux-mmc@...r.kernel.org, kernel-janitors@...r.kernel.org,
 Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
 Dmitry Torokhov <dmitry.torokhov@...il.com>,
 Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
 Paolo Abeni <pabeni@...hat.com>, Ulf Hansson <ulf.hansson@...aro.org>,
 Yang Yingliang <yangyingliang@...wei.com>
Cc: LKML <linux-kernel@...r.kernel.org>, cocci@...ia.fr
Subject: [PATCH] mmc: mmc_spi: Adjust error handling in mmc_spi_probe()

From: Markus Elfring <elfring@...rs.sourceforge.net>
Date: Wed, 27 Dec 2023 12:23:20 +0100

The kfree() function was called in one case by
the mmc_spi_probe() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.

* Thus return directly after a call of the function “kmalloc” failed
  at the beginning.

* Move an error code assignment into an if branch.

Signed-off-by: Markus Elfring <elfring@...rs.sourceforge.net>
---
 drivers/mmc/host/mmc_spi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index b0cccef4cfbf..6e7d8e1e6f38 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -1349,15 +1349,17 @@ static int mmc_spi_probe(struct spi_device *spi)
 	 * NOTE if many systems use more than one MMC-over-SPI connector
 	 * it'd save some memory to share this.  That's evidently rare.
 	 */
-	status = -ENOMEM;
 	ones = kmalloc(MMC_SPI_BLOCKSIZE, GFP_KERNEL);
 	if (!ones)
-		goto nomem;
+		return -ENOMEM;
+
 	memset(ones, 0xff, MMC_SPI_BLOCKSIZE);

 	mmc = mmc_alloc_host(sizeof(*host), &spi->dev);
-	if (!mmc)
+	if (!mmc) {
+		status = -ENOMEM;
 		goto nomem;
+	}

 	mmc->ops = &mmc_spi_ops;
 	mmc->max_blk_size = MMC_SPI_BLOCKSIZE;
--
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ