Re: [PATCH 2/3] drivers/media/media-entity: clear media_gobj.mdev in _destroy()
From: Max Kellermann
Date: Fri Jun 17 2016 - 09:04:12 EST
On 2016/06/17 14:53, Sakari Ailus <sakari.ailus@xxxxxx> wrote:
> On Wed, Jun 15, 2016 at 10:15:07PM +0200, Max Kellermann wrote:
> > media_gobj_destroy() may be called twice on one instance - once by
> > media_device_unregister() and again by dvb_media_device_free(). The
>
> Is that something that should really happen, and why? The same object should
> not be unregistered more than once --- in many call paths gobj
> unregistration is followed by kfree() on the gobj.
True, it should not happen, and I think the code is currently
misdesigned (or I just don't grasp it correctly; I may be wrong).
The "gobj" is inserted into a linked list, the list's owner
(media_device) feels responsible to free items in that list. Plus,
the dvb_device instances holds a pointer and also tries to free it.
Usually, dvbdev.c destruction gets called first, which removes the
"gobj" from the linked list, and media_device never sees it during its
own destruction. But that ordering is all but guaranteed. It just
happens to be that way under "normal" circumstances.
None of this makes any sense to me. There appears to be lots of bogus
and unsafe code. I'm still waiting for somebody with more clue to
enlighten me.
Max