mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-09-20 15:21:42 +01:00
lib: sbi_fifo: add TSA annotations
Add Thread Safety Analysis (TSA) annotations for the FIFO implementation. This consists of indicating which fields are protected by a spinlock and annotating functionst that must be called under a spinlock. sbi_fifo_init() must be excluded, as acquiring a spinlock before it is initialized does not make sense. Signed-off-by: Carlos López <carlos.lopezr4096@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20260909162322.29778-5-carlos.lopezr4096@gmail.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
@@ -15,12 +15,12 @@
|
|||||||
#include <sbi/sbi_types.h>
|
#include <sbi/sbi_types.h>
|
||||||
|
|
||||||
struct sbi_fifo {
|
struct sbi_fifo {
|
||||||
void *queue;
|
|
||||||
spinlock_t qlock;
|
spinlock_t qlock;
|
||||||
|
void *queue PT_GUARDED_BY(&qlock);
|
||||||
u16 entry_size;
|
u16 entry_size;
|
||||||
u16 num_entries;
|
u16 num_entries;
|
||||||
u16 avail;
|
u16 avail GUARDED_BY(&qlock);
|
||||||
u16 tail;
|
u16 tail GUARDED_BY(&qlock);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SBI_FIFO_INITIALIZER(__queue_mem, __entries, __entry_size) \
|
#define SBI_FIFO_INITIALIZER(__queue_mem, __entries, __entry_size) \
|
||||||
|
|||||||
+8
-3
@@ -13,7 +13,7 @@
|
|||||||
#include <sbi/sbi_string.h>
|
#include <sbi/sbi_string.h>
|
||||||
|
|
||||||
void sbi_fifo_init(struct sbi_fifo *fifo, void *queue_mem, u16 entries,
|
void sbi_fifo_init(struct sbi_fifo *fifo, void *queue_mem, u16 entries,
|
||||||
u16 entry_size)
|
u16 entry_size) NO_THREAD_SAFETY_ANALYSIS
|
||||||
{
|
{
|
||||||
fifo->queue = queue_mem;
|
fifo->queue = queue_mem;
|
||||||
fifo->num_entries = entries;
|
fifo->num_entries = entries;
|
||||||
@@ -25,6 +25,7 @@ void sbi_fifo_init(struct sbi_fifo *fifo, void *queue_mem, u16 entries,
|
|||||||
|
|
||||||
/* Note: must be called with fifo->qlock held */
|
/* Note: must be called with fifo->qlock held */
|
||||||
static inline bool __sbi_fifo_is_full(struct sbi_fifo *fifo)
|
static inline bool __sbi_fifo_is_full(struct sbi_fifo *fifo)
|
||||||
|
MUST_HOLD(&fifo->qlock)
|
||||||
{
|
{
|
||||||
return (fifo->avail == fifo->num_entries) ? true : false;
|
return (fifo->avail == fifo->num_entries) ? true : false;
|
||||||
}
|
}
|
||||||
@@ -58,7 +59,8 @@ int sbi_fifo_is_full(struct sbi_fifo *fifo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Note: must be called with fifo->qlock held */
|
/* Note: must be called with fifo->qlock held */
|
||||||
static inline void __sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data)
|
static inline void __sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data)
|
||||||
|
MUST_HOLD(&fifo->qlock)
|
||||||
{
|
{
|
||||||
u32 head;
|
u32 head;
|
||||||
|
|
||||||
@@ -91,7 +93,8 @@ static inline void __sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Note: must be called with fifo->qlock held */
|
/* Note: must be called with fifo->qlock held */
|
||||||
static inline void __sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data)
|
static inline void __sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data)
|
||||||
|
MUST_HOLD(&fifo->qlock)
|
||||||
{
|
{
|
||||||
if (!data)
|
if (!data)
|
||||||
goto skip_data_copy;
|
goto skip_data_copy;
|
||||||
@@ -126,6 +129,7 @@ skip_data_copy:
|
|||||||
|
|
||||||
/* Note: must be called with fifo->qlock held */
|
/* Note: must be called with fifo->qlock held */
|
||||||
static inline bool __sbi_fifo_is_empty(struct sbi_fifo *fifo)
|
static inline bool __sbi_fifo_is_empty(struct sbi_fifo *fifo)
|
||||||
|
MUST_HOLD(&fifo->qlock)
|
||||||
{
|
{
|
||||||
return (fifo->avail == 0) ? true : false;
|
return (fifo->avail == 0) ? true : false;
|
||||||
}
|
}
|
||||||
@@ -146,6 +150,7 @@ int sbi_fifo_is_empty(struct sbi_fifo *fifo)
|
|||||||
|
|
||||||
/* Note: must be called with fifo->qlock held */
|
/* Note: must be called with fifo->qlock held */
|
||||||
static inline void __sbi_fifo_reset(struct sbi_fifo *fifo)
|
static inline void __sbi_fifo_reset(struct sbi_fifo *fifo)
|
||||||
|
MUST_HOLD(&fifo->qlock)
|
||||||
{
|
{
|
||||||
size_t size = (size_t)fifo->num_entries * fifo->entry_size;
|
size_t size = (size_t)fifo->num_entries * fifo->entry_size;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user