From 2b53acb5f8466f19155f402e215cb2032a6762ca Mon Sep 17 00:00:00 2001 From: Huihuang Shi Date: Tue, 9 Oct 2018 15:21:35 +0800 Subject: [PATCH] HV:change the return type of sbuf_get and sbuf_put Because of the return type inconsistent,change the sbuf return type to uint32_t to fix it,and make the pre-condition to check the parameter whether is NULL. V1->V2: 1.add () to bool expression 2.add pre-assumption to sbuf_get and sbuf_put Tracked-On: #861 Signed-off-by: Huihuang Shi Acked-by: Eddie Dong --- hypervisor/debug/logmsg.c | 8 ++++---- hypervisor/debug/sbuf.c | 12 ++---------- hypervisor/include/debug/sbuf.h | 12 ++++++++++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/hypervisor/debug/logmsg.c b/hypervisor/debug/logmsg.c index aa51ef9ea..fe82c0323 100644 --- a/hypervisor/debug/logmsg.c +++ b/hypervisor/debug/logmsg.c @@ -174,7 +174,7 @@ void do_logmsg(uint32_t severity, const char *fmt, ...) void print_logmsg_buffer(uint16_t pcpu_id) { char buffer[LOG_ENTRY_SIZE + 1]; - int read_cnt; + uint32_t read_cnt; struct shared_buf **sbuf; int is_earlylog = 0; uint64_t rflags; @@ -203,13 +203,13 @@ void print_logmsg_buffer(uint16_t pcpu_id) uint32_t idx; (void)memset(buffer, 0U, LOG_ENTRY_SIZE + 1U); - if (*sbuf == NULL) { + if ((*sbuf == NULL) || (buffer == NULL)) { return; } read_cnt = sbuf_get(*sbuf, (uint8_t *)buffer); - if (read_cnt <= 0) { + if (read_cnt == 0U) { return; } @@ -220,5 +220,5 @@ void print_logmsg_buffer(uint16_t pcpu_id) spinlock_irqsave_obtain(&(logmsg.lock), &rflags); printf("%s\n\r", buffer); spinlock_irqrestore_release(&(logmsg.lock), rflags); - } while (read_cnt > 0); + } while (read_cnt > 0U); } diff --git a/hypervisor/debug/sbuf.c b/hypervisor/debug/sbuf.c index b33fc8f88..72e44789c 100644 --- a/hypervisor/debug/sbuf.c +++ b/hypervisor/debug/sbuf.c @@ -82,14 +82,10 @@ void sbuf_free(struct shared_buf *sbuf) free(sbuf); } -int sbuf_get(struct shared_buf *sbuf, uint8_t *data) +uint32_t sbuf_get(struct shared_buf *sbuf, uint8_t *data) { const void *from; - if ((sbuf == NULL) || (data == NULL)) { - return -EINVAL; - } - if (sbuf_is_empty(sbuf)) { /* no data available */ return 0; @@ -122,16 +118,12 @@ int sbuf_get(struct shared_buf *sbuf, uint8_t *data) * negative: failed. */ -int sbuf_put(struct shared_buf *sbuf, uint8_t *data) +uint32_t sbuf_put(struct shared_buf *sbuf, uint8_t *data) { void *to; uint32_t next_tail; bool trigger_overwrite = false; - if ((sbuf == NULL) || (data == NULL)) { - return -EINVAL; - } - next_tail = sbuf_next_ptr(sbuf->tail, sbuf->ele_size, sbuf->size); /* if this write would trigger overrun */ if (next_tail == sbuf->head) { diff --git a/hypervisor/include/debug/sbuf.h b/hypervisor/include/debug/sbuf.h index 64de4fcfd..99c5b3d0c 100644 --- a/hypervisor/include/debug/sbuf.h +++ b/hypervisor/include/debug/sbuf.h @@ -74,8 +74,16 @@ static inline void sbuf_add_flags(struct shared_buf *sbuf, uint64_t flags) struct shared_buf *sbuf_allocate(uint32_t ele_num, uint32_t ele_size); void sbuf_free(struct shared_buf *sbuf); -int sbuf_get(struct shared_buf *sbuf, uint8_t *data); -int sbuf_put(struct shared_buf *sbuf, uint8_t *data); +/** + *@pre sbuf != NULL + *@pre data != NULL + */ +uint32_t sbuf_get(struct shared_buf *sbuf, uint8_t *data); +/** + *@pre sbuf != NULL + *@pre data != NULL + */ +uint32_t sbuf_put(struct shared_buf *sbuf, uint8_t *data); int sbuf_share_setup(uint16_t pcpu_id, uint32_t sbuf_id, uint64_t *hva); #else /* HV_DEBUG */