From 1718b1642ee8c31eb2c49d78b5834e06f3324394 Mon Sep 17 00:00:00 2001 From: Dong Du Date: Fri, 27 Aug 2021 22:46:28 +0800 Subject: lib: sbi: Checking fifo validness in sbi_fifo_is_empty and is_full As other exported fifo functions, we should check whether the fifo is valid in sbi_fifo_is_empty and sbi_fifo_is_full. To this end, this patch changes the retval from bool to int, and the two functions will return SBI_EINVAL in the case the fifo is invalid. Signed-off-by: Dong Du Reviewed-by: Atish Patra --- lib/sbi/sbi_fifo.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/sbi/sbi_fifo.c') diff --git a/lib/sbi/sbi_fifo.c b/lib/sbi/sbi_fifo.c index b2395f3..589cc18 100644 --- a/lib/sbi/sbi_fifo.c +++ b/lib/sbi/sbi_fifo.c @@ -43,10 +43,13 @@ u16 sbi_fifo_avail(struct sbi_fifo *fifo) return ret; } -bool sbi_fifo_is_full(struct sbi_fifo *fifo) +int sbi_fifo_is_full(struct sbi_fifo *fifo) { bool ret; + if (!fifo) + return SBI_EINVAL; + spin_lock(&fifo->qlock); ret = __sbi_fifo_is_full(fifo); spin_unlock(&fifo->qlock); @@ -75,10 +78,13 @@ static inline bool __sbi_fifo_is_empty(struct sbi_fifo *fifo) return (fifo->avail == 0) ? TRUE : FALSE; } -bool sbi_fifo_is_empty(struct sbi_fifo *fifo) +int sbi_fifo_is_empty(struct sbi_fifo *fifo) { bool ret; + if (!fifo) + return SBI_EINVAL; + spin_lock(&fifo->qlock); ret = __sbi_fifo_is_empty(fifo); spin_unlock(&fifo->qlock); -- cgit v1.2.3