Skip to content

Commit e2f9e42

Browse files
committed
drivers: ethernet: adin2111: Fix a bug in offload thread in OA mode
Fixes a bug where eth_adin2111_oa_data_read returning error (for example when the is not enough RX buffers available) would exit the thread and cause RTOS crash as the thread is set up as essential. Signed-off-by: Maciej Panek <[email protected]>
1 parent 1540bd7 commit e2f9e42

File tree

1 file changed

+21
-33
lines changed

1 file changed

+21
-33
lines changed

drivers/ethernet/eth_adin2111.c

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ int eth_adin2111_oa_data_read(const struct device *dev, const uint16_t port_idx)
317317
K_MSEC(CONFIG_ETH_ADIN2111_TIMEOUT));
318318
if (!pkt) {
319319
LOG_ERR("OA RX: cannot allcate packet space, skipping.");
320-
return -EIO;
320+
return -ENOMEM;
321321
}
322322
/* Skipping CRC32 */
323323
ret = net_pkt_write(pkt, ctx->buf, ctx->scur - sizeof(uint32_t));
@@ -698,51 +698,39 @@ static void adin2111_offload_thread(void *p1, void *p2, void *p3)
698698
adin2111_port_on_phyint(ctx->port[1]);
699699
}
700700

701-
if (ctx->oa) {
701+
/* handle rx interrupt(s) */
702+
do {
703+
/* handle port 1 rx */
702704
if (status1 & ADIN2111_STATUS1_P1_RX_RDY) {
703-
ret = eth_adin2111_oa_data_read(dev, 0);
704-
if (ret < 0) {
705-
break;
706-
}
707-
}
708-
if (status1 & ADIN2111_STATUS1_P2_RX_RDY) {
709-
ret = eth_adin2111_oa_data_read(dev, 1);
710-
if (ret < 0) {
711-
break;
705+
if (ctx->oa) {
706+
ret = eth_adin2111_oa_data_read(dev, 0);
707+
} else {
708+
ret = adin2111_read_fifo(dev, 0U);
712709
}
713-
}
714-
goto continue_unlock;
715-
}
716710

717-
/* handle port 1 rx */
718-
if (status1 & ADIN2111_STATUS1_P1_RX_RDY) {
719-
do {
720-
ret = adin2111_read_fifo(dev, 0U);
721711
if (ret < 0) {
722712
break;
723713
}
714+
}
724715

725-
ret = eth_adin2111_reg_read(dev, ADIN2111_STATUS1, &status1);
726-
if (ret < 0) {
727-
goto continue_unlock;
716+
/* handle port 2 rx */
717+
if ((status1 & ADIN2111_STATUS1_P2_RX_RDY) && is_adin2111) {
718+
if (ctx->oa) {
719+
ret = eth_adin2111_oa_data_read(dev, 1);
720+
} else {
721+
ret = adin2111_read_fifo(dev, 1U);
728722
}
729-
} while (!!(status1 & ADIN2111_STATUS1_P1_RX_RDY));
730-
}
731723

732-
/* handle port 2 rx */
733-
if ((status1 & ADIN2111_STATUS1_P2_RX_RDY) && is_adin2111) {
734-
do {
735-
ret = adin2111_read_fifo(dev, 1U);
736724
if (ret < 0) {
737725
break;
738726
}
727+
}
739728

740-
ret = eth_adin2111_reg_read(dev, ADIN2111_STATUS1, &status1);
741-
if (ret < 0) {
742-
goto continue_unlock;
743-
}
744-
} while (!!(status1 & ADIN2111_STATUS1_P2_RX_RDY));
745-
}
729+
ret = eth_adin2111_reg_read(dev, ADIN2111_STATUS1, &status1);
730+
if (ret < 0) {
731+
goto continue_unlock;
732+
}
733+
} while (status1 & (ADIN2111_STATUS1_P1_RX_RDY | ADIN2111_STATUS1_P2_RX_RDY));
746734

747735
continue_unlock:
748736
/* clear interrupts */

0 commit comments

Comments
 (0)