Skip to content

Commit

Permalink
fix: address coverity issues - part 2 (#1013)
Browse files Browse the repository at this point in the history
Address issues connected with Coverity scan - part 2
  • Loading branch information
PanKaker authored Nov 28, 2024
1 parent 296ca24 commit e217e63
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 56 deletions.
61 changes: 15 additions & 46 deletions app/src/parse_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -2749,60 +2749,29 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) {
ctx->rx_st30p_session_cnt += num;
}

/* allocate rx sessions */
/* Allocate rx sessions */
ctx->rx_video_sessions = (st_json_video_session_t*)st_app_zmalloc(
ctx->rx_video_session_cnt * sizeof(st_json_video_session_t));
if (!ctx->rx_video_sessions) {
err("%s, failed to allocate rx_video_sessions\n", __func__);
ret = -ST_JSON_NULL;
goto error;
}
(size_t)ctx->rx_video_session_cnt * sizeof(st_json_video_session_t));
ctx->rx_audio_sessions = (st_json_audio_session_t*)st_app_zmalloc(
ctx->rx_audio_session_cnt * sizeof(st_json_audio_session_t));
if (!ctx->rx_audio_sessions) {
err("%s, failed to allocate rx_audio_sessions\n", __func__);
ret = -ST_JSON_NULL;
goto error;
}
(size_t)ctx->rx_audio_session_cnt * sizeof(st_json_audio_session_t));
ctx->rx_anc_sessions = (st_json_ancillary_session_t*)st_app_zmalloc(
ctx->rx_anc_session_cnt * sizeof(st_json_ancillary_session_t));
if (!ctx->rx_anc_sessions) {
err("%s, failed to allocate rx_anc_sessions\n", __func__);
ret = -ST_JSON_NULL;
goto error;
}
(size_t)ctx->rx_anc_session_cnt * sizeof(st_json_ancillary_session_t));
ctx->rx_fmd_sessions = (st_json_fastmetadata_session_t*)st_app_zmalloc(
ctx->rx_fmd_session_cnt * sizeof(st_json_fastmetadata_session_t));
if (!ctx->rx_fmd_sessions) {
err("%s, failed to allocate rx_fmd_sessions\n", __func__);
ret = -ST_JSON_NULL;
goto error;
}
(size_t)ctx->rx_fmd_session_cnt * sizeof(st_json_fastmetadata_session_t));
ctx->rx_st22p_sessions = (st_json_st22p_session_t*)st_app_zmalloc(
ctx->rx_st22p_session_cnt * sizeof(st_json_st22p_session_t));
if (!ctx->rx_st22p_sessions) {
err("%s, failed to allocate rx_st22p_sessions\n", __func__);
ret = -ST_JSON_NULL;
goto error;
}
(size_t)ctx->rx_st22p_session_cnt * sizeof(st_json_st22p_session_t));
ctx->rx_st20p_sessions = (st_json_st20p_session_t*)st_app_zmalloc(
ctx->rx_st20p_session_cnt * sizeof(st_json_st20p_session_t));
if (!ctx->rx_st20p_sessions) {
err("%s, failed to allocate rx_st20p_sessions\n", __func__);
ret = -ST_JSON_NULL;
goto error;
}
(size_t)ctx->rx_st20p_session_cnt * sizeof(st_json_st20p_session_t));
ctx->rx_st30p_sessions = (st_json_st30p_session_t*)st_app_zmalloc(
ctx->rx_st30p_session_cnt * sizeof(st_json_st30p_session_t));
if (!ctx->rx_st30p_sessions) {
err("%s, failed to allocate rx_st30p_sessions\n", __func__);
ret = -ST_JSON_NULL;
goto error;
}
(size_t)ctx->rx_st30p_session_cnt * sizeof(st_json_st30p_session_t));
ctx->rx_st20r_sessions = (st_json_video_session_t*)st_app_zmalloc(
ctx->rx_st20r_session_cnt * sizeof(*ctx->rx_st20r_sessions));
if (!ctx->rx_st20r_sessions) {
err("%s, failed to allocate rx_st20r_sessions\n", __func__);
(size_t)ctx->rx_st20r_session_cnt * sizeof(*ctx->rx_st20r_sessions));

/* Check for allocation failures */
if (!ctx->rx_video_sessions || !ctx->rx_audio_sessions || !ctx->rx_anc_sessions ||
!ctx->rx_fmd_sessions || !ctx->rx_st22p_sessions || !ctx->rx_st20p_sessions ||
!ctx->rx_st30p_sessions || !ctx->rx_st20r_sessions) {
err("%s, failed to allocate rx sessions\n", __func__);
ret = -ST_JSON_NULL;
goto error;
}
Expand Down
10 changes: 7 additions & 3 deletions app/v4l2_to_ip/v4l2_to_ip.c
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,10 @@ static int video_alloc_buffers(struct device* dev, int nbufs, unsigned int offse
break;
}

if (ret < 0) return ret;
if (ret < 0) {
free(buffers);
return ret;
}
}

