[PATCH v6 11/15] nand: spi: add basic operations support

Peter Pan peterpansjtu at gmail.com
Wed Oct 11 18:28:10 PDT 2017


Hi Boris,

On Wed, Oct 11, 2017 at 9:35 PM, Boris Brezillon
<boris.brezillon at free-electrons.com> wrote:
> Hi Peter,
>
> I'm resurrecting this series, and I still have on question on this
> patch (probably not my last question ;-)).

Please feel free to comment on it. :)

>
> On Wed, 24 May 2017 15:07:07 +0800
> Peter Pan <peterpandong at micron.com> wrote:
>
>
>
>> +/**
>> + * spinand_do_write_ops - write data from buffer to device
>> + * @mtd: MTD device structure
>> + * @to: offset to write to
>> + * @ops: oob operations description structure
>> + */
>> +static int spinand_do_write_ops(struct mtd_info *mtd, loff_t to,
>> +                             struct mtd_oob_ops *ops)
>> +{
>> +     struct spinand_device *spinand = mtd_to_spinand(mtd);
>> +     struct nand_device *nand = mtd_to_nand(mtd);
>> +     int ret = 0;
>> +
>> +     ret = nand_check_address(nand, to);
>> +     if (ret) {
>> +             dev_err(spinand->dev, "%s: invalid write address\n", __func__);
>> +             return ret;
>> +     }
>> +
>> +     ret = nand_check_oob_ops(nand, to, ops);
>> +     if (ret) {
>> +             dev_err(spinand->dev,
>> +                     "%s: invalid oob operation input\n", __func__);
>> +             return ret;
>> +     }
>> +
>> +     if (nand_oob_ops_across_page(mtd_to_nand(mtd), ops)) {
>> +             dev_err(spinand->dev,
>> +                     "%s: try to across page when writing with OOB\n",
>> +                     __func__);
>> +             return -EINVAL;
>> +     }
>
> Why do you prevent writing more than one OOB region?

Well, actually this is not my original intention. If we remove the across page
check, the mtd_oobtest.ko will failed in "write past end of device" test. And
I checked nand_base.c, I found that nand_do_write_oob() had this check.

An interesting thing is in part_read_oob() we have check for "read pass the
end of partition" while in part_write_oob() we don't have. I don't
know the history
so I just followed raw NAND code.

Thanks

Peter Pan

>
>> +
>> +     mutex_lock(&spinand->lock);
>> +     ret = spinand_write_pages(mtd, to, ops);
>> +     mutex_unlock(&spinand->lock);
>> +
>> +     return ret;
>> +}



More information about the linux-mtd mailing list