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: <20150204142959.de8ddfef8374132b27a5d0c2@linux-foundation.org>
Date:	Wed, 4 Feb 2015 14:29:59 -0800
From:	Andrew Morton <akpm@...ux-foundation.org>
To:	Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>
Cc:	linux-kernel@...r.kernel.org, jmarchan@...hat.com,
	minchan@...nel.org, ngupta@...are.org, opensource.ganesh@...il.com,
	sergey.senozhatsky@...il.com, mm-commits@...r.kernel.org
Subject: Re: + zram-rework-reset-and-destroy-path-fix.patch added to -mm
 tree

On Wed, 4 Feb 2015 10:07:20 +0900 Sergey Senozhatsky <sergey.senozhatsky.work@...il.com> wrote:

> Set dev_id to zero and fix zram_devices allocation error handling
> path, can pass uninit dev_id to destroy_devices().
> 
> cosmetic:
> change destroy_devices() message from pr_debug() to pr_info(), as
> proposed by Minchan Kim.
> 

Seems unnecessarily complicated.  What about

--- a/drivers/block/zram/zram_drv.c~zram-rework-reset-and-destroy-path-fix-2-fix
+++ a/drivers/block/zram/zram_drv.c
@@ -1141,7 +1141,8 @@ static void destroy_devices(unsigned int
 
 static int __init zram_init(void)
 {
-	int ret = -ENOMEM, dev_id = 0;
+	int ret;
+	int dev_id;
 
 	if (num_devices > max_num_devices) {
 		pr_warn("Invalid value for num_devices: %u\n",
@@ -1157,20 +1158,23 @@ static int __init zram_init(void)
 
 	/* Allocate the device array and initialize each one */
 	zram_devices = kzalloc(num_devices * sizeof(struct zram), GFP_KERNEL);
-	if (!zram_devices)
-		goto out_error;
+	if (!zram_devices) {
+		ret = -ENOMEM;
+		goto out;
+	}
 
 	for (dev_id = 0; dev_id < num_devices; dev_id++) {
 		ret = create_device(&zram_devices[dev_id], dev_id);
 		if (ret)
-			goto out_error;
+			goto out_devices;
 	}
 
 	pr_info("Created %u device(s)\n", num_devices);
 	return 0;
 
-out_error:
+out_devices:
 	destroy_devices(dev_id);
+out:
 	return ret;
 }

which yields

static int __init zram_init(void)
{
	int ret;
	int dev_id;

	if (num_devices > max_num_devices) {
		pr_warn("Invalid value for num_devices: %u\n",
				num_devices);
		return -EINVAL;
	}

	zram_major = register_blkdev(0, "zram");
	if (zram_major <= 0) {
		pr_warn("Unable to get major number\n");
		return -EBUSY;
	}

	/* Allocate the device array and initialize each one */
	zram_devices = kzalloc(num_devices * sizeof(struct zram), GFP_KERNEL);
	if (!zram_devices) {
		ret = -ENOMEM;
		goto out;
	}

	for (dev_id = 0; dev_id < num_devices; dev_id++) {
		ret = create_device(&zram_devices[dev_id], dev_id);
		if (ret)
			goto out_devices;
	}

	pr_info("Created %u device(s)\n", num_devices);
	return 0;

out_devices:
	destroy_devices(dev_id);
out:
	return ret;
}

 
_

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