Skip to content

Commit 2ebf82c

Browse files
rruuaanngfabiobaltieri
authored andcommitted
subsystem: usb: device_next: Fix unchecked return value in usbd_cdc_ecm
Fix unchecked return value scanned by Coverity. Signed-off-by: James Roy <[email protected]>
1 parent 00e217d commit 2ebf82c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

subsys/usb/device_next/class/usbd_cdc_ecm.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ static int cdc_ecm_send(const struct device *dev, struct net_pkt *const pkt)
492492
struct usbd_class_data *c_data = data->c_data;
493493
size_t len = net_pkt_get_len(pkt);
494494
struct net_buf *buf;
495+
uint8_t ep;
496+
int ret;
495497

496498
if (len > NET_ETH_MAX_FRAME_SIZE) {
497499
LOG_WRN("Trying to send too large packet, drop");
@@ -504,7 +506,8 @@ static int cdc_ecm_send(const struct device *dev, struct net_pkt *const pkt)
504506
return -EACCES;
505507
}
506508

507-
buf = cdc_ecm_buf_alloc(cdc_ecm_get_bulk_in(c_data));
509+
ep = cdc_ecm_get_bulk_in(c_data);
510+
buf = cdc_ecm_buf_alloc(ep);
508511
if (buf == NULL) {
509512
LOG_ERR("Failed to allocate buffer");
510513
return -ENOMEM;
@@ -523,7 +526,13 @@ static int cdc_ecm_send(const struct device *dev, struct net_pkt *const pkt)
523526
udc_ep_buf_set_zlp(buf);
524527
}
525528

526-
usbd_ep_enqueue(c_data, buf);
529+
ret = usbd_ep_enqueue(c_data, buf);
530+
if (ret) {
531+
LOG_ERR("Failed to enqueue net_buf for 0x%02x", ep);
532+
net_buf_unref(buf);
533+
return ret;
534+
}
535+
527536
k_sem_take(&data->sync_sem, K_FOREVER);
528537
net_buf_unref(buf);
529538

0 commit comments

Comments
 (0)