From db7e7f1c4447cc1d08dd1f5d4d86f4251f9f985a Mon Sep 17 00:00:00 2001 From: Shuo A Liu Date: Tue, 18 Jun 2019 14:00:23 +0800 Subject: [PATCH] dm: platform: clean up assert() for some platform devices Tracked-On: #3252 Signed-off-by: Shuo A Liu Reviewed-by: Yonghua Huang --- devicemodel/hw/platform/atkbdc.c | 24 ++++++++++++++++-------- devicemodel/hw/platform/cmos_io.c | 6 ------ devicemodel/hw/platform/ps2kbd.c | 10 +++++----- devicemodel/hw/platform/ps2mouse.c | 13 +++++-------- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/devicemodel/hw/platform/atkbdc.c b/devicemodel/hw/platform/atkbdc.c index 8966b4b58..fe8d96d56 100644 --- a/devicemodel/hw/platform/atkbdc.c +++ b/devicemodel/hw/platform/atkbdc.c @@ -26,7 +26,6 @@ */ #include -#include #include #include #include @@ -43,6 +42,7 @@ #include "ps2mouse.h" #include "vmmapi.h" #include "mevent.h" +#include "log.h" static void atkbdc_assert_kbd_intr(struct atkbdc_base *base) @@ -291,7 +291,7 @@ atkbdc_sts_ctl_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, uint32_t *eax, void *arg) { struct atkbdc_base *base; - int error, retval; + int retval; if (bytes != 1) return -1; @@ -361,9 +361,8 @@ atkbdc_sts_ctl_handler(struct vmctx *ctx, int vcpu, int in, int port, KBDS_KBD_BUFFER_FULL; break; case KBDC_RESET: /* Pulse "cold reset" line */ - error = vm_suspend(ctx, VM_SUSPEND_FULL_RESET); + vm_suspend(ctx, VM_SUSPEND_FULL_RESET); mevent_notify(); - assert(error == 0 || errno == EALREADY); break; default: if (*eax >= 0x21 && *eax <= 0x3f) { @@ -415,8 +414,10 @@ atkbdc_init(struct vmctx *ctx) int error; base = calloc(1, sizeof(struct atkbdc_base)); - - assert(base != NULL); + if (!base) { + pr_err("%s: alloc memory fail!\n", __func__); + return; + } base->ctx = ctx; ctx->atkbdc_base = base; @@ -432,7 +433,8 @@ atkbdc_init(struct vmctx *ctx) iop.arg = base; error = register_inout(&iop); - assert(error == 0); + if (error < 0) + goto fail; bzero(&iop, sizeof(struct inout_port)); iop.name = "atkdbc"; @@ -443,7 +445,8 @@ atkbdc_init(struct vmctx *ctx) iop.arg = base; error = register_inout(&iop); - assert(error == 0); + if (error < 0) + goto fail; pci_irq_reserve(KBD_DEV_IRQ); base->kbd.irq = KBD_DEV_IRQ; @@ -453,6 +456,11 @@ atkbdc_init(struct vmctx *ctx) base->ps2kbd = ps2kbd_init(base); base->ps2mouse = ps2mouse_init(base); + + return; +fail: + pr_err("%s: fail to init!\n", __func__); + free(base); } void diff --git a/devicemodel/hw/platform/cmos_io.c b/devicemodel/hw/platform/cmos_io.c index 842406aaf..9054b3db7 100644 --- a/devicemodel/hw/platform/cmos_io.c +++ b/devicemodel/hw/platform/cmos_io.c @@ -28,7 +28,6 @@ */ #include -#include #include #include "inout.h" @@ -63,9 +62,6 @@ cmos_io_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, static int buf_offset; static int next_ops; /* 0 for addr, 1 for data, in pair (addr,data)*/ - assert(port == CMOS_ADDR || port == CMOS_DATA); - assert(bytes == 1); - #ifdef CMOS_DEBUG if (!dbg_file) dbg_file = fopen("/tmp/cmos_log", "a+"); @@ -77,7 +73,6 @@ cmos_io_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, if (port == CMOS_ADDR) { /* if port is addr, ops should be 0 */ - assert(next_ops == 0 && !in); if (next_ops != 0) { next_ops = 0; return -1; @@ -88,7 +83,6 @@ cmos_io_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, } else if (port == CMOS_DATA) { - assert(next_ops == 1); if (next_ops != 1) { next_ops = 0; return -1; diff --git a/devicemodel/hw/platform/ps2kbd.c b/devicemodel/hw/platform/ps2kbd.c index baf795be8..d02d72b93 100644 --- a/devicemodel/hw/platform/ps2kbd.c +++ b/devicemodel/hw/platform/ps2kbd.c @@ -25,7 +25,6 @@ * SUCH DAMAGE. */ -#include #include #include #include @@ -35,6 +34,7 @@ #include "types.h" #include "atkbdc.h" #include "console.h" +#include "log.h" /* keyboard device commands */ #define PS2KC_RESET_DEV 0xff @@ -225,8 +225,6 @@ ps2kbd_keysym_queue(struct ps2kbd_info *kbd, 0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x0e, 0x00, }; -/* assert(pthread_mutex_isowned_np(&kbd->mtx)); */ - switch (keysym) { case 0x0 ... 0x7f: if (!down) @@ -462,8 +460,10 @@ ps2kbd_init(struct atkbdc_base *base) struct ps2kbd_info *kbd; kbd = calloc(1, sizeof(struct ps2kbd_info)); - - assert(kbd != NULL); + if (!kbd) { + pr_err("%s: alloc memory fail!\n", __func__); + return NULL; + } pthread_mutex_init(&kbd->mtx, NULL); fifo_init(kbd); diff --git a/devicemodel/hw/platform/ps2mouse.c b/devicemodel/hw/platform/ps2mouse.c index b72a2c3c7..3cf5cf0c5 100644 --- a/devicemodel/hw/platform/ps2mouse.c +++ b/devicemodel/hw/platform/ps2mouse.c @@ -25,7 +25,6 @@ * SUCH DAMAGE. */ -#include #include #include #include @@ -35,6 +34,7 @@ #include "types.h" #include "atkbdc.h" #include "console.h" +#include "log.h" /* mouse device commands */ #define PS2MC_RESET_DEV 0xff @@ -152,8 +152,6 @@ fifo_get(struct ps2mouse_info *mouse, uint8_t *val) static void movement_reset(struct ps2mouse_info *mouse) { - /* assert(pthread_mutex_isowned_np(&mouse->mtx)); */ - mouse->delta_x = 0; mouse->delta_y = 0; } @@ -172,8 +170,6 @@ movement_get(struct ps2mouse_info *mouse) { uint8_t val0, val1, val2; -/* assert(pthread_mutex_isowned_np(&mouse->mtx)); */ - val0 = PS2M_DATA_AONE; val0 |= mouse->status & (PS2M_DATA_LEFT_BUTTON | PS2M_DATA_RIGHT_BUTTON | PS2M_DATA_MID_BUTTON); @@ -220,7 +216,6 @@ movement_get(struct ps2mouse_info *mouse) static void ps2mouse_reset(struct ps2mouse_info *mouse) { -/* assert(pthread_mutex_isowned_np(&mouse->mtx)); */ fifo_reset(mouse); movement_reset(mouse); mouse->status = PS2M_STS_ENABLE_DEV; @@ -395,8 +390,10 @@ ps2mouse_init(struct atkbdc_base *base) struct ps2mouse_info *mouse; mouse = calloc(1, sizeof(struct ps2mouse_info)); - - assert(mouse != NULL); + if (!mouse) { + pr_err("%s: alloc memory fail!\n", __func__); + return NULL; + } pthread_mutex_init(&mouse->mtx, NULL); fifo_init(mouse);