mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/5] nvmem: fix nvmem_register error path
@ 2024-06-13 13:15 Marco Felsch
  2024-06-13 13:15 ` [PATCH v2 2/5] nvmem: sync with linux code base Marco Felsch
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Marco Felsch @ 2024-06-13 13:15 UTC (permalink / raw)
  To: barebox

Currently the nvmem memory is freed without removing/unregister the
nvmem->dev if nvmem_register_cdev() fails. Fix this by unregister the
device first, free the memory and return the error code.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
v2:
- new patch

 drivers/nvmem/core.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index bf393fc180ab..fe93a2ca5f48 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -234,15 +234,19 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 
 	if (!config->cdev) {
 		rval = nvmem_register_cdev(nvmem, config->name);
-		if (rval) {
-			kfree(nvmem);
-			return ERR_PTR(rval);
-		}
+		if (rval)
+			goto err_unregister;
 	}
 
 	list_add_tail(&nvmem->node, &nvmem_devs);
 
 	return nvmem;
+
+err_unregister:
+	unregister_device(&nvmem->dev);
+	kfree(nvmem);
+
+	return ERR_PTR(rval);
 }
 EXPORT_SYMBOL_GPL(nvmem_register);
 
-- 
2.39.2




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-06-14 10:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-13 13:15 [PATCH v2 1/5] nvmem: fix nvmem_register error path Marco Felsch
2024-06-13 13:15 ` [PATCH v2 2/5] nvmem: sync with linux code base Marco Felsch
2024-06-13 13:15 ` [PATCH v2 3/5] nvmem: expose nvmem cells as cdev Marco Felsch
2024-06-14  7:46   ` Sascha Hauer
2024-06-14 10:31     ` Marco Felsch
2024-06-13 13:15 ` [PATCH v2 4/5] nvmem: allow single and dynamic device ids Marco Felsch
2024-06-13 13:15 ` [PATCH v2 5/5] eeprom: at24: fix device name handling Marco Felsch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox