aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/memif
diff options
context:
space:
mode:
authorMilan Lenco <milan.lenco@pantheon.tech>2017-03-31 14:51:18 +0200
committerDamjan Marion <dmarion.lists@gmail.com>2017-04-03 11:20:10 +0000
commitc966ecd11ccb4e2ad8e92385a4935c8fd4586a2d (patch)
tree5a581088859256baf02f24b337c8a9790db23dfa /src/plugins/memif
parentc4ba20fe05d0c10da6a244e77b756dab27c76d8a (diff)
Fix memif coverity issues
Change-Id: I844ec53b55ceaa1e00996f5cf8a018537ea8b481 Signed-off-by: Milan Lenco <milan.lenco@pantheon.tech>
Diffstat (limited to 'src/plugins/memif')
-rw-r--r--src/plugins/memif/device.c16
-rw-r--r--src/plugins/memif/memif.c26
-rw-r--r--src/plugins/memif/memif.h1
3 files changed, 33 insertions, 10 deletions
diff --git a/src/plugins/memif/device.c b/src/plugins/memif/device.c
index 4faeb0554f3..70bdb48ba9c 100644
--- a/src/plugins/memif/device.c
+++ b/src/plugins/memif/device.c
@@ -193,7 +193,7 @@ memif_interface_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
CLIB_MEMORY_STORE_BARRIER ();
ring->head = head;
- clib_spinlock_unlock (&mif->lockp);
+ clib_spinlock_unlock_if_init (&mif->lockp);
if (n_left)
{
@@ -255,9 +255,11 @@ static clib_error_t *
memif_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
{
memif_main_t *apm = &memif_main;
- memif_msg_t msg;
+ vlib_main_t *vm = vlib_get_main ();
+ memif_msg_t msg = { 0 };
vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
memif_if_t *mif = pool_elt_at_index (apm->interfaces, hw->dev_instance);
+ static clib_error_t *error = 0;
if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
mif->flags |= MEMIF_IF_FLAG_ADMIN_UP;
@@ -269,11 +271,17 @@ memif_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
{
msg.version = MEMIF_VERSION;
msg.type = MEMIF_MSG_TYPE_DISCONNECT;
- send (mif->connection.fd, &msg, sizeof (msg), 0);
+ if (send (mif->connection.fd, &msg, sizeof (msg), 0) < 0)
+ {
+ clib_unix_warning ("Failed to send disconnect request");
+ error = clib_error_return_unix (0, "send fd %d",
+ mif->connection.fd);
+ memif_disconnect (vm, mif);
+ }
}
}
- return 0;
+ return error;
}
static clib_error_t *
diff --git a/src/plugins/memif/memif.c b/src/plugins/memif/memif.c
index cf8ca577d54..f0d4aacded2 100644
--- a/src/plugins/memif/memif.c
+++ b/src/plugins/memif/memif.c
@@ -85,7 +85,7 @@ memif_connect (vlib_main_t * vm, memif_if_t * mif)
VNET_HW_INTERFACE_FLAG_LINK_UP);
}
-static void
+void
memif_disconnect (vlib_main_t * vm, memif_if_t * mif)
{
vnet_main_t *vnm = vnet_get_main ();
@@ -248,7 +248,12 @@ response:
resp.version = MEMIF_VERSION;
resp.type = MEMIF_MSG_TYPE_CONNECT_RESP;
resp.retval = retval;
- send (fd, &resp, sizeof (resp), 0);
+ if (send (fd, &resp, sizeof (resp), 0) < 0)
+ {
+ DEBUG_UNIX_LOG ("Failed to send connection response");
+ error = clib_error_return_unix (0, "send fd %d", fd);
+ memif_disconnect (vm, mif);
+ }
return error;
}
@@ -511,7 +516,8 @@ memif_connect_master (vlib_main_t * vm, memif_if_t * mif)
{
u16 slot = i * (1 << mif->log2_ring_size) + j;
ring->desc[j].region = 0;
- ring->desc[j].offset = buffer_offset + (slot * mif->buffer_size);
+ ring->desc[j].offset =
+ buffer_offset + (u32) (slot * mif->buffer_size);
ring->desc[j].buffer_length = mif->buffer_size;
}
}
@@ -524,7 +530,8 @@ memif_connect_master (vlib_main_t * vm, memif_if_t * mif)
u16 slot =
(i + mif->num_s2m_rings) * (1 << mif->log2_ring_size) + j;
ring->desc[j].region = 0;
- ring->desc[j].offset = buffer_offset + (slot * mif->buffer_size);
+ ring->desc[j].offset =
+ buffer_offset + (u32) (slot * mif->buffer_size);
ring->desc[j].buffer_length = mif->buffer_size;
}
}
@@ -595,6 +602,11 @@ memif_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
f64 start_time, last_run_duration = 0, now;
sockfd = socket (AF_UNIX, SOCK_STREAM, 0);
+ if (sockfd < 0)
+ {
+ DEBUG_UNIX_LOG ("socket AF_UNIX");
+ return 0;
+ }
sun.sun_family = AF_UNIX;
template.read_function = memif_conn_fd_read_ready;
@@ -730,26 +742,28 @@ int
memif_worker_thread_enable ()
{
/* if worker threads are enabled, switch to polling mode */
+ /* *INDENT-OFF* */
foreach_vlib_main ((
{
vlib_node_set_state (this_vlib_main,
memif_input_node.index,
VLIB_NODE_STATE_POLLING);
}));
-
+ /* *INDENT-ON* */
return 0;
}
int
memif_worker_thread_disable ()
{
+ /* *INDENT-OFF* */
foreach_vlib_main ((
{
vlib_node_set_state (this_vlib_main,
memif_input_node.index,
VLIB_NODE_STATE_INTERRUPT);
}));
-
+ /* *INDENT-ON* */
return 0;
}
diff --git a/src/plugins/memif/memif.h b/src/plugins/memif/memif.h
index f57170f8e6f..ea5b350173d 100644
--- a/src/plugins/memif/memif.h
+++ b/src/plugins/memif/memif.h
@@ -196,6 +196,7 @@ typedef struct
int memif_create_if (vlib_main_t * vm, memif_create_if_args_t * args);
int memif_delete_if (vlib_main_t * vm, u64 key);
+void memif_disconnect (vlib_main_t * vm, memif_if_t * mif);
clib_error_t *memif_plugin_api_hookup (vlib_main_t * vm);
#ifndef __NR_memfd_create