[PATCH] mtd: use refcount to prevent corruption

Richard Weinberger richard at nod.at
Wed Jan 27 16:17:50 EST 2021


----- Ursprüngliche Mail -----
>> > When underlying device is removed mtd core will crash in case user
>> > space is still holding an open handle to a mtd device node.
>> > A proper refcounting is needed so device is release only when a
>> > partition has no active users. The current simple counter is not
>> > sufficient.
>> 
>> Can you please explain a little more what devices are involved?
>> Does it implement _get_device() and _put_device()?
> No this is not connected to those handlers of the underlying device and those
> won't help.
> I have a spi device provided by MFD framework so it can go away anytime.

Can it go away physically or just in software?

Usually the pattern is that you make sure in the device driver that nobody
can orphan the MTD while it is in use.
e.g. drivers/mtd/ubi/gluebi.c does so. In _get_device() it grabs a reference on the
underlying UBI volume to make sure it cannot go away while the MTD (on top of UBI)
is in use.

Thanks,
//richard



More information about the linux-mtd mailing list