Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: nand: Error out if cmd_ctrl() is missing

If no user specified chip->select_chip() function is provided, code in
nand_base.c will automatically set this hook to nand_select_chip(),
which in turn depends on chip->cmd_ctrl() hook being valid. Not
providing both of those functions in NAND controller driver (for example
by mistake) will result in a bit cryptic segfault. Same is true for
chip->cmdfunc().

To avoid the above scenario add a check in nand_scan_dent and error out
if cmd_ctrl() is not provided.

Suggested-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Suggested-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>

authored by

Andrey Smirnov and committed by
Boris Brezillon
76fe334f 75c19e58

+9
+9
drivers/mtd/nand/nand_base.c
··· 4140 4140 if (!mtd->name && mtd->dev.parent) 4141 4141 mtd->name = dev_name(mtd->dev.parent); 4142 4142 4143 + if ((!chip->cmdfunc || !chip->select_chip) && !chip->cmd_ctrl) { 4144 + /* 4145 + * Default functions assigned for chip_select() and 4146 + * cmdfunc() both expect cmd_ctrl() to be populated, 4147 + * so we need to check that that's the case 4148 + */ 4149 + pr_err("chip.cmd_ctrl() callback is not provided"); 4150 + return -EINVAL; 4151 + } 4143 4152 /* Set the default functions */ 4144 4153 nand_set_defaults(chip, chip->options & NAND_BUSWIDTH_16); 4145 4154