Skip to content

Commit

Permalink
Coverity/23.12: fix code scan issues (#647) (#649)
Browse files Browse the repository at this point in the history
Signed-off-by: Ric Li <[email protected]>
  • Loading branch information
ricmli authored Dec 15, 2023
1 parent 611244c commit 905bae3
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/sample/fwd/rx_st20p_tx_st20p_downsample_merge_fwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static void* tx_st20p_fwd_thread(void* args) {
struct merge_fwd_sample_ctx* s = args;
st20p_tx_handle tx_handle = s->tx_handle;
struct st_frame* frame;
struct st_frame down_frame; /* empty temp frame*/
struct st_frame down_frame = {0}; /* empty temp frame*/

/* in case when timestamp mismatch */
struct st_frame* rx_restore_frame = NULL;
Expand Down
6 changes: 4 additions & 2 deletions include/mtl_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,20 @@ enum mtl_port {
MTL_PORT_5, /**< port index: 5 */
MTL_PORT_6, /**< port index: 6 */
MTL_PORT_7, /**< port index: 7 */
MTL_PORT_MAX, /**< max value of this enum */
};

#define MTL_PORT_MAX (MTL_PORT_7 + 1)

/**
* Session port logical type
*/
enum mtl_session_port {
MTL_SESSION_PORT_P = 0, /**< primary session(logical) port */
MTL_SESSION_PORT_R, /**< redundant session(logical) port */
MTL_SESSION_PORT_MAX, /**< max value of this enum */
};

#define MTL_SESSION_PORT_MAX (MTL_SESSION_PORT_R + 1)

/**
* Log level type to MTL context
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/src/datapath/mt_dp_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static uint16_t tx_socket_send_mbuf_gso(struct mt_tx_socket_thread* t,
int fd = t->fd, ret;
uint16_t gso_sz = entry->gso_sz;
struct iovec iovs[nb_pkts];
int gso_cnt = 0;
uint16_t gso_cnt = 0;
struct msghdr* msg = &t->msg;
ssize_t write;
struct mtl_port_status* stats = mt_if(entry->parent, port)->dev_stats_sw;
Expand Down
3 changes: 2 additions & 1 deletion lib/src/dev/mt_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1852,8 +1852,9 @@ int mt_dev_create(struct mtl_main_impl* impl) {

/* create system sch */
impl->main_sch = mt_sch_get(impl, 0, MT_SCH_TYPE_DEFAULT, MT_SCH_MASK_ALL);
if (ret < 0) {
if (!impl->main_sch) {
err("%s, get sch fail\n", __func__);
ret = -EIO;
goto err_exit;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/mt_instance.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int mt_instance_init(struct mtl_main_impl* impl, struct mtl_init_params* p) {
mtl_register_message_t* reg_msg = &msg.body.register_msg;
reg_msg->pid = htonl(u_info->pid);
reg_msg->uid = htonl(getuid());
strncpy(reg_msg->hostname, u_info->hostname, sizeof(reg_msg->hostname));
snprintf(reg_msg->hostname, sizeof(reg_msg->hostname), "%s", u_info->hostname);

/* manager will load xdp program for afxdp interfaces */
uint16_t num_xdp_if = 0;
Expand Down
2 changes: 0 additions & 2 deletions tests/src/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ TEST(Misc, hp_malloc_expect_fail) {
int num_port = st_test_num_port(ctx);

hp_malloc_test(ctx, 0, MTL_PORT_P, false, false);
hp_malloc_test(ctx, 8, MTL_PORT_MAX, false, false);
if (num_port > 1) hp_malloc_test(ctx, 0, MTL_PORT_R, false, false);
}

Expand All @@ -492,7 +491,6 @@ TEST(Misc, hp_zmalloc_expect_fail) {
int num_port = st_test_num_port(ctx);

hp_malloc_test(ctx, 0, MTL_PORT_P, true, false);
hp_malloc_test(ctx, 8, MTL_PORT_MAX, true, false);
if (num_port > 1) hp_malloc_test(ctx, 0, MTL_PORT_R, true, false);
}

Expand Down
12 changes: 5 additions & 7 deletions tests/src/ufd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,7 @@ static void socket_expect_fail_test(enum mtl_port port) {
EXPECT_LT(ret, 0);
}

TEST(Api, socket_expect_fail) {
socket_expect_fail_test(MTL_PORT_P);
int ret = mufd_socket_port(AF_INET, SOCK_STREAM, 0, MTL_PORT_MAX);
EXPECT_LT(ret, 0);
}
TEST(Api, socket_expect_fail) { socket_expect_fail_test(MTL_PORT_P); }
TEST(Api, socket_expect_fail_r) { socket_expect_fail_test(MTL_PORT_R); }

static void socket_max_test(enum mtl_port port) {
Expand Down Expand Up @@ -309,8 +305,10 @@ static int check_r_port_alive(struct mtl_init_params* p) {
if (ret < 0) goto out;

while (retry < max_retry) {
mufd_sendto(tx_fd, send_buf, sizeof(send_buf), 0, (const struct sockaddr*)&rx_addr,
sizeof(rx_addr));
if (mufd_sendto(tx_fd, send_buf, sizeof(send_buf), 0,
(const struct sockaddr*)&rx_addr, sizeof(rx_addr)) < 0)
warn("%s, send buf fail at %d\n", __func__, retry);

ssize_t recv = mufd_recvfrom(rx_fd, recv_buf, sizeof(recv_buf), 0, NULL, NULL);
if (recv > 0) {
info("%s, rx port alive at %d\n", __func__, retry);
Expand Down

0 comments on commit 905bae3

Please sign in to comment.