Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1625355 > unrolled thread

[PATCH 1/2] nvmem: core: Improve error path code of nvmem_register()

Started byAndrey Smirnov <andrew.smirnov@gmail.com>
First post2017-04-18 16:30 +0200
Last post2017-04-18 16:30 +0200
Articles 2 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/2] nvmem: core: Improve error path code of nvmem_register() Andrey Smirnov <andrew.smirnov@gmail.com> - 2017-04-18 16:30 +0200
    [PATCH 2/2] nvmem: core: Call put_device() in nvmem_unregister() Andrey Smirnov <andrew.smirnov@gmail.com> - 2017-04-18 16:30 +0200

#1625355 — [PATCH 1/2] nvmem: core: Improve error path code of nvmem_register()

FromAndrey Smirnov <andrew.smirnov@gmail.com>
Date2017-04-18 16:30 +0200
Subject[PATCH 1/2] nvmem: core: Improve error path code of nvmem_register()
Message-ID<txCiJ-7dQ-1@gated-at.bofh.it>
From: Nikita Yushchenko <nikita.yoush@cogentembedded.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@gmail.com
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.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

[toc] | [next] | [standalone]


#1625360 — [PATCH 2/2] nvmem: core: Call put_device() in nvmem_unregister()

FromAndrey Smirnov <andrew.smirnov@gmail.com>
Date2017-04-18 16:30 +0200
Subject[PATCH 2/2] nvmem: core: Call put_device() in nvmem_unregister()
Message-ID<txCiK-7dQ-21@gated-at.bofh.it>
In reply to#1625355
Call put_device() in nvmem_unregister() to make sure nvmem_release
gets called freeing up allocated resources.

Cc: cphealy@gmail.com
Cc: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/nvmem/core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 095e3fc..4bec82e 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -530,6 +530,7 @@ int nvmem_unregister(struct nvmem_device *nvmem)
 
 	nvmem_device_remove_all_cells(nvmem);
 	device_del(&nvmem->dev);
+	put_device(&nvmem->dev);
 
 	return 0;
 }
-- 
2.9.3

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web