From f1697e2dd92ba9f32d06e4f5237589c902aa7e59 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 2 Mar 2016 10:28:54 +0100 Subject: [PATCH] card_emu: Only allocate a new buffer if needed in send_tpdu_header() --- firmware/src_simtrace/card_emu.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/firmware/src_simtrace/card_emu.c b/firmware/src_simtrace/card_emu.c index f45bc211..eea6fc45 100644 --- a/firmware/src_simtrace/card_emu.c +++ b/firmware/src_simtrace/card_emu.c @@ -580,14 +580,21 @@ static void send_tpdu_header(struct card_handle *ch) ch->tpdu.hdr[4]); /* if we already/still have a context, send it off */ - if (ch->uart_rx_ctx && ch->uart_rx_ctx->idx) { - flush_rx_buffer(ch); + if (ch->uart_rx_ctx) { + TRACE_DEBUG("have old buffer\r\n"); + if (ch->uart_rx_ctx->idx) { + TRACE_DEBUG("flushing old buffer\r\n"); + flush_rx_buffer(ch); + } + } else { + TRACE_DEBUG("allocating new buffer\r\n"); + /* ensure we have a new buffer */ + ch->uart_rx_ctx = req_ctx_find_get(0, RCTX_S_FREE, RCTX_S_UART_RX_BUSY); + if (!ch->uart_rx_ctx) { + TRACE_ERROR("%s: ENOMEM\r\n", __func__); + return; + } } - - /* ensure we have a new buffer */ - ch->uart_rx_ctx = req_ctx_find_get(0, RCTX_S_FREE, RCTX_S_UART_RX_BUSY); - if (!ch->uart_rx_ctx) - return; rctx = ch->uart_rx_ctx; rd = (struct cardemu_usb_msg_rx_data *) rctx->data;