Skip to content

Commit fa2d779

Browse files
committed
rpmsg: fix name service endpoint leak
The name service endpoint wasn't destroyed, so fix it. This is achieved by introducing an internal __rpmsg_destroy_ept function which doesn't assume the given ept is bound to an rpmsg channel (much like the existing __rpmsg_create_ept). This is needed because the name service ept belongs to the rpmsg bus, and is never bound with a specific rpdev. Reported-by: Omar Ramirez Luna <omar.ramirez@ti.com> Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com> Cc: Grant Likely <grant.likely@secretlab.ca> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Mark Grosen <mgrosen@ti.com> Cc: Suman Anna <s-anna@ti.com> Cc: Fernando Guzman Lugo <fernando.lugo@ti.com> Cc: Rob Clark <rob@ti.com> Cc: Ludovic BARRE <ludovic.barre@stericsson.com> Cc: Loic PALLARDY <loic.pallardy@stericsson.com> Cc: Omar Ramirez Luna <omar.ramirez@ti.com>
1 parent 9cd8eb4 commit fa2d779

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

‎drivers/rpmsg/virtio_rpmsg_bus.c‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,22 +290,36 @@ struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_channel *rpdev,
290290
EXPORT_SYMBOL(rpmsg_create_ept);
291291

292292
/**
293-
* rpmsg_destroy_ept() - destroy an existing rpmsg endpoint
293+
* __rpmsg_destroy_ept() - destroy an existing rpmsg endpoint
294+
* @vrp: virtproc which owns this ept
294295
* @ept: endpoing to destroy
295296
*
296-
* Should be used by drivers to destroy an rpmsg endpoint previously
297-
* created with rpmsg_create_ept().
297+
* An internal function which destroy an ept without assuming it is
298+
* bound to an rpmsg channel. This is needed for handling the internal
299+
* name service endpoint, which isn't bound to an rpmsg channel.
300+
* See also __rpmsg_create_ept().
298301
*/
299-
void rpmsg_destroy_ept(struct rpmsg_endpoint *ept)
302+
static void
303+
__rpmsg_destroy_ept(struct virtproc_info *vrp, struct rpmsg_endpoint *ept)
300304
{
301-
struct virtproc_info *vrp = ept->rpdev->vrp;
302-
303305
mutex_lock(&vrp->endpoints_lock);
304306
idr_remove(&vrp->endpoints, ept->addr);
305307
mutex_unlock(&vrp->endpoints_lock);
306308

307309
kfree(ept);
308310
}
311+
312+
/**
313+
* rpmsg_destroy_ept() - destroy an existing rpmsg endpoint
314+
* @ept: endpoing to destroy
315+
*
316+
* Should be used by drivers to destroy an rpmsg endpoint previously
317+
* created with rpmsg_create_ept().
318+
*/
319+
void rpmsg_destroy_ept(struct rpmsg_endpoint *ept)
320+
{
321+
__rpmsg_destroy_ept(ept->rpdev->vrp, ept);
322+
}
309323
EXPORT_SYMBOL(rpmsg_destroy_ept);
310324

311325
/*
@@ -964,6 +978,9 @@ static void __devexit rpmsg_remove(struct virtio_device *vdev)
964978
if (ret)
965979
dev_warn(&vdev->dev, "can't remove rpmsg device: %d\n", ret);
966980

981+
if (vrp->ns_ept)
982+
__rpmsg_destroy_ept(vrp, vrp->ns_ept);
983+
967984
idr_remove_all(&vrp->endpoints);
968985
idr_destroy(&vrp->endpoints);
969986

0 commit comments

Comments
 (0)