From mboxrd@z Thu Jan 1 00:00:00 1970 From: grant.likely@secretlab.ca (Grant Likely) Date: Wed, 29 Jun 2011 09:43:10 -0600 Subject: [RFC 7/8] drivers: introduce rpmsg, a remote-processor messaging bus In-Reply-To: References: <1308640714-17961-1-git-send-email-ohad@wizery.com> <1308640714-17961-8-git-send-email-ohad@wizery.com> <20110627222121.GD20865@ponder.secretlab.ca> Message-ID: To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Tue, Jun 28, 2011 at 5:00 PM, Ohad Ben-Cohen wrote: > On Wed, Jun 29, 2011 at 1:51 AM, Grant Likely 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.