mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-03 09:23:35 +00:00
HV: vuart: MISRA clean in vuart.c
1. remove multiple return 2. remove goto 3. fix potential NULL pointer dereferencing 4. rename struct fifo to struct vuart_fifo to avoid naming conflicts. Tracked-On: #2987 Signed-off-by: Conghui Chen <conghui.chen@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
c61db6ffa0
commit
a4b5e39fab
@ -43,14 +43,14 @@ static uint16_t vuart_com_base = CONFIG_COM_BASE;
|
||||
#define vuart_lock(vu) spinlock_obtain(&((vu)->lock))
|
||||
#define vuart_unlock(vu) spinlock_release(&((vu)->lock))
|
||||
|
||||
static inline void fifo_reset(struct fifo *fifo)
|
||||
static inline void fifo_reset(struct vuart_fifo *fifo)
|
||||
{
|
||||
fifo->rindex = 0U;
|
||||
fifo->windex = 0U;
|
||||
fifo->num = 0U;
|
||||
}
|
||||
|
||||
static inline void fifo_putchar(struct fifo *fifo, char ch)
|
||||
static inline void fifo_putchar(struct vuart_fifo *fifo, char ch)
|
||||
{
|
||||
fifo->buf[fifo->windex] = ch;
|
||||
if (fifo->num < fifo->size) {
|
||||
@ -62,21 +62,19 @@ static inline void fifo_putchar(struct fifo *fifo, char ch)
|
||||
}
|
||||
}
|
||||
|
||||
static inline char fifo_getchar(struct fifo *fifo)
|
||||
static inline char fifo_getchar(struct vuart_fifo *fifo)
|
||||
{
|
||||
char c;
|
||||
char c = -1;
|
||||
|
||||
if (fifo->num > 0U) {
|
||||
c = fifo->buf[fifo->rindex];
|
||||
fifo->rindex = (fifo->rindex + 1U) % fifo->size;
|
||||
fifo->num--;
|
||||
return c;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline uint32_t fifo_numchars(const struct fifo *fifo)
|
||||
static inline uint32_t fifo_numchars(const struct vuart_fifo *fifo)
|
||||
{
|
||||
return fifo->num;
|
||||
}
|
||||
@ -117,15 +115,16 @@ static inline void vuart_fifo_init(struct acrn_vuart *vu)
|
||||
*/
|
||||
static uint8_t vuart_intr_reason(const struct acrn_vuart *vu)
|
||||
{
|
||||
uint8_t ret = IIR_NOPEND;
|
||||
|
||||
if (((vu->lsr & LSR_OE) != 0U) && ((vu->ier & IER_ELSI) != 0U)) {
|
||||
return IIR_RLS;
|
||||
ret = IIR_RLS;
|
||||
} else if ((fifo_numchars(&vu->rxfifo) > 0U) && ((vu->ier & IER_ERBFI) != 0U)) {
|
||||
return IIR_RXTOUT;
|
||||
ret = IIR_RXTOUT;
|
||||
} else if (vu->thre_int_pending && ((vu->ier & IER_ETBEI) != 0U)) {
|
||||
return IIR_TXRDY;
|
||||
} else {
|
||||
return IIR_NOPEND;
|
||||
ret = IIR_TXRDY;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct acrn_vuart *find_vuart_by_port(struct acrn_vm *vm, uint16_t offset)
|
||||
@ -194,29 +193,21 @@ static bool vuart_write(struct acrn_vm *vm, uint16_t offset_arg,
|
||||
uint8_t value_u8 = (uint8_t)value;
|
||||
struct acrn_vuart *target_vu = NULL;
|
||||
|
||||
if (vu) {
|
||||
offset -= vu->port_base;
|
||||
target_vu = vu->target_vu;
|
||||
if ((offset == UART16550_THR) && target_vu) {
|
||||
vuart_write_to_target(target_vu, value_u8);
|
||||
return true;
|
||||
}
|
||||
|
||||
} else {
|
||||
vuart_lock(vu);
|
||||
/*
|
||||
* Take care of the special case DLAB accesses first
|
||||
*/
|
||||
if ((vu->lcr & LCR_DLAB) != 0U) {
|
||||
if (offset == UART16550_DLL) {
|
||||
if ((vu->lcr & LCR_DLAB) != 0U && offset == UART16550_DLL) {
|
||||
vu->dll = value_u8;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (offset == UART16550_DLM) {
|
||||
} else if ((vu->lcr & LCR_DLAB) != 0U && offset == UART16550_DLM) {
|
||||
vu->dlh = value_u8;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
switch (offset) {
|
||||
case UART16550_THR:
|
||||
fifo_putchar(&vu->txfifo, (char)value_u8);
|
||||
@ -272,11 +263,12 @@ static bool vuart_write(struct acrn_vm *vm, uint16_t offset_arg,
|
||||
*/
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
vuart_toggle_intr(vu);
|
||||
vuart_unlock(vu);
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -288,6 +280,7 @@ static bool vuart_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t offs
|
||||
struct acrn_vuart *vu = find_vuart_by_port(vm, offset);
|
||||
struct pio_request *pio_req = &vcpu->req.reqs.pio;
|
||||
|
||||
if (vu) {
|
||||
offset -= vu->port_base;
|
||||
vuart_lock(vu);
|
||||
/*
|
||||
@ -296,14 +289,12 @@ static bool vuart_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t offs
|
||||
if ((vu->lcr & LCR_DLAB) != 0U) {
|
||||
if (offset == UART16550_DLL) {
|
||||
reg = vu->dll;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (offset == UART16550_DLM) {
|
||||
} else if (offset == UART16550_DLM) {
|
||||
reg = vu->dlh;
|
||||
goto done;
|
||||
}
|
||||
} else {
|
||||
reg = 0U;
|
||||
}
|
||||
} else {
|
||||
switch (offset) {
|
||||
case UART16550_RBR:
|
||||
vu->lsr &= ~LSR_OE;
|
||||
@ -354,10 +345,11 @@ static bool vuart_read(struct acrn_vm *vm, struct acrn_vcpu *vcpu, uint16_t offs
|
||||
reg = 0xFFU;
|
||||
break;
|
||||
}
|
||||
done:
|
||||
}
|
||||
vuart_toggle_intr(vu);
|
||||
pio_req->value = (uint32_t)reg;
|
||||
vuart_unlock(vu);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@
|
||||
#define COM3_IRQ 6U
|
||||
#define COM4_IRQ 7U
|
||||
|
||||
struct fifo {
|
||||
struct vuart_fifo {
|
||||
char *buf;
|
||||
uint32_t rindex; /* index to read from */
|
||||
uint32_t windex; /* index to write to */
|
||||
|
Loading…
Reference in New Issue
Block a user