[PATCH 11/15] nand: Add function to unregister NAND devices

Dario Binacchi dario.binacchi at amarulasolutions.com
Thu Nov 2 11:58:54 CET 2023


Sean, All,

On Sun, Oct 29, 2023 at 4:49 AM Sean Anderson <seanga2 at gmail.com> wrote:
>
> 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 at gmail.com>
> ---
>
>  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
>

Reviewed-by: Dario Binacchi <dario.binacchi at amarulasolutions.com>

Thanks and regards,

Dario
-- 

Dario Binacchi

Senior Embedded Linux Developer

dario.binacchi at amarulasolutions.com

__________________________________


Amarula Solutions SRL

Via Le Canevare 30, 31100 Treviso, Veneto, IT

T. +39 042 243 5310
info at amarulasolutions.com

www.amarulasolutions.com


More information about the U-Boot mailing list