Skip to contentSkip to conversation

fix regressions in DoC G4 driver

PATCH In review Sergey Larin 4 participants 8 messages Jul 8, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover fix regressions in DoC G4 driver

docg4 driver became broken and these patches will make it work again.

Sergey Larin (2):
mtd: rawnand: docg4: fix NULL deref while probing
mtd: rawnand: docg4: specify bits_per_cell

 drivers/mtd/nand/raw/docg4.c | 2 ++
 1 file changed, 2 insertions(+)
Signature · 1 line
2.18.0
#1 lore raw

PATCH 1/2 mtd: rawnand: docg4: fix NULL deref while probing

nand_scan_tail() invokes nand_chip->scan_bbt() at the end, which is not set by the driver. Use the default nand_default_bbt() function to avoid NULL dereferncing.

---
 drivers/mtd/nand/raw/docg4.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/raw/docg4.c +1 -0
index bb96cb33cd6b..bbed8ea7858c 100644
@@ -1269,6 +1269,7 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
 	nand->read_buf = docg4_read_buf;
 	nand->write_buf = docg4_write_buf16;
 	nand->erase = docg4_erase_block;
+	nand->scan_bbt = nand_default_bbt;
 	nand->set_features = nand_get_set_features_notsupp;
 	nand->get_features = nand_get_set_features_notsupp;
 	nand->ecc.read_page = docg4_read_page;
Signature · 1 line
2.18.0
maintainer
#2 lore raw

Re: [PATCH 1/2] mtd: rawnand: docg4: fix NULL deref while probing

Hi Sergey,

Sergey Larin <[email protected]> wrote on Sun, 8 Jul 2018 14:29:23 +0300:

Quoted 3 lines

nand_scan_tail() invokes nand_chip->scan_bbt() at the end, which is not set by the driver. Use the default nand_default_bbt() function to avoid NULL dereferncing.

dereferencing

Quoted 2 lines

Maybe a Fixes/stable tags would be appropriate here if this is a real runtime error?

Quoted 16 lines
---
 drivers/mtd/nand/raw/docg4.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/raw/docg4.c +1 -0
index bb96cb33cd6b..bbed8ea7858c 100644
@@ -1269,6 +1269,7 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
 	nand->read_buf = docg4_read_buf;
 	nand->write_buf = docg4_write_buf16;
 	nand->erase = docg4_erase_block;
+	nand->scan_bbt = nand_default_bbt;
 	nand->set_features = nand_get_set_features_notsupp;
 	nand->get_features = nand_get_set_features_notsupp;
 	nand->ecc.read_page = docg4_read_page;
Signature · 3 lines
Miquel Raynal, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
#3 lore raw

Re: [PATCH 1/2] mtd: rawnand: docg4: fix NULL deref while probing

In reply to Sergey Larin
Quoted 3 lines · On Sun, 8 Jul 2018 14:29:23 +0300 Sergey Larin <[email protected]>…

nand_scan_tail() invokes nand_chip->scan_bbt() at the end, which is not set by the driver. Use the default nand_default_bbt() function to avoid NULL dereferncing.

Wow! For how long has this driver been broken? The ->scan_bbt() hook has been there for a very long time, and nand_scan_tail() is calling it when NAND_SKIP_BBTSCAN is not set.

Quoted 2 lines

Missing Fixes and Cc stable tags.

drivers/mtd/nand/raw/docg4.c static void __init init_mtd_structs(struct mtd_info *mtd) · line 1272

Quoted 13 lines
---
 drivers/mtd/nand/raw/docg4.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/raw/docg4.c +1 -0
index bb96cb33cd6b..bbed8ea7858c 100644
@@ -1269,6 +1269,7 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
 	nand->read_buf = docg4_read_buf;
 	nand->write_buf = docg4_write_buf16;
 	nand->erase = docg4_erase_block;
+	nand->scan_bbt = nand_default_bbt;

Are you sure that's really what you want. My experience with docg4 code is that it's not really fitting in the raw NAND framework, so I wouldn't be surprised if the default bad block table scan function does not match how the docg4 NAND works.

