static int qcom_smd_channel_open()

in qcom_smd.c [815:859]


static int qcom_smd_channel_open(struct qcom_smd_channel *channel,
				 rpmsg_rx_cb_t cb)
{
	struct qcom_smd_edge *edge = channel->edge;
	size_t bb_size;
	int ret;

	/*
	 * Packets are maximum 4k, but reduce if the fifo is smaller
	 */
	bb_size = min(channel->fifo_size, SZ_4K);
	channel->bounce_buffer = kmalloc(bb_size, GFP_KERNEL);
	if (!channel->bounce_buffer)
		return -ENOMEM;

	qcom_smd_channel_set_callback(channel, cb);
	qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENING);

	/* Wait for remote to enter opening or opened */
	ret = wait_event_interruptible_timeout(channel->state_change_event,
			channel->remote_state == SMD_CHANNEL_OPENING ||
			channel->remote_state == SMD_CHANNEL_OPENED,
			HZ);
	if (!ret) {
		dev_err(&edge->dev, "remote side did not enter opening state\n");
		goto out_close_timeout;
	}

	qcom_smd_channel_set_state(channel, SMD_CHANNEL_OPENED);

	/* Wait for remote to enter opened */
	ret = wait_event_interruptible_timeout(channel->state_change_event,
			channel->remote_state == SMD_CHANNEL_OPENED,
			HZ);
	if (!ret) {
		dev_err(&edge->dev, "remote side did not enter open state\n");
		goto out_close_timeout;
	}

	return 0;

out_close_timeout:
	qcom_smd_channel_set_state(channel, SMD_CHANNEL_CLOSED);
	return -ETIMEDOUT;
}