mtd: rawnand: initialize ntargets with maxchips [Linux 5.2]

mtd: rawnand: initialize ntargets with maxchips [Linux 5.2]

This Linux kernel change "mtd: rawnand: initialize ntargets with maxchips" is included in the Linux 5.2 release. This change is authored by Sascha Hauer <s.hauer [at]> on Tue May 21 10:43:35 2019 +0200. The commit for this change in Linux stable tree is b2b5921 (patch).

mtd: rawnand: initialize ntargets with maxchips

memorg->ntargets is initialized with '1'. It should be initialized with
the maxchips argument from nand_scan() instead. Otherwise multi chip
support errors out on the secondary chip selects when trying to call
nand_reset() on them:

WARNING: CPU: 0 PID: 1 at drivers/mtd/nand/raw/internals.h:114

With this memorg->ntargets is initialized with the maximum number of
chip selects supported by the driver. After having detected the number
of actually connected chips memory->ntargets is updated with that

Fixes: 32813e288414 ("mtd: rawnand: Get rid of chip->numchips")
Signed-off-by: Sascha Hauer <[email protected]>
Reviewed-by: Boris Brezillon <[email protected]>
Signed-off-by: Miquel Raynal <[email protected]>

There are 3 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/mtd/nand/raw/nand_base.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
index 2cf7106..3a14b79 100644
--- a/drivers/mtd/nand/raw/nand_base.c
+++ b/drivers/mtd/nand/raw/nand_base.c
@@ -4666,7 +4666,6 @@ static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type)
    memorg = nanddev_get_memorg(&chip->base);
    memorg->planes_per_lun = 1;
    memorg->luns_per_target = 1;
-   memorg->ntargets = 1;

     * Reset the chip, required by some chips (e.g. Micron MT29FxGxxxxx)
@@ -5031,6 +5030,8 @@ static int nand_scan_ident(struct nand_chip *chip, unsigned int maxchips,
    if (ret)
        return ret;

+   memorg->ntargets = maxchips;
    /* Read the flash type */
    ret = nand_detect(chip, table);
    if (ret) {

Leave a Reply

Your email address will not be published. Required fields are marked *