Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8cf25cc1 authored by Chris Lew's avatar Chris Lew
Browse files

rpmsg: glink: spi: Fix idr and channel refcounts



Each kref_put represents a cleanup for an open function. Remove the
extra kref put and rely on transport remove to cleanup any defunct
channels. Remove the idr from the lcid and rcid lists since the idr is
added on the open calls. This prevents any references to the dangling
pointers after cleanup.

Change-Id: I5c78ab17b716f5dea36b5d23ed2888ad5743edbf
Signed-off-by: default avatarChris Lew <clew@codeaurora.org>
parent 159dc458
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -1501,13 +1501,12 @@ static int glink_spi_create_remote(struct glink_spi *glink,

	/*
	 * Send a close request to "undo" our open-ack. The close-ack will
	 * release the last reference.
	 * release glink_spi_send_open_req() reference and the last reference
	 * will be release after rx_close or transport unregister by calling
	 * glink_spi_remove().
	 */
	glink_spi_send_close_req(glink, channel);

	/* Release glink_spi_send_open_req() reference */
	kref_put(&channel->refcount, glink_spi_channel_release);

	return ret;
}

@@ -2470,13 +2469,15 @@ static void glink_spi_remove(struct glink_spi *glink)
	spin_lock_irqsave(&glink->idr_lock, flags);
	/* Release any defunct local channels, waiting for close-ack */
	idr_for_each_entry(&glink->lcids, channel, cid) {
		if (kref_put(&channel->refcount, glink_spi_channel_release))
		kref_put(&channel->refcount, glink_spi_channel_release);
		idr_remove(&glink->lcids, cid);
	}

	/* Release any defunct local channels, waiting for close-req */
	idr_for_each_entry(&glink->lcids, channel, cid)
	idr_for_each_entry(&glink->lcids, channel, cid) {
		kref_put(&channel->refcount, glink_spi_channel_release);
		idr_remove(&glink->lcids, cid);
	}

	idr_destroy(&glink->lcids);
	idr_destroy(&glink->rcids);