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

Commit 09174e50 authored by Amir Samuelov's avatar Amir Samuelov Committed by Gerrit - the friendly Code Review server
Browse files

spcom: ignore CONNECTED notification while closing the channel



The spcom_notify_state() callback, is called by glink driver.
In case of calling glink_open() and shortly after that calling
glink_close(), the glink might notify of channel CONNECTED while
glink_closed() is called.
Avoid updating the glink channel upon CONNECTED event, if in process
of closing the channel.

Change-Id: If5cbec1a7d1653c56b5350afcd3cee61e1ae05fa
Signed-off-by: default avatarAmir Samuelov <amirs@codeaurora.org>
parent afce6728
Loading
Loading
Loading
Loading
+43 −26
Original line number Diff line number Diff line
@@ -193,6 +193,7 @@ struct spcom_channel {
	 * glink state: CONNECTED / LOCAL_DISCONNECTED, REMOTE_DISCONNECTED
	 */
	unsigned int glink_state;
	bool is_closing;

	/* Events notification */
	struct completion connect;
@@ -481,7 +482,17 @@ static void spcom_notify_state(void *handle, const void *priv,
	switch (event) {
	case GLINK_CONNECTED:
		pr_debug("GLINK_CONNECTED, ch name [%s].\n", ch->name);
		mutex_lock(&ch->lock);

		if (ch->is_closing) {
			pr_err("Unexpected CONNECTED while closing [%s].\n",
				ch->name);
			mutex_unlock(&ch->lock);
			return;
		}

		ch->glink_state = event;

		/*
		 * if spcom_notify_state() is called within glink_open()
		 * then ch->glink_handle is not updated yet.
@@ -491,17 +502,28 @@ static void spcom_notify_state(void *handle, const void *priv,
			ch->glink_handle = handle;
		}

		/* prepare default rx buffer after connected */
		/* signal before unlock mutex & before calling glink */
		complete_all(&ch->connect);

		/*
		 * Prepare default rx buffer.
		 * glink_queue_rx_intent() can be called only AFTER connected.
		 * We do it here, ASAP, to allow rx data.
		 */

		pr_debug("call glink_queue_rx_intent() ch [%s].\n", ch->name);
		ret = glink_queue_rx_intent(ch->glink_handle,
					    ch, ch->rx_buf_size);
		if (ret) {
			pr_err("glink_queue_rx_intent() err [%d]\n", ret);
		} else {
			pr_debug("rx buf is ready, size [%zu].\n",
			pr_debug("rx buf is ready, size [%zu]\n",
				 ch->rx_buf_size);
			ch->rx_buf_ready = true;
		}
		complete_all(&ch->connect);

		pr_debug("GLINK_CONNECTED, ch name [%s] done.\n", ch->name);
		mutex_unlock(&ch->lock);
		break;
	case GLINK_LOCAL_DISCONNECTED:
		/*
@@ -554,9 +576,7 @@ static void spcom_notify_state(void *handle, const void *priv,
static bool spcom_notify_rx_intent_req(void *handle, const void *priv,
				       size_t req_size)
{
	struct spcom_channel *ch = (struct spcom_channel *) priv;

	pr_err("Unexpected intent request for ch [%s].\n", ch->name);
	pr_err("Unexpected intent request\n");

	return false;
}
@@ -668,6 +688,13 @@ static int spcom_init_channel(struct spcom_channel *ch, const char *name)
	ch->glink_state = GLINK_LOCAL_DISCONNECTED;
	ch->actual_rx_size = 0;
	ch->rx_buf_size = SPCOM_RX_BUF_SIZE;
	ch->is_closing = false;
	ch->glink_handle = NULL;
	ch->ref_count = 0;
	ch->rx_abort = false;
	ch->tx_abort = false;
	ch->txn_id = INITIAL_TXN_ID; /* use non-zero nonce for debug */
	ch->pid = 0;

	return 0;
}
@@ -737,6 +764,8 @@ static int spcom_open(struct spcom_channel *ch, unsigned int timeout_msec)
	/* init completion before calling glink_open() */
	reinit_completion(&ch->connect);

	ch->is_closing = false;

	handle = glink_open(&cfg);
	if (IS_ERR_OR_NULL(handle)) {
		pr_err("glink_open failed.\n");
@@ -751,6 +780,8 @@ static int spcom_open(struct spcom_channel *ch, unsigned int timeout_msec)
	ch->pid = current_pid();
	ch->txn_id = INITIAL_TXN_ID;

	mutex_unlock(&ch->lock);

	pr_debug("Wait for connection on channel [%s] timeout_msec [%d].\n",
		 name, timeout_msec);

@@ -767,8 +798,6 @@ static int spcom_open(struct spcom_channel *ch, unsigned int timeout_msec)
		pr_debug("Channel [%s] opened, no timeout.\n", name);
	}

	mutex_unlock(&ch->lock);

	return 0;
exit_err:
	mutex_unlock(&ch->lock);
@@ -795,6 +824,8 @@ static int spcom_close(struct spcom_channel *ch)
		return 0;
	}

	ch->is_closing = true;

	ret = glink_close(ch->glink_handle);
	if (ret)
		pr_err("glink_close() fail, ret [%d].\n", ret);
@@ -810,6 +841,7 @@ static int spcom_close(struct spcom_channel *ch)
	ch->pid = 0;

	pr_debug("Channel closed [%s].\n", ch->name);

	mutex_unlock(&ch->lock);

	return 0;
@@ -1921,18 +1953,6 @@ static int spcom_handle_unlock_ion_buf_command(struct spcom_channel *ch,
	return ret;
}

/**
 * spcom_handle_fake_ssr_command() - Handle fake ssr command from user space.
 */
static int spcom_handle_fake_ssr_command(struct spcom_channel *ch, int arg)
{
	pr_debug("Start Fake glink SSR subsystem [%s].\n", spcom_edge);
	glink_ssr(spcom_edge);
	pr_debug("Fake glink SSR subsystem [%s] done.\n", spcom_edge);

	return 0;
}

/**
 * spcom_handle_write() - Handle user space write commands.
 *
@@ -1979,9 +1999,6 @@ static int spcom_handle_write(struct spcom_channel *ch,
	case SPCOM_CMD_UNLOCK_ION_BUF:
		ret = spcom_handle_unlock_ion_buf_command(ch, buf, buf_size);
		break;
	case SPCOM_CMD_FSSR:
		ret = spcom_handle_fake_ssr_command(ch, cmd->arg);
		break;
	case SPCOM_CMD_CREATE_CHANNEL:
		ret = spcom_handle_create_channel_command(buf, buf_size);
		break;
@@ -2765,7 +2782,7 @@ static int __init spcom_init(void)
{
	int ret;

	pr_info("spcom driver Ver 1.0 23-Nov-2015.\n");
	pr_info("spcom driver version 1.1 17-July-2017.\n");

	ret = platform_driver_register(&spcom_driver);
	if (ret)