Skip to content

Commit 2b53acb

Browse files
Shawnshhwenlingz
authored andcommitted
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>
1 parent c5f4c51 commit 2b53acb

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

hypervisor/debug/logmsg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void do_logmsg(uint32_t severity, const char *fmt, ...)
174174
void print_logmsg_buffer(uint16_t pcpu_id)
175175
{
176176
char buffer[LOG_ENTRY_SIZE + 1];
177-
int read_cnt;
177+
uint32_t read_cnt;
178178
struct shared_buf **sbuf;
179179
int is_earlylog = 0;
180180
uint64_t rflags;
@@ -203,13 +203,13 @@ void print_logmsg_buffer(uint16_t pcpu_id)
203203
uint32_t idx;
204204
(void)memset(buffer, 0U, LOG_ENTRY_SIZE + 1U);
205205

206-
if (*sbuf == NULL) {
206+
if ((*sbuf == NULL) || (buffer == NULL)) {
207207
return;
208208
}
209209

210210
read_cnt = sbuf_get(*sbuf, (uint8_t *)buffer);
211211

212-
if (read_cnt <= 0) {
212+
if (read_cnt == 0U) {
213213
return;
214214
}
215215

@@ -220,5 +220,5 @@ void print_logmsg_buffer(uint16_t pcpu_id)
220220
spinlock_irqsave_obtain(&(logmsg.lock), &rflags);
221221
printf("%s\n\r", buffer);
222222
spinlock_irqrestore_release(&(logmsg.lock), rflags);
223-
} while (read_cnt > 0);
223+
} while (read_cnt > 0U);
224224
}

hypervisor/debug/sbuf.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,10 @@ void sbuf_free(struct shared_buf *sbuf)
8282
free(sbuf);
8383
}
8484

85-
int sbuf_get(struct shared_buf *sbuf, uint8_t *data)
85+
uint32_t sbuf_get(struct shared_buf *sbuf, uint8_t *data)
8686
{
8787
const void *from;
8888

89-
if ((sbuf == NULL) || (data == NULL)) {
90-
return -EINVAL;
91-
}
92-
9389
if (sbuf_is_empty(sbuf)) {
9490
/* no data available */
9591
return 0;
@@ -122,16 +118,12 @@ int sbuf_get(struct shared_buf *sbuf, uint8_t *data)
122118
* negative: failed.
123119
*/
124120

125-
int sbuf_put(struct shared_buf *sbuf, uint8_t *data)
121+
uint32_t sbuf_put(struct shared_buf *sbuf, uint8_t *data)
126122
{
127123
void *to;
128124
uint32_t next_tail;
129125
bool trigger_overwrite = false;
130126

131-
if ((sbuf == NULL) || (data == NULL)) {
132-
return -EINVAL;
133-
}
134-
135127
next_tail = sbuf_next_ptr(sbuf->tail, sbuf->ele_size, sbuf->size);
136128
/* if this write would trigger overrun */
137129
if (next_tail == sbuf->head) {

hypervisor/include/debug/sbuf.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,16 @@ static inline void sbuf_add_flags(struct shared_buf *sbuf, uint64_t flags)
7474

7575
struct shared_buf *sbuf_allocate(uint32_t ele_num, uint32_t ele_size);
7676
void sbuf_free(struct shared_buf *sbuf);
77-
int sbuf_get(struct shared_buf *sbuf, uint8_t *data);
78-
int sbuf_put(struct shared_buf *sbuf, uint8_t *data);
77+
/**
78+
*@pre sbuf != NULL
79+
*@pre data != NULL
80+
*/
81+
uint32_t sbuf_get(struct shared_buf *sbuf, uint8_t *data);
82+
/**
83+
*@pre sbuf != NULL
84+
*@pre data != NULL
85+
*/
86+
uint32_t sbuf_put(struct shared_buf *sbuf, uint8_t *data);
7987
int sbuf_share_setup(uint16_t pcpu_id, uint32_t sbuf_id, uint64_t *hva);
8088

8189
#else /* HV_DEBUG */

0 commit comments

Comments
 (0)