[PATCH] mtdcore: Infrastructure for the device release API

Martin Habets mhabets at solarflare.com
Wed May 31 09:15:11 PDT 2017

On 27/05/17 01:13, Brian Norris wrote:
> On Thu, May 18, 2017 at 10:23:11AM +0100, Martin Habets wrote:
>> This API adds a cleanup callback for the user of an MTD device.
>> Normally they will have allocated the mtd_info structure, and using
>> this callback they can free that memory when the last reference is
>> dropped.
> Can you provide an example user? This callback is meaningless (and won't
> be merged) if it has no users.

I found this for the sfc driver (drivers/net/ethernet/sfc), but it also affects
all drivers that use mtd_partition (i.e. mtdpart.c).

>> CONFIG_DEBUG_KOBJECT_RELEASE can be used to detect users that free
>> the memory too early.
> Are there any such users?

Apart from the sfc driver there are lots of drivers that use MTD partitions
it seems. There could be other drivers that I'm not aware of.

To highlight the issue in mtdpart.c: in del_mtd_partitions() it calls
del_mtd_device() to unregister the device and then frees the memory in
The freeing of memory could happen before the last reference to the device
has been dropped (and off course the memory could be handed out again to
something else).

If this callback is acceptable we can fix mtdpart.c all other drivers over
time. Fixes for the sfc driver go through netdev, and I would not want to
burden this mailing lists with the patch for that driver.

>> The information contained in this message is confidential and is
>> intended for the addressee(s) only. If you have received this message
>> in error, please notify the sender immediately and delete the message.
>> Unless you are an addressee (or authorized to receive for an
>> addressee), you may not use, copy or disclose to anyone this message
>> or any information contained in this message. The unauthorized use,
>> disclosure, copying or alteration of this message is strictly
>> prohibited.
> Nice.

Sorry, I hope this has been fixed now.


More information about the linux-mtd mailing list