[PATCH] mtdcore: Infrastructure for the device release API

Martin Habets mhabets at solarflare.com
Thu Jun 22 06:54:07 PDT 2017


Brian, any opinion about this?

Thanks,
Martin

On 31/05/17 17:15, Martin Habets wrote:
> 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
> free_partition().
> 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.



More information about the linux-mtd mailing list