Skip to content

Commit db7e7f1

Browse files
Shuo A Liuwenlingz
authored andcommitted
dm: platform: clean up assert() for some platform devices
Tracked-On: #3252 Signed-off-by: Shuo A Liu <shuo.a.liu@intel.com> Reviewed-by: Yonghua Huang <yonghua.huang@intel.com>
1 parent 1b79953 commit db7e7f1

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

devicemodel/hw/platform/atkbdc.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
*/
2727

2828
#include <stdint.h>
29-
#include <assert.h>
3029
#include <errno.h>
3130
#include <stdbool.h>
3231
#include <stdlib.h>
@@ -43,6 +42,7 @@
4342
#include "ps2mouse.h"
4443
#include "vmmapi.h"
4544
#include "mevent.h"
45+
#include "log.h"
4646

4747
static void
4848
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,
291291
int bytes, uint32_t *eax, void *arg)
292292
{
293293
struct atkbdc_base *base;
294-
int error, retval;
294+
int retval;
295295

296296
if (bytes != 1)
297297
return -1;
@@ -361,9 +361,8 @@ atkbdc_sts_ctl_handler(struct vmctx *ctx, int vcpu, int in, int port,
361361
KBDS_KBD_BUFFER_FULL;
362362
break;
363363
case KBDC_RESET: /* Pulse "cold reset" line */
364-
error = vm_suspend(ctx, VM_SUSPEND_FULL_RESET);
364+
vm_suspend(ctx, VM_SUSPEND_FULL_RESET);
365365
mevent_notify();
366-
assert(error == 0 || errno == EALREADY);
367366
break;
368367
default:
369368
if (*eax >= 0x21 && *eax <= 0x3f) {
@@ -415,8 +414,10 @@ atkbdc_init(struct vmctx *ctx)
415414
int error;
416415

417416
base = calloc(1, sizeof(struct atkbdc_base));
418-
419-
assert(base != NULL);
417+
if (!base) {
418+
pr_err("%s: alloc memory fail!\n", __func__);
419+
return;
420+
}
420421

421422
base->ctx = ctx;
422423
ctx->atkbdc_base = base;
@@ -432,7 +433,8 @@ atkbdc_init(struct vmctx *ctx)
432433
iop.arg = base;
433434

434435
error = register_inout(&iop);
435-
assert(error == 0);
436+
if (error < 0)
437+
goto fail;
436438

437439
bzero(&iop, sizeof(struct inout_port));
438440
iop.name = "atkdbc";
@@ -443,7 +445,8 @@ atkbdc_init(struct vmctx *ctx)
443445
iop.arg = base;
444446

445447
error = register_inout(&iop);
446-
assert(error == 0);
448+
if (error < 0)
449+
goto fail;
447450

448451
pci_irq_reserve(KBD_DEV_IRQ);
449452
base->kbd.irq = KBD_DEV_IRQ;
@@ -453,6 +456,11 @@ atkbdc_init(struct vmctx *ctx)
453456

454457
base->ps2kbd = ps2kbd_init(base);
455458
base->ps2mouse = ps2mouse_init(base);
459+
460+
return;
461+
fail:
462+
pr_err("%s: fail to init!\n", __func__);
463+
free(base);
456464
}
457465

458466
void

devicemodel/hw/platform/cmos_io.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
*/
2929

3030
#include <stdio.h>
31-
#include <assert.h>
3231
#include <stdbool.h>
3332

3433
#include "inout.h"
@@ -63,9 +62,6 @@ cmos_io_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
6362
static int buf_offset;
6463
static int next_ops; /* 0 for addr, 1 for data, in pair (addr,data)*/
6564

66-
assert(port == CMOS_ADDR || port == CMOS_DATA);
67-
assert(bytes == 1);
68-
6965
#ifdef CMOS_DEBUG
7066
if (!dbg_file)
7167
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,
7773
if (port == CMOS_ADDR) {
7874

7975
/* if port is addr, ops should be 0 */
80-
assert(next_ops == 0 && !in);
8176
if (next_ops != 0) {
8277
next_ops = 0;
8378
return -1;
@@ -88,7 +83,6 @@ cmos_io_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
8883

8984
} else if (port == CMOS_DATA) {
9085

91-
assert(next_ops == 1);
9286
if (next_ops != 1) {
9387
next_ops = 0;
9488
return -1;

devicemodel/hw/platform/ps2kbd.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
* SUCH DAMAGE.
2626
*/
2727

28-
#include <assert.h>
2928
#include <stdbool.h>
3029
#include <stdio.h>
3130
#include <stdlib.h>
@@ -35,6 +34,7 @@
3534
#include "types.h"
3635
#include "atkbdc.h"
3736
#include "console.h"
37+
#include "log.h"
3838

3939
/* keyboard device commands */
4040
#define PS2KC_RESET_DEV 0xff
@@ -225,8 +225,6 @@ ps2kbd_keysym_queue(struct ps2kbd_info *kbd,
225225
0x22, 0x35, 0x1a, 0x54, 0x5d, 0x5b, 0x0e, 0x00,
226226
};
227227

228-
/* assert(pthread_mutex_isowned_np(&kbd->mtx)); */
229-
230228
switch (keysym) {
231229
case 0x0 ... 0x7f:
232230
if (!down)
@@ -462,8 +460,10 @@ ps2kbd_init(struct atkbdc_base *base)
462460
struct ps2kbd_info *kbd;
463461

464462
kbd = calloc(1, sizeof(struct ps2kbd_info));
465-
466-
assert(kbd != NULL);
463+
if (!kbd) {
464+
pr_err("%s: alloc memory fail!\n", __func__);
465+
return NULL;
466+
}
467467

468468
pthread_mutex_init(&kbd->mtx, NULL);
469469
fifo_init(kbd);

devicemodel/hw/platform/ps2mouse.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
* SUCH DAMAGE.
2626
*/
2727

28-
#include <assert.h>
2928
#include <stdbool.h>
3029
#include <stdio.h>
3130
#include <stdlib.h>
@@ -35,6 +34,7 @@
3534
#include "types.h"
3635
#include "atkbdc.h"
3736
#include "console.h"
37+
#include "log.h"
3838

3939
/* mouse device commands */
4040
#define PS2MC_RESET_DEV 0xff
@@ -152,8 +152,6 @@ fifo_get(struct ps2mouse_info *mouse, uint8_t *val)
152152
static void
153153
movement_reset(struct ps2mouse_info *mouse)
154154
{
155-
/* assert(pthread_mutex_isowned_np(&mouse->mtx)); */
156-
157155
mouse->delta_x = 0;
158156
mouse->delta_y = 0;
159157
}
@@ -172,8 +170,6 @@ movement_get(struct ps2mouse_info *mouse)
172170
{
173171
uint8_t val0, val1, val2;
174172

175-
/* assert(pthread_mutex_isowned_np(&mouse->mtx)); */
176-
177173
val0 = PS2M_DATA_AONE;
178174
val0 |= mouse->status & (PS2M_DATA_LEFT_BUTTON |
179175
PS2M_DATA_RIGHT_BUTTON | PS2M_DATA_MID_BUTTON);
@@ -220,7 +216,6 @@ movement_get(struct ps2mouse_info *mouse)
220216
static void
221217
ps2mouse_reset(struct ps2mouse_info *mouse)
222218
{
223-
/* assert(pthread_mutex_isowned_np(&mouse->mtx)); */
224219
fifo_reset(mouse);
225220
movement_reset(mouse);
226221
mouse->status = PS2M_STS_ENABLE_DEV;
@@ -395,8 +390,10 @@ ps2mouse_init(struct atkbdc_base *base)
395390
struct ps2mouse_info *mouse;
396391

397392
mouse = calloc(1, sizeof(struct ps2mouse_info));
398-
399-
assert(mouse != NULL);
393+
if (!mouse) {
394+
pr_err("%s: alloc memory fail!\n", __func__);
395+
return NULL;
396+
}
400397

401398
pthread_mutex_init(&mouse->mtx, NULL);
402399
fifo_init(mouse);

0 commit comments

Comments
 (0)