From cc295f69454b1e7c0a6e383393025548f1d674db Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Wed, 16 Nov 2022 10:46:07 +0100 Subject: [PATCH] firmware/sniffer: Avoid extra call for rbuf_is_full rbuf_write() will tell us in the return value if the buffer was full (error) or not (success). Let's use that return value rather than a theoretically race-y call to rbuf_is_full() before. It's theoretical as the write happens from IRQ context and the read from normal process context, so the fill-level cannot really change while we're in the USART interrupt. So it doesn't fix a bug, just improves coding style and also avoids an extra function call + irq-disable/re-enable. Change-Id: Icf570d0aa48d67a19e63c6e2b6caa14438fe88e3 --- firmware/libcommon/source/sniffer.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/firmware/libcommon/source/sniffer.c b/firmware/libcommon/source/sniffer.c index e3b7fbb3..cbfa7c9c 100644 --- a/firmware/libcommon/source/sniffer.c +++ b/firmware/libcommon/source/sniffer.c @@ -826,11 +826,8 @@ void Sniffer_usart_isr(void) /* Reset WT timer */ wt_remaining = wt; /* Store sniffed data into buffer (also clear interrupt */ - if (rbuf_is_full(&sniff_buffer)) { + if (rbuf_write(&sniff_buffer, byte) != 0) TRACE_ERROR("USART buffer full\n\r"); - } else { - rbuf_write(&sniff_buffer, byte); - } } /* Verify it WT timeout occurred, to detect unresponsive card */