ar71xx: fix invalid pointer dereference in rb95x_nand_scan_fixup()
authorGabor Juhos <juhosg@freemail.hu>
Tue, 12 Dec 2017 20:49:50 +0000 (21:49 +0100)
committerJohn Crispin <john@phrozen.org>
Fri, 15 Dec 2017 23:00:25 +0000 (00:00 +0100)
Since Linux 4.6, mtd->priv no longer points to the NAND specific
structure. Under 4.9 it contains NULL, thus using it to access
chip->options causes an invalid pointer dereference (FS#1200).

Update the code to use the mtd_to_nand() helper under 4.9 to obtain
the address of the chip specific data.

Fixes: 7bbf4117c6fe ("ar71xx: Add kernel 4.9 support")
Signed-off-by: Gabor Juhos <juhosg@freemail.hu>
target/linux/ar71xx/files/arch/mips/ath79/mach-rb95x.c

index 9eaeaa7f9db595094ec9964dd05d36932e1238c1..5e24694d5cc52fa5b92e55b89236d8fcb212fa6c 100644 (file)
@@ -207,7 +207,11 @@ static const struct mtd_ooblayout_ops rb95x_nand_ecclayout_ops = {
 
 static int rb95x_nand_scan_fixup(struct mtd_info *mtd)
 {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0)
        struct nand_chip *chip = mtd->priv;
+#else
+       struct nand_chip *chip = mtd_to_nand(mtd);
+#endif /* < 4.6.0 */
 
        if (mtd->writesize == 512) {
                /*