Hi Xiaolei, Xiaolei Li <xiaolei.li@xxxxxxxxxxxx> wrote on Mon, 29 Apr 2019 14:38:32 +0800: > Currently, we only check how many CE# pins are set in device tree. > But it should be necessary to check whether CE# pin setting is > duplicated or if CE# pin index exceeds the maximum CE# number that > controller supports. > > So, add validity check to avoid these invalid settings. > > Signed-off-by: Xiaolei Li <xiaolei.li@xxxxxxxxxxxx> > --- > drivers/mtd/nand/raw/mtk_nand.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/drivers/mtd/nand/raw/mtk_nand.c b/drivers/mtd/nand/raw/mtk_nand.c > index a2f7af536380..7a5e8c9cf61b 100644 > --- a/drivers/mtd/nand/raw/mtk_nand.c > +++ b/drivers/mtd/nand/raw/mtk_nand.c > @@ -162,6 +162,8 @@ struct mtk_nfc { > struct list_head chips; > > u8 *buffer; > + > + unsigned long assigned_cs; > }; > > /* > @@ -1351,6 +1353,17 @@ static int mtk_nfc_nand_chip_init(struct device *dev, struct mtk_nfc *nfc, > dev_err(dev, "reg property failure : %d\n", ret); > return ret; > } > + > + if (tmp >= MTK_NAND_MAX_NSELS) { > + dev_err(dev, "invalid CS: %u\n", tmp); > + return -EINVAL; > + } > + > + if (test_and_set_bit(tmp, &nfc->assigned_cs)) { > + dev_err(dev, "CS %u already assigned\n", tmp); > + return -EINVAL; > + } > + > chip->sels[i] = tmp; > } > Reviewed-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx> Thanks, Miquèl ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/