layer2: check return values when adding empty packets

This commit is contained in:
Simon Ruderich 2024-07-23 09:31:17 +02:00
parent 4e2815923c
commit 52f45cb433

View file

@ -96,10 +96,6 @@ result_t layer2_tx_fill_packet_queue(layer2_tx_t *ctx)
result_t layer2_tx_add_empty_packet(layer2_tx_t *ctx, bool tx_request)
{
if(packet_queue_get_free_space(&ctx->packet_queue) == 0) {
return ERR_NO_MEM;
}
layer2_packet_header_t header;
header.dst_addr.addr[0] = 0xFFFF;
@ -111,7 +107,9 @@ result_t layer2_tx_add_empty_packet(layer2_tx_t *ctx, bool tx_request)
header.tx_seq_nr = 0; // not used in empty packets
header.tx_request = tx_request;
packet_queue_add(&ctx->packet_queue, &header, NULL, 0);
if (!packet_queue_add(&ctx->packet_queue, &header, NULL, 0)) {
return ERR_NO_MEM;
}
return OK;
}
@ -188,7 +186,10 @@ void layer2_tx_handle_ack(layer2_tx_t *ctx, uint8_t acked_seq)
if(packets_available == 0) {
// no packets left in queue, but an acknowledgement must be
// transmitted. Add an empty packet to do that.
layer2_tx_add_empty_packet(ctx, false);
result_t res = layer2_tx_add_empty_packet(ctx, false);
if (res != OK) {
LOG(LVL_WARN, "Failed to add empty packet: %d.", res);
}
}
}