Quoted 3 lines
drivers/mtd/nand/raw/docg4.c +0 -0
 	nand->set_features = nand_get_set_features_notsupp;
 	nand->get_features = nand_get_set_features_notsupp;
 	nand->ecc.read_page = docg4_read_page;
#4 lore raw

Re: [PATCH 1/2] mtd: rawnand: docg4: fix NULL deref while probing

In reply to Sergey Larin
Thank you for the patch! Yet something to improve:

Hi Sergey,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mtd/nand/next]
[also build test ERROR on v4.18-rc3 next-20180706]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Sergey-Larin/fix-regressions-in-DoC-G4-driver/20180708-193220
base:   git://git.infradead.org/linux-mtd.git nand/next
config: i386-randconfig-s0-201827 (attached as .config)
compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

>> ERROR: "nand_default_bbt" [drivers/mtd/nand/raw/docg4.ko] undefined!

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#5 lore raw

PATCH 2/2 mtd: rawnand: docg4: specify bits_per_cell

In reply to Sergey Larin

This fixes WARN() in nand_is_slc().

DoC G4 is 2-bit MLC, so set bits_per_cell value according to this.

---
 drivers/mtd/nand/raw/docg4.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/raw/docg4.c +1 -0
index bbed8ea7858c..82d97a16e246 100644
@@ -1250,6 +1250,7 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
 	nand->pagemask = 0x3ffff;
 	nand->badblockpos = NAND_LARGE_BADBLOCK_POS;
 	nand->badblockbits = 8;
+	nand->bits_per_cell = 2;
 	nand->ecc.mode = NAND_ECC_HW_SYNDROME;
 	nand->ecc.size = DOCG4_PAGE_SIZE;
 	nand->ecc.prepad = 8;
Signature · 1 line
2.18.0
#6 lore raw

Re: [PATCH 2/2] mtd: rawnand: docg4: specify bits_per_cell

Quoted 3 lines · On Sun, 8 Jul 2018 14:29:24 +0300 Sergey Larin <[email protected]>…

This fixes WARN() in nand_is_slc().

DoC G4 is 2-bit MLC, so set bits_per_cell value according to this.

What you do here implies "no UBI on docg4". To be honest, I'm pretty sure there's an FTL in there, which clearly does not make it a good candidate for the raw NAND framework. Not to mention that it's not even using the same instruction set which forced developers of this driver to guess what the core was trying to do in the ->cmdfunc() implementation and convert it to docg4 operations. This approach is going against the recent evolution of the raw NAND framework (deprecating ->cmdfunc() in favor of ->exec_op()).

I'd really like to see this driver moved outside of drivers/mtd/nand/raw/. If it really has NAND constraints, you could re-use the interface agnostic NAND framework (include/linux/nand.h) and add a new driver under drivers/mtd/nand/diskonchip/docg4.c.

That's the very reason I asked if you if you had access to this HW. I can help you with the development part, but I can't test.

Quoted 18 lines
---
 drivers/mtd/nand/raw/docg4.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/nand/raw/docg4.c +1 -0
index bbed8ea7858c..82d97a16e246 100644
@@ -1250,6 +1250,7 @@ static void __init init_mtd_structs(struct mtd_info *mtd)
 	nand->pagemask = 0x3ffff;
 	nand->badblockpos = NAND_LARGE_BADBLOCK_POS;
 	nand->badblockbits = 8;
+	nand->bits_per_cell = 2;
 	nand->ecc.mode = NAND_ECC_HW_SYNDROME;
 	nand->ecc.size = DOCG4_PAGE_SIZE;
 	nand->ecc.prepad = 8;
#7 lore raw
In reply to Sergey Larin

Hi Sergey,

Quoted 1 line · On Sun, 8 Jul 2018 14:29:22 +0300 Sergey Larin <[email protected]>…

docg4 driver became broken and these patches will make it work again.

I guess you have a platform with a DoC G4 on it. If that's the case, I might have a few changes I'd need you to test if you don't mind.

Thanks,

Boris

Quoted 8 lines

Sergey Larin (2):
mtd: rawnand: docg4: fix NULL deref while probing
mtd: rawnand: docg4: specify bits_per_cell

 drivers/mtd/nand/raw/docg4.c | 2 ++
 1 file changed, 2 insertions(+)