mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-23 14:07:42 +00:00
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 <huihuang.shi@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
c5f4c5109c
commit
2b53acb5f8
@ -174,7 +174,7 @@ void do_logmsg(uint32_t severity, const char *fmt, ...)
|
|||||||
void print_logmsg_buffer(uint16_t pcpu_id)
|
void print_logmsg_buffer(uint16_t pcpu_id)
|
||||||
{
|
{
|
||||||
char buffer[LOG_ENTRY_SIZE + 1];
|
char buffer[LOG_ENTRY_SIZE + 1];
|
||||||
int read_cnt;
|
uint32_t read_cnt;
|
||||||
struct shared_buf **sbuf;
|
struct shared_buf **sbuf;
|
||||||
int is_earlylog = 0;
|
int is_earlylog = 0;
|
||||||
uint64_t rflags;
|
uint64_t rflags;
|
||||||
@ -203,13 +203,13 @@ void print_logmsg_buffer(uint16_t pcpu_id)
|
|||||||
uint32_t idx;
|
uint32_t idx;
|
||||||
(void)memset(buffer, 0U, LOG_ENTRY_SIZE + 1U);
|
(void)memset(buffer, 0U, LOG_ENTRY_SIZE + 1U);
|
||||||
|
|
||||||
if (*sbuf == NULL) {
|
if ((*sbuf == NULL) || (buffer == NULL)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_cnt = sbuf_get(*sbuf, (uint8_t *)buffer);
|
read_cnt = sbuf_get(*sbuf, (uint8_t *)buffer);
|
||||||
|
|
||||||
if (read_cnt <= 0) {
|
if (read_cnt == 0U) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,5 +220,5 @@ void print_logmsg_buffer(uint16_t pcpu_id)
|
|||||||
spinlock_irqsave_obtain(&(logmsg.lock), &rflags);
|
spinlock_irqsave_obtain(&(logmsg.lock), &rflags);
|
||||||
printf("%s\n\r", buffer);
|
printf("%s\n\r", buffer);
|
||||||
spinlock_irqrestore_release(&(logmsg.lock), rflags);
|
spinlock_irqrestore_release(&(logmsg.lock), rflags);
|
||||||
} while (read_cnt > 0);
|
} while (read_cnt > 0U);
|
||||||
}
|
}
|
||||||
|
@ -82,14 +82,10 @@ void sbuf_free(struct shared_buf *sbuf)
|
|||||||
free(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;
|
const void *from;
|
||||||
|
|
||||||
if ((sbuf == NULL) || (data == NULL)) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sbuf_is_empty(sbuf)) {
|
if (sbuf_is_empty(sbuf)) {
|
||||||
/* no data available */
|
/* no data available */
|
||||||
return 0;
|
return 0;
|
||||||
@ -122,16 +118,12 @@ int sbuf_get(struct shared_buf *sbuf, uint8_t *data)
|
|||||||
* negative: failed.
|
* 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;
|
void *to;
|
||||||
uint32_t next_tail;
|
uint32_t next_tail;
|
||||||
bool trigger_overwrite = false;
|
bool trigger_overwrite = false;
|
||||||
|
|
||||||
if ((sbuf == NULL) || (data == NULL)) {
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
next_tail = sbuf_next_ptr(sbuf->tail, sbuf->ele_size, sbuf->size);
|
next_tail = sbuf_next_ptr(sbuf->tail, sbuf->ele_size, sbuf->size);
|
||||||
/* if this write would trigger overrun */
|
/* if this write would trigger overrun */
|
||||||
if (next_tail == sbuf->head) {
|
if (next_tail == sbuf->head) {
|
||||||
|
@ -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);
|
struct shared_buf *sbuf_allocate(uint32_t ele_num, uint32_t ele_size);
|
||||||
void sbuf_free(struct shared_buf *sbuf);
|
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);
|
int sbuf_share_setup(uint16_t pcpu_id, uint32_t sbuf_id, uint64_t *hva);
|
||||||
|
|
||||||
#else /* HV_DEBUG */
|
#else /* HV_DEBUG */
|
||||||
|
Loading…
Reference in New Issue
Block a user