From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de,
Dario Binacchi <dario.binacchi@amarulasolutions.com>,
Michael Trimarchi <michael@amarulasolutions.com>
Cc: Tom Rini <trini@konsulko.com>, Sean Anderson <seanga2@gmail.com>
Subject: [PATCH v2 11/15] nand: Add function to unregister NAND devices
Date: Sat, 4 Nov 2023 16:37:49 -0400 [thread overview]
Message-ID: <20231104203753.1579217-12-seanga2@gmail.com> (raw)
In-Reply-To: <20231104203753.1579217-1-seanga2@gmail.com>
This performs the opposite of nand_register, allowing drivers to unregister
nand devices. This is probably unnecessary for most regular drivers, but we
expect sandbox drivers to get repeatedly bound/unbound, so this will help
avoid dangling pointers.
Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
(no changes since v1)
drivers/mtd/nand/raw/nand.c | 17 +++++++++++++++++
include/nand.h | 1 +
2 files changed, 18 insertions(+)
diff --git a/drivers/mtd/nand/raw/nand.c b/drivers/mtd/nand/raw/nand.c
index 3abd82068fb..80017b3dddd 100644
--- a/drivers/mtd/nand/raw/nand.c
+++ b/drivers/mtd/nand/raw/nand.c
@@ -74,6 +74,23 @@ int nand_register(int devnum, struct mtd_info *mtd)
return 0;
}
+void nand_unregister(struct mtd_info *mtd)
+{
+ int devnum = nand_mtd_to_devnum(mtd);
+
+ if (devnum < 0)
+ return;
+
+ if (nand_curr_device == devnum)
+ nand_curr_device = -1;
+
+ total_nand_size -= mtd->size / 1024;
+
+ del_mtd_device(nand_info[devnum]);
+
+ nand_info[devnum] = NULL;
+}
+
#if !CONFIG_IS_ENABLED(SYS_NAND_SELF_INIT)
static void nand_init_chip(int i)
{
diff --git a/include/nand.h b/include/nand.h
index c1d7533aaac..fc584f5ef7a 100644
--- a/include/nand.h
+++ b/include/nand.h
@@ -22,6 +22,7 @@ int nand_mtd_to_devnum(struct mtd_info *mtd);
#if CONFIG_IS_ENABLED(SYS_NAND_SELF_INIT)
void board_nand_init(void);
int nand_register(int devnum, struct mtd_info *mtd);
+void nand_unregister(struct mtd_info *mtd);
#else
struct nand_chip;
--
2.37.1
next prev parent reply other threads:[~2023-11-04 20:42 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-04 20:37 [PATCH v2 00/15] nand: Add sandbox tests Sean Anderson
2023-11-04 20:37 ` [PATCH v2 01/15] spl: nand: Fix NULL-pointer dereference Sean Anderson
2023-11-04 20:37 ` [PATCH v2 02/15] nand: Don't dereference NULL manufacturer_desc Sean Anderson
2023-11-04 20:37 ` [PATCH v2 03/15] nand: Calculate SYS_NAND_BLOCK_PAGES (neé SYS_NAND_PAGE_COUNT) automatically Sean Anderson
2023-11-04 20:37 ` [PATCH v2 04/15] nand: spl_loaders: Only read enough pages to load the image Sean Anderson
2023-11-04 20:37 ` [PATCH v2 05/15] spl: legacy: Honor bl_len when decompressing Sean Anderson
2023-11-04 20:37 ` [PATCH v2 06/15] spl: nand: Set bl_len to page size Sean Anderson
2023-11-04 20:37 ` [PATCH v2 07/15] cmd: nand: Map memory before accessing it Sean Anderson
2023-11-04 20:37 ` [PATCH v2 08/15] spl: " Sean Anderson
2023-11-04 20:37 ` [PATCH v2 09/15] mtd: Rename SPL_MTD_SUPPORT to SPL_MTD Sean Anderson
2023-11-04 20:37 ` [PATCH v2 10/15] mtd: Add some fallbacks for add/del_mtd_device Sean Anderson
2023-11-04 20:37 ` Sean Anderson [this message]
2023-11-04 20:37 ` [PATCH v2 12/15] nand: Allow reinitialization Sean Anderson
2023-11-04 20:37 ` [PATCH v2 13/15] arch: sandbox: Add function to create temporary files Sean Anderson
2023-11-04 20:37 ` [PATCH v2 14/15] nand: Add sandbox driver Sean Anderson
2023-11-04 20:37 ` [PATCH v2 15/15] test: spl: Add a test for NAND Sean Anderson
2023-11-17 13:40 ` [PATCH v2 00/15] nand: Add sandbox tests Tom Rini
2023-11-18 17:09 ` Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231104203753.1579217-12-seanga2@gmail.com \
--to=seanga2@gmail.com \
--cc=dario.binacchi@amarulasolutions.com \
--cc=michael@amarulasolutions.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox