[Sound-open-firmware] [PATCH] comp: buffer: complain loudly if componenst try to under/over run buffers

Liam Girdwood liam.r.girdwood at linux.intel.com
Thu Aug 24 00:57:49 CEST 2017


Complain loudly in trace if we have components overruning or underruning
buffers. Components should check buffer free/avail before use.

Signed-off-by: Liam Girdwood <liam.r.girdwood at linux.intel.com>
---
 src/include/reef/audio/buffer.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/include/reef/audio/buffer.h b/src/include/reef/audio/buffer.h
index 55e9de1..9394d29 100644
--- a/src/include/reef/audio/buffer.h
+++ b/src/include/reef/audio/buffer.h
@@ -81,6 +81,14 @@ void buffer_free(struct comp_buffer *buffer);
 static inline void comp_update_buffer_produce(struct comp_buffer *buffer,
 	uint32_t bytes)
 {
+	/* complain loudly if component tries to overrun buffer
+	 * components MUST check for free space first !! */
+	if (bytes > buffer->free) {
+		trace_buffer_error("Xxo");
+		trace_value(buffer->ipc_buffer.comp.id);
+		return;
+	}
+
 	buffer->w_ptr += bytes;
 
 	/* check for pointer wrap */
@@ -107,6 +115,14 @@ static inline void comp_update_buffer_produce(struct comp_buffer *buffer,
 static inline void comp_update_buffer_consume(struct comp_buffer *buffer,
 	uint32_t bytes)
 {
+	/* complain loudly if component tries to underrun buffer
+	 * components MUST check for avail space first !! */
+	if (buffer->avail < bytes) {
+		trace_buffer_error("Xxu");
+		trace_value(buffer->ipc_buffer.comp.id);
+		return;
+	}
+
 	buffer->r_ptr += bytes;
 
 	/* check for pointer wrap */
-- 
2.11.0



More information about the Sound-open-firmware mailing list