Skip to content

Commit 268105f

Browse files
committed
rpmsg: smd: Perform handshake during open
Validate the the remote side is opening the channel that we've found by performing a handshake when opening the channel. Tested-by: Will Newton <[email protected]> Signed-off-by: Bjorn Andersson <[email protected]>
1 parent 9d32497 commit 268105f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

drivers/rpmsg/qcom_smd.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ struct qcom_smd_channel {
200200
char *name;
201201
enum smd_channel_state state;
202202
enum smd_channel_state remote_state;
203+
wait_queue_head_t state_change_event;
203204

204205
struct smd_channel_info_pair *info;
205206
struct smd_channel_info_word_pair *info_word;
@@ -570,6 +571,8 @@ static bool qcom_smd_channel_intr(struct qcom_smd_channel *channel)
570571
if (remote_state != channel->remote_state) {
571572
channel->remote_state = remote_state;
572573
need_state_scan = true;
574+
575+
wake_up_interruptible_all(&channel->state_change_event);
573576
}
574577
/* Indicate that we have seen any state change */
575578
SET_RX_CHANNEL_FLAG(channel, fSTATE, 0);
@@ -786,7 +789,9 @@ static int __qcom_smd_send(struct qcom_smd_channel *channel, const void *data,
786789
static int qcom_smd_channel_open(struct qcom_smd_channel *channel,
787790
rpmsg_rx_cb_t cb)
788791
{
792+
struct qcom_smd_edge *edge = channel->edge;
789793
size_t bb_size;
794+
int ret;
790795

791796
/*
792797
* Packets are maximum 4k, but reduce if the fifo is smaller
@@ -798,9 +803,33 @@ static int qcom_smd_channel_open(struct qcom_smd_channel *channel,
798803

799804
qcom_smd_channel_set_callback(channel, cb);
800805
qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENING);
806+
807+
/* Wait for remote to enter opening or opened */
808+
ret = wait_event_interruptible_timeout(channel->state_change_event,
809+
channel->remote_state == SMD_CHANNEL_OPENING ||
810+
channel->remote_state == SMD_CHANNEL_OPENED,
811+
HZ);
812+
if (!ret) {
813+
dev_err(&edge->dev, "remote side did not enter opening state\n");
814+
goto out_close_timeout;
815+
}
816+
801817
qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENED);
802818

819+
/* Wait for remote to enter opened */
820+
ret = wait_event_interruptible_timeout(channel->state_change_event,
821+
channel->remote_state == SMD_CHANNEL_OPENED,
822+
HZ);
823+
if (!ret) {
824+
dev_err(&edge->dev, "remote side did not enter open state\n");
825+
goto out_close_timeout;
826+
}
827+
803828
return 0;
829+
830+
out_close_timeout:
831+
qcom_smd_channel_set_state(channel, SMD_CHANNEL_CLOSED);
832+
return -ETIMEDOUT;
804833
}
805834

806835
/*
@@ -1055,6 +1084,7 @@ static struct qcom_smd_channel *qcom_smd_create_channel(struct qcom_smd_edge *ed
10551084
mutex_init(&channel->tx_lock);
10561085
spin_lock_init(&channel->recv_lock);
10571086
init_waitqueue_head(&channel->fblockread_event);
1087+
init_waitqueue_head(&channel->state_change_event);
10581088

10591089
info = qcom_smem_get(edge->remote_pid, smem_info_item, &info_size);
10601090
if (IS_ERR(info)) {

0 commit comments

Comments
 (0)