]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
nand: Add function to unregister NAND devices
authorSean Anderson <seanga2@gmail.com>
Sat, 4 Nov 2023 20:37:49 +0000 (16:37 -0400)
committerTom Rini <trini@konsulko.com>
Thu, 16 Nov 2023 17:43:49 +0000 (12:43 -0500)
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>
drivers/mtd/nand/raw/nand.c
include/nand.h

index 3abd82068fb1638239f0406787ce1a66dfcf85bc..80017b3dddd62f901334041a54fcd8986919c61a 100644 (file)
@@ -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)
 {
index c1d7533aaac9876b8aa80201bf5a19f9c3938827..fc584f5ef7aeb8456f58963ae748576ef29d0ff7 100644 (file)
@@ -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;