msm: ipc: Clean-up code redundancy

The receive message operation for the socket interface and the kernel
interface has redundant code.

Clean-up redundant code.

Change-Id: Ibe52816f5b567feab4d6247a3dba1945e209c626
Signed-off-by: Arun Kumar Neelakantam <aneela@codeaurora.org>
This commit is contained in:
Arun Kumar Neelakantam 2013-06-21 17:57:18 +05:30 committed by Stephen Boyd
parent c68a6ce8ad
commit eb09ba06fd
3 changed files with 57 additions and 52 deletions

View File

@ -2265,6 +2265,48 @@ int msm_ipc_router_read(struct msm_ipc_port *port_ptr,
return ret;
}
/**
* msm_ipc_router_rx_data_wait() - Wait for new message destined to a local port.
* @port_ptr: Pointer to the local port
* @timeout: < 0 timeout indicates infinite wait till a message arrives.
* > 0 timeout indicates the wait time.
* 0 indicates that we do not wait.
* @return: 0 if there are pending messages to read,
* standard Linux error code otherwise.
*
* Checks for the availability of messages that are destined to a local port.
* If no messages are present then waits as per @timeout.
*/
int msm_ipc_router_rx_data_wait(struct msm_ipc_port *port_ptr, long timeout)
{
int ret = 0;
mutex_lock(&port_ptr->port_rx_q_lock_lhb3);
while (list_empty(&port_ptr->port_rx_q)) {
mutex_unlock(&port_ptr->port_rx_q_lock_lhb3);
if (timeout < 0) {
ret = wait_event_interruptible(
port_ptr->port_rx_wait_q,
!list_empty(&port_ptr->port_rx_q));
if (ret)
return ret;
} else if (timeout > 0) {
timeout = wait_event_interruptible_timeout(
port_ptr->port_rx_wait_q,
!list_empty(&port_ptr->port_rx_q),
timeout);
if (timeout < 0)
return -EFAULT;
}
if (timeout == 0)
return -ENOMSG;
mutex_lock(&port_ptr->port_rx_q_lock_lhb3);
}
mutex_unlock(&port_ptr->port_rx_q_lock_lhb3);
return ret;
}
/**
* msm_ipc_router_recv_from() - Recieve messages destined to a local port.
* @port_ptr: Pointer to the local port
@ -2274,7 +2316,7 @@ int msm_ipc_router_read(struct msm_ipc_port *port_ptr,
* > 0 timeout indicates the wait time.
* 0 indicates that we do not wait.
* @return: = Number of bytes read(On successful read operation).
* = 0 (If there are no pending messages and timeout is 0).
* = -ENOMSG (If there are no pending messages and timeout is 0).
* = -EINVAL (If either of the arguments, port_ptr or data is invalid)
* = -EFAULT (If there are no pending messages when timeout is > 0
* and the wait_event_interruptible_timeout has returned value > 0)
@ -2303,28 +2345,10 @@ int msm_ipc_router_recv_from(struct msm_ipc_port *port_ptr,
}
*data = NULL;
mutex_lock(&port_ptr->port_rx_q_lock_lhb3);
while (list_empty(&port_ptr->port_rx_q)) {
mutex_unlock(&port_ptr->port_rx_q_lock_lhb3);
if (timeout < 0) {
ret = wait_event_interruptible(
port_ptr->port_rx_wait_q,
!list_empty(&port_ptr->port_rx_q));
if (ret)
return ret;
} else if (timeout > 0) {
timeout = wait_event_interruptible_timeout(
port_ptr->port_rx_wait_q,
!list_empty(&port_ptr->port_rx_q),
timeout);
if (timeout < 0)
return -EFAULT;
}
if (timeout == 0)
return 0;
mutex_lock(&port_ptr->port_rx_q_lock_lhb3);
}
mutex_unlock(&port_ptr->port_rx_q_lock_lhb3);
ret = msm_ipc_router_rx_data_wait(port_ptr, timeout);
if (ret)
return ret;
ret = msm_ipc_router_read(port_ptr, data, 0);
if (ret <= 0 || !(*data))
@ -2358,12 +2382,10 @@ int msm_ipc_router_read_msg(struct msm_ipc_port *port_ptr,
ret = msm_ipc_router_recv_from(port_ptr, &in_skb_head, src, 0);
if (ret == 0)
return -ENOMSG;
if (ret < 0) {
pr_err("%s: msm_ipc_router_recv_from failed - ret: %d\n",
__func__, ret);
if (ret != -ENOMSG)
pr_err("%s: msm_ipc_router_recv_from failed - ret: %d\n",
__func__, ret);
return ret;
}

View File

@ -160,6 +160,8 @@ void msm_ipc_sync_sec_rule(uint32_t service, uint32_t instance, void *rule);
void msm_ipc_sync_default_sec_rule(void *rule);
int msm_ipc_router_rx_data_wait(struct msm_ipc_port *port_ptr, long timeout);
#if defined CONFIG_MSM_IPC_ROUTER_SMD_XPRT
extern void *msm_ipc_load_default_node(void);

View File

@ -411,33 +411,14 @@ static int msm_ipc_router_recvmsg(struct kiocb *iocb, struct socket *sock,
lock_sock(sk);
timeout = sk->sk_rcvtimeo;
mutex_lock(&port_ptr->port_rx_q_lock_lhb3);
while (list_empty(&port_ptr->port_rx_q)) {
mutex_unlock(&port_ptr->port_rx_q_lock_lhb3);
release_sock(sk);
if (timeout < 0) {
ret = wait_event_interruptible(
port_ptr->port_rx_wait_q,
!list_empty(&port_ptr->port_rx_q));
if (ret)
return ret;
} else if (timeout > 0) {
timeout = wait_event_interruptible_timeout(
port_ptr->port_rx_wait_q,
!list_empty(&port_ptr->port_rx_q),
timeout);
if (timeout < 0)
return -EFAULT;
}
if (timeout == 0) {
ret = msm_ipc_router_rx_data_wait(port_ptr, timeout);
if (ret) {
release_sock(sk);
if (ret == -ENOMSG)
m->msg_namelen = 0;
return 0;
}
lock_sock(sk);
mutex_lock(&port_ptr->port_rx_q_lock_lhb3);
return ret;
}
mutex_unlock(&port_ptr->port_rx_q_lock_lhb3);
ret = msm_ipc_router_read(port_ptr, &msg, buf_len);
if (ret <= 0 || !msg) {