mtd locking

Matthias Auchmann m.auchmann at artech.at
Sun May 29 06:38:28 PDT 2016


Hi all!

I have a question - sorry if it turns out to be a beginner's question. I'm using kernel version 3.17, but as far as I can tell my question still applies.

My question is how locking is ensured with MTD. I understand that usually there would only be one file system attached to one mtd partition, but what if I concurrently ran multiple instances of nanddump from userspace? Is MTD thread-safe?

I'm asking since I had an issue where when I called nanddump on two partitions of the same NAND flash simultaneously, the ECC errors would count up for both nanddumps although only one partition had ECC errors. Experimentally adding a mutex to mtdpart.c's part_read() function solved the issue.

I then noticed that quite frequently in the MTD code, ecc_stats are saved, then some reads are performed, and then ecc_stats are compared. No mutex or spinlock or whatever protection is used. Given that the ECC errors can result in -EUCLEAN or a positive bitflip count (then resulting in scrubbing for UBI for example)... I started to feel a little uncomfortable about the whole MTD locking issue.

This is where the question comes from... could anyone shed light on this?

Thanks!




More information about the linux-mtd mailing list