dm: refine assert usage

Remove unnecessary assert and add error handling when required.

Tracked-On: #3252
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
This commit is contained in:
Jian Jun Chen 2019-06-18 13:38:37 +08:00 committed by ACRN System Integration
parent 0a8bf6cee4
commit 56469f3edc
4 changed files with 26 additions and 33 deletions

View File

@ -30,7 +30,6 @@
* Micro event library for FreeBSD, designed for a single i/o thread
* using EPOLL, and having events be persistent by default.
*/
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
@ -377,7 +376,6 @@ int
mevent_init(void)
{
epoll_fd = epoll_create1(0);
assert(epoll_fd >= 0);
if (epoll_fd >= 0)
return 0;
@ -420,7 +418,10 @@ mevent_dispatch(void)
* Add internal event handler for the pipe write fd
*/
pipev = mevent_add(mevent_pipefd[0], EVF_READ, mevent_pipe_read, NULL, NULL, NULL);
assert(pipev != NULL);
if (!pipev) {
fprintf(stderr, "pipefd mevent_add failed\n");
exit(0);
}
for (;;) {
int suspend_mode;

View File

@ -60,22 +60,18 @@ static void
pci_uart_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
int baridx, uint64_t offset, int size, uint64_t value)
{
assert(baridx == 0);
assert(size == 1);
uart_write(dev->arg, offset, value);
if (baridx == 0 && size == 1)
uart_write(dev->arg, offset, value);
}
uint64_t
pci_uart_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
int baridx, uint64_t offset, int size)
{
uint8_t val;
uint8_t val = 0xff;
assert(baridx == 0);
assert(size == 1);
val = uart_read(dev->arg, offset);
if (baridx == 0 && size == 1)
val = uart_read(dev->arg, offset);
return val;
}

View File

@ -39,7 +39,6 @@
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <pthread.h>
#include <termios.h>
#include <limits.h>
@ -272,15 +271,13 @@ virtio_console_add_port(struct virtio_console *console, const char *name,
static void
virtio_console_control_tx(struct virtio_console_port *port, void *arg,
struct iovec *iov, int niov)
struct iovec *iov, int niov __attribute__((unused)))
{
struct virtio_console *console;
struct virtio_console_port *tmp;
struct virtio_console_control resp, *ctrl;
int i;
assert(niov == 1);
console = port->console;
ctrl = (struct virtio_console_control *)iov->iov_base;
@ -363,8 +360,10 @@ virtio_console_control_send(struct virtio_console *console,
return;
n = vq_getchain(vq, &idx, &iov, 1, NULL);
assert(n == 1);
if (n < 1) {
WPRINTF(("vtcon: control_send vq_getchain error %d\n", n));
return;
}
memcpy(iov.iov_base, ctrl, sizeof(struct virtio_console_control));
if (payload != NULL && len > 0)

View File

@ -29,7 +29,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fcntl.h>
#include <termios.h>
#include <unistd.h>
@ -167,7 +166,9 @@ rxfifo_reset(struct uart_vdev *uart, int size)
{
struct fifo *fifo;
assert(size <= uart->rxfifo_size);
if (size > uart->rxfifo_size)
size = uart->rxfifo_size;
fifo = &uart->rxfifo;
fifo->rindex = 0;
fifo->windex = 0;
@ -301,7 +302,6 @@ modem_status(uint8_t mcr)
*/
msr = MSR_DCD | MSR_DSR;
}
assert((msr & MSR_DELTA_MASK) == 0);
return msr;
}
@ -373,8 +373,6 @@ uart_drain(int fd, enum ev_type ev, void *arg)
uart = arg;
assert(ev == EVF_READ);
/*
* This routine is called in the context of the mevent thread
* to take out the uart lock to protect against concurrent
@ -632,18 +630,17 @@ uart_init(uart_intr_func_t intr_assert, uart_intr_func_t intr_deassert,
struct uart_vdev *uart;
uart = calloc(1, sizeof(struct uart_vdev) + rxfifo_size);
if (uart) {
uart->arg = arg;
uart->rxfifo_size = rxfifo_size;
uart->intr_assert = intr_assert;
uart->intr_deassert = intr_deassert;
uart->rxfifo.buf = (uint8_t *)(uart + 1);
assert(uart != NULL);
pthread_mutex_init(&uart->mtx, NULL);
uart->arg = arg;
uart->rxfifo_size = rxfifo_size;
uart->intr_assert = intr_assert;
uart->intr_deassert = intr_deassert;
uart->rxfifo.buf = (uint8_t *)(uart + 1);
pthread_mutex_init(&uart->mtx, NULL);
uart_reset(uart);
uart_reset(uart);
}
return uart;
}