[RFC 7/8] drivers: introduce rpmsg, a remote-processor messaging bus

Grant Likely grant.likely at secretlab.ca
Wed Jun 29 11:43:10 EDT 2011


On Tue, Jun 28, 2011 at 5:00 PM, Ohad Ben-Cohen <ohad at wizery.com> wrote:
> On Wed, Jun 29, 2011 at 1:51 AM, Grant Likely <grant.likely at secretlab.ca> wrote:
>> It's not the device_for_each_child() that you're 'putting' back from
>> here.  Its the original kref initialization when the device was
>> created.
>
> device_unregister() is already calling put_device(), doesn't that deal
> with the original kref init for us ?

/me digs deeper:

device_register() has 2 parts; device_initialize() and device_add()
device_init() initialized the kref to 1 (via kobject_init()
device_add() calls get_device() to increment it to 2

Then similarly for device_unregister():
device_del() calls put_device() to decrement the kref to 1
a final put_device() call decrements the kref to 0 - which triggers a
call to the release method that kfrees the object.

So you are right that device_unregister drops the refcount to zero,
but the code still needs to be fixed to not call kfree() directly.

It also looks like rpmsg_destroy_channel() needs to be fixed to remove
the kfree call and an extra put_device() call.  This is important
because the last put_device() call above might /not/ decrement the
refcount to zero is for some reason something still holds a reference
to the device.  But the device will still get freed correctly when the
other holder finally calls device_put().

g.



More information about the linux-arm-kernel mailing list