[PATCH 1/2] mtd: use put_device() if device_register fail

Martin Habets mhabets at solarflare.com
Wed Mar 21 03:08:33 PDT 2018


Hi Arvind,

On 19/03/18 17:56, arvindY wrote:
> 
> 
> On Monday 19 March 2018 04:13 PM, Martin Habets wrote:
>> On 17/03/18 09:45, arvindY wrote:
>>>>>       of_node_put(mtd_get_of_node(mtd));
>>>> You're referencing an object that is supposed to have been
>>>> freed/released by the put_device() call. Again, it's not really a
>>>> problem because in our case ->release() does not free the mtd object
>>>> (as is usually done in other parts of the kernel), but it still looks
>>>> wrong. It's probably better to move the of_node_put() and the below
>>>> idr_remove() call in the ->release() hook if you want to use
>>>> put_device().
>>>>
>>>>>       idr_remove(&mtd_idr, i);
>>> Sure, we can move put_device() below this. But need to check
>>> how we can add hook in release.
>> My guess is that you would need this:
>> http://lists.infradead.org/pipermail/linux-mtd/2017-May/074373.html
> 
> we should not removes(device_destroy) a MTD device in
> release. MTD device should be removes when
> deleting(unregister) a MTD device.

No, deleting an MTD device should only decrement a refcounter.
At this point there can still be other processes with a /dev/mtd*
device open.
When there are no more users release gets called to remove it.

> MTD device should decrement refcount of a node and
> Remove MTD from IDR in dev->release().

You could be right about this, I'm not sure.

My patch allows the caller to free the mtd_info memory. This is needed since
the caller allocated the memory in the first place, and because the caller has
no other of knowing that the last MTD user is gone.

Martin




More information about the linux-mtd mailing list