freenode
Kernel & Low-Level

NAND flash handles would outlive the driver that owned them

A 58-patch series keeps chip metadata valid after unbind and rejects further hardware access instead of touching freed controller state.

James Hilliard has posted a fifth revision of a 58-patch series that tries to stop Linux from using raw NAND controller state after the driver that owns it has gone away. An MTD handle can outlive controller unbind. Closing a still-open writable file can call sync against that handle, and NVMEM consumers can keep using a provider that no longer has hardware behind it. Reference counting on the MTD object was not enough: holding that reference did not keep the driver-owned allocation that contains the master device.

The series splits the class device from the backing allocation, drops device interfaces, and drains NVMEM and power-management callbacks before that backing data is freed. Registered nodes and acquired handles keep the chip; nested partitions also keep their parent metadata. Unregister runs first so removal notifiers can finish I/O, then the raw NAND path disconnects and drains operations already admitted. Hardware, including DMA channels, interrupts, and chip-select windows, can then be released without waiting for open files to close. Later access is meant to fail rather than reach the unbound driver. Metadata such as the out-of-band layout is snapshotted into core-owned data before publication, so queries do not call back into a module that may already be gone.

Driver conversions stop reusing static chip-select slots that an old handle might still own, and allocate a fresh chip when removable media such as a SmartMedia card is inserted again, so a stale handle cannot see the replacement. Virtual concatenations are disconnected and drained before any physical component disappears. A parallel SPI-NOR series from Tze Yee Ng covers the same class of lifetime bugs on that path. Earlier review from Greg Kroah-Hartman pushed the split between class-device data and the MTD allocation.