dev->timestamp_type = buf.flags & V4L2_BUF_FLAG_TIMESTAMP_MASK;
Expand Down Expand Up @@ -1314,15 +1317,16 @@ static int tx_video_frame_done(void* priv, uint16_t frame_idx,
int ret;
MTL_MAY_UNUSED(meta);

pthread_mutex_lock(&(framebuff_ctl->wake_mutex));

if (frame_idx != framebuff_ctl->receive_idx) {
ret = -EIO;
printf("%s, receive_idx %d != frame_done %d\n", __func__, framebuff_ctl->receive_idx,
frame_idx);
pthread_mutex_unlock(&(framebuff_ctl->wake_mutex));
return ret;
}

pthread_mutex_lock(&(framebuff_ctl->wake_mutex));

if (TX_FRAME_TRANSMITTING != framebuff_ctl->buffs[framebuff_ctl->receive_idx].status) {
ret = -EIO;
printf("%s, receive status %d != TRASNSMIT\n", __func__,
Expand Down
3 changes: 2 additions & 1 deletion lib/src/mt_cni.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ static int cni_rx_handle(struct mt_cni_entry* cni, struct rte_mbuf* m) {
/* vlan check */
ether_type = ntohs(eth_hdr->ether_type);
if (ether_type == RTE_ETHER_TYPE_VLAN) {
vlan_header = (struct rte_vlan_hdr*)((void*)&eth_hdr->ether_type + 2);
vlan_header =
(struct rte_vlan_hdr*)((uint8_t*)eth_hdr + sizeof(struct rte_ether_hdr));
ether_type = ntohs(vlan_header->eth_proto);
vlan = true;
hdr_offset += sizeof(struct rte_vlan_hdr);
Expand Down
5 changes: 3 additions & 2 deletions lib/src/mt_mcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,13 +564,14 @@ int mt_mcast_join(struct mtl_main_impl* impl, uint32_t group_addr, uint32_t sour

if (mt_drv_mcast_in_dp(impl, port)) return 0;

mt_pthread_mutex_lock(&mcast->group_mutex);

if (mcast->group_num >= MT_MCAST_GROUP_MAX) {
mt_pthread_mutex_unlock(&mcast->group_mutex);
err("%s(%d), reach max multicast group number!\n", __func__, port);
return -EIO;
}

mt_pthread_mutex_lock(&mcast->group_mutex);

/* find existing group */
bool found = false;
struct mt_mcast_group_entry* group;
Expand Down
7 changes: 4 additions & 3 deletions lib/src/st2110/st_tx_video_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ static int tv_build_st20(struct st_tx_video_session_impl* s, struct rte_mbuf* pk
if (e_rtp)
payload = &e_rtp[1];
else
payload = &rtp[1];
payload = (void*)((uint8_t*)rtp + sizeof(*rtp));
if (e_rtp && s->st20_linesize > s->st20_bytes_in_line) {
/* cross lines with padding case */
mtl_memcpy(payload, frame_info->addr + offset, line1_length);
Expand Down Expand Up @@ -3090,12 +3090,13 @@ static int tv_attach(struct mtl_main_impl* impl, struct st_tx_video_sessions_mgr
s->st22_box_hdr_length = sizeof(struct st22_boxes);
s->st22_codestream_size = st22_frame_ops->framebuff_max_size;
s->st20_frame_size = s->st22_codestream_size + s->st22_box_hdr_length;
s->st20_fb_size = s->st20_frame_size;
info("%s(%d), st22 max codestream size %" PRId64 ", box len %u\n", __func__, idx,
s->st22_codestream_size, s->st22_box_hdr_length);
} else {
s->st20_frame_size = ops->width * height * s->st20_pg.size / s->st20_pg.coverage;
s->st20_fb_size = s->st20_linesize * height;
}
s->st20_fb_size = s->st20_frame_size;
s->st20_frames_cnt = ops->framebuff_cnt;

ret = tv_init_pkt(impl, s, ops, st22_frame_ops);
Expand Down Expand Up @@ -3946,7 +3947,7 @@ int st20_frame_tx_start(struct mtl_main_impl* impl, struct st_tx_video_session_i
mt_mbuf_init_ipv4(pkt);

/* copy user meta */
void* payload = &rtp[1];
void* payload = (uint8_t*)rtp + sizeof(struct st20_rfc4175_rtp_hdr);
mtl_memcpy(payload, frame->user_meta, frame->user_meta_data_size);

pkt->data_len = sizeof(struct st_rfc4175_video_hdr) + frame->user_meta_data_size;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/udp/udp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static int udp_build_tx_pkt(struct mtl_main_impl* impl, struct mudp_impl* s,
pkt->pkt_len = pkt->data_len;

/* copy payload */
void* payload = &udp[1];
void* payload = (uint8_t*)udp + sizeof(struct rte_udp_hdr);
mtl_memcpy(payload, buf, len);

udp->dgram_len = htons(pkt->pkt_len - pkt->l2_len - pkt->l3_len);
Expand Down

0 comments on commit e217e63

Please sign in to comment.