File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -61,10 +61,19 @@ static inline int update_simrupt_data(void)
6161/* Insert a value into the kfifo buffer */
6262static void produce_data (unsigned char val )
6363{
64- /* Implement a kind of circular FIFO here (skip oldest element if kfifo
65- * buffer is full).
64+ /* Implement overwrite-on-full FIFO behavior:
65+ * If the kfifo buffer is full, remove the oldest element
66+ * before inserting the new one.
6667 */
67- unsigned int len = kfifo_in (& rx_fifo , & val , sizeof (val ));
68+ unsigned int len ;
69+ if (kfifo_avail (& rx_fifo ) < sizeof (val )) {
70+ unsigned char dummy ;
71+ len = kfifo_out (& rx_fifo , & dummy , sizeof (dummy ));
72+ if (len != sizeof (dummy ))
73+ pr_warn ("Failed to remove the oldest element (%u bytes)\n" , len );
74+ }
75+
76+ len = kfifo_in (& rx_fifo , & val , sizeof (val ));
6877 if (unlikely (len < sizeof (val )) && printk_ratelimit ())
6978 pr_warn ("%s: %zu bytes dropped\n" , __func__ , sizeof (val ) - len );
7079
You can’t perform that action at this time.
0 commit comments