rpmsg: avoid premature deallocation of endpoints
authorOhad Ben-Cohen <ohad@wizery.com>
Wed, 6 Jun 2012 07:09:25 +0000 (10:09 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 16 Jul 2012 16:03:52 +0000 (09:03 -0700)
commit735129c4609e98fd149cddda50b823e43bab0677
tree69ab2f02267bf2f4aeece86c21ad8135d3524b19
parent4ce16269215ffaad3d480425bc74bf632956151e
rpmsg: avoid premature deallocation of endpoints

commit 5a081caa0414b9bbb82c17ffab9d6fe66edbb72f upstream.

When an inbound message arrives, the rpmsg core looks up its
associated endpoint and invokes the registered callback.

If a message arrives while its endpoint is being removed (because
the rpmsg driver was removed, or a recovery of a remote processor
has kicked in) we must ensure atomicity, i.e.:

- Either the ept is removed before it is found

or

- The ept is found but will not be freed until the callback returns

This is achieved by maintaining a per-ept reference count, which,
when drops to zero, will trigger deallocation of the ept.

With this in hand, it is now forbidden to directly deallocate
epts once they have been added to the endpoints idr.

Reported-by: Fernando Guzman Lugo <fernando.lugo@ti.com>
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/rpmsg/virtio_rpmsg_bus.c
include/linux/rpmsg.h