File tree 1 file changed +12
-3
lines changed
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)
61
61
/* Insert a value into the kfifo buffer */
62
62
static void produce_data (unsigned char val )
63
63
{
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.
66
67
*/
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 ));
68
77
if (unlikely (len < sizeof (val )) && printk_ratelimit ())
69
78
pr_warn ("%s: %zu bytes dropped\n" , __func__ , sizeof (val ) - len );
70
79
You can’t perform that action at this time.
0 commit comments