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

mtd: mtdconcat: Check _read, _write callbacks existence before assignment

Since 2431c4f5b46c3 ("mtd: Implement mtd_{read,write}() as wrappers
around mtd_{read,write}_oob()") don't allow _write|_read and
_write_oob|_read_oob existing at the same time, we should check the
existence of callbacks "_read and _write" from subdev's master device
(We can trust master device since it has been registered) before
assigning, otherwise following warning occurs while making
concatenated device:

WARNING: CPU: 2 PID: 6728 at drivers/mtd/mtdcore.c:595
add_mtd_device+0x7f/0x7b0

Fixes: 2431c4f5b46c3 ("mtd: Implement mtd_{read,write}() around ...")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20210817114857.2784825-3-chengzhihao1@huawei.com

authored by

Zhihao Cheng and committed by
Miquel Raynal
a89d69a4 f9e109a2

+4 -2
+4 -2
drivers/mtd/mtdconcat.c
··· 694 694 concat->mtd._block_markbad = concat_block_markbad; 695 695 if (subdev_master->_panic_write) 696 696 concat->mtd._panic_write = concat_panic_write; 697 + if (subdev_master->_read) 698 + concat->mtd._read = concat_read; 699 + if (subdev_master->_write) 700 + concat->mtd._write = concat_write; 697 701 698 702 concat->mtd.ecc_stats.badblocks = subdev[0]->ecc_stats.badblocks; 699 703 ··· 759 755 concat->mtd.name = name; 760 756 761 757 concat->mtd._erase = concat_erase; 762 - concat->mtd._read = concat_read; 763 - concat->mtd._write = concat_write; 764 758 concat->mtd._sync = concat_sync; 765 759 concat->mtd._lock = concat_lock; 766 760 concat->mtd._unlock = concat_unlock;