# Does the Linux MTD Driver Practice Erase Avoidance?

## John R. Graham

I'm probably going to end up having to research this for myself, but here's a quick, lazy question.

If a partial-sector write to an MTD device would only turn one bits into zero bits in the underlying physical flash device, is the driver smart enough to just write the new data as opposed to performing a full sector read/modify/erase/write?

I can provide background information if necessary but, if you need it, you probably can't answer the question.  :Wink: 

- John

----------

## Ant P.

Skimmed through the code... the closest thing I could find was inftl_writeblock() in linux/drivers/mtd/inftlcore.c which is just a vanilla discard optimization.

I get what you're describing here, but I think it just isn't done for performance reasons; bitmask checks on every 64/128KB write isn't cheap, and short-circuiting them isn't an option because of the potential for timing attacks (no matter how contrived they seem).

It might be possibly happening down in the MTD firmware, but nobody's going to be able to say for sure.

----------

## John R. Graham

Thanks. I did a cursory review of the source code as well and didn't see any logic that could be doing that either. The flash I'm using, parallel (and, in some cases, SPI) NOR, has no firmware, per se.

- John

----------

