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]
Message-Id: <20170418142454.23921-1-andrew.smirnov@gmail.com>
Date:   Tue, 18 Apr 2017 07:24:53 -0700
From:   Andrey Smirnov <andrew.smirnov@...il.com>
To:     linux-kernel@...r.kernel.org
Cc:     Nikita Yushchenko <nikita.yoush@...entembedded.com>,
        cphealy@...il.com,
        Srinivas Kandagatla <srinivas.kandagatla@...aro.org>,
        Maxime Ripard <maxime.ripard@...e-electrons.com>,
        Andrey Smirnov <andrew.smirnov@...il.com>
Subject: [PATCH 1/2] nvmem: core: Improve error path code of nvmem_register()

From: Nikita Yushchenko <nikita.yoush@...entembedded.com>

Improve error path code of nvmem_register() in the following ways:

    - Call device_del when call to nvmem_setup_compat() fails, since
      at that point device_add has suceeded and we need to undo that.

    - Documentation for device_add discorages explicitly freeing
      memory occupied by the device even in case of device_add
      failure, so to fix that use put_device() instead.

Cc: cphealy@...il.com
Cc: Srinivas Kandagatla <srinivas.kandagatla@...aro.org>
Cc: Maxime Ripard <maxime.ripard@...e-electrons.com>
Signed-off-by: Nikita Yushchenko <nikita.yoush@...entembedded.com>
Signed-off-by: Andrey Smirnov <andrew.smirnov@...il.com>
---
 drivers/nvmem/core.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 408b521..095e3fc 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -488,21 +488,23 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 
 	rval = device_add(&nvmem->dev);
 	if (rval)
-		goto out;
+		goto err_add;
 
 	if (config->compat) {
 		rval = nvmem_setup_compat(nvmem, config);
 		if (rval)
-			goto out;
+			goto err_compat;
 	}
 
 	if (config->cells)
 		nvmem_add_cells(nvmem, config);
 
 	return nvmem;
-out:
-	ida_simple_remove(&nvmem_ida, nvmem->id);
-	kfree(nvmem);
+
+err_compat:
+	device_del(&nvmem->dev);
+err_add:
+	put_device(&nvmem->dev);
 	return ERR_PTR(rval);
 }
 EXPORT_SYMBOL_GPL(nvmem_register);
-- 
2.9.3

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