Skip to content

Commit 3ef385d

Browse files
conghuic23wenlingz
authored andcommitted
dm: ahci: clean up assert
This patch is to clean up assert from achi. Tracked-On: #3252 Signed-off-by: Conghui Chen <conghui.chen@intel.com> Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
1 parent 4145b8a commit 3ef385d

File tree

1 file changed

+57
-18
lines changed

1 file changed

+57
-18
lines changed

devicemodel/hw/pci/ahci.c

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <stdio.h>
3232
#include <stdlib.h>
3333
#include <string.h>
34-
#include <assert.h>
3534
#include <pthread.h>
3635
#include <inttypes.h>
3736
#include <openssl/md5.h>
@@ -626,7 +625,6 @@ ahci_build_iov(struct ahci_port *p, struct ahci_ioreq *aior,
626625
if (j == BLOCKIF_IOV_MAX) {
627626
extra = todo % blockif_sectsz(p->bctx);
628627
todo -= extra;
629-
assert(todo > 0);
630628
while (extra > 0) {
631629
if (breq->iov[j - 1].iov_len > extra) {
632630
breq->iov[j - 1].iov_len -= extra;
@@ -702,7 +700,10 @@ ahci_handle_rw(struct ahci_port *p, int slot, uint8_t *cfis, uint32_t done)
702700

703701
/* Pull request off free list */
704702
aior = STAILQ_FIRST(&p->iofhd);
705-
assert(aior != NULL);
703+
if (aior == NULL) {
704+
WPRINTF("%s: failed to pull request off free list\n", __func__);
705+
return;
706+
}
706707
STAILQ_REMOVE_HEAD(&p->iofhd, io_flist);
707708

708709
aior->cfis = cfis;
@@ -726,7 +727,8 @@ ahci_handle_rw(struct ahci_port *p, int slot, uint8_t *cfis, uint32_t done)
726727
err = blockif_read(p->bctx, breq);
727728
else
728729
err = blockif_write(p->bctx, breq);
729-
assert(err == 0);
730+
if (err)
731+
WPRINTF("%s: blockif read or write error\n", __func__);
730732
}
731733

732734
static void
@@ -740,7 +742,10 @@ ahci_handle_flush(struct ahci_port *p, int slot, uint8_t *cfis)
740742
* Pull request off free list
741743
*/
742744
aior = STAILQ_FIRST(&p->iofhd);
743-
assert(aior != NULL);
745+
if (aior == NULL) {
746+
WPRINTF("%s: failed to pull request off free list\n", __func__);
747+
return;
748+
}
744749
STAILQ_REMOVE_HEAD(&p->iofhd, io_flist);
745750
aior->cfis = cfis;
746751
aior->slot = slot;
@@ -760,7 +765,8 @@ ahci_handle_flush(struct ahci_port *p, int slot, uint8_t *cfis)
760765
TAILQ_INSERT_HEAD(&p->iobhd, aior, io_blist);
761766

762767
err = blockif_flush(p->bctx, breq);
763-
assert(err == 0);
768+
if (err)
769+
WPRINTF("%s: blockif flush failed\n", __func__);
764770
}
765771

766772
static inline void
@@ -849,7 +855,10 @@ ahci_handle_dsm_trim(struct ahci_port *p, int slot, uint8_t *cfis,
849855
* Pull request off free list
850856
*/
851857
aior = STAILQ_FIRST(&p->iofhd);
852-
assert(aior != NULL);
858+
if (aior == NULL) {
859+
WPRINTF("%s: failed to pull request off free list\n", __func__);
860+
return;
861+
}
853862
STAILQ_REMOVE_HEAD(&p->iofhd, io_flist);
854863
aior->cfis = cfis;
855864
aior->slot = slot;
@@ -875,7 +884,8 @@ ahci_handle_dsm_trim(struct ahci_port *p, int slot, uint8_t *cfis,
875884
ahci_write_fis_d2h_ncq(p, slot);
876885

877886
err = blockif_discard(p->bctx, breq);
878-
assert(err == 0);
887+
if (err)
888+
WPRINTF("%s: blockif discard failed\n", __func__);
879889
}
880890

881891
static inline void
@@ -1401,7 +1411,10 @@ atapi_read(struct ahci_port *p, int slot, uint8_t *cfis, uint32_t done)
14011411
* Pull request off free list
14021412
*/
14031413
aior = STAILQ_FIRST(&p->iofhd);
1404-
assert(aior != NULL);
1414+
if (aior == NULL) {
1415+
WPRINTF("%s: failed to pull request off free list\n", __func__);
1416+
return;
1417+
}
14051418
STAILQ_REMOVE_HEAD(&p->iofhd, io_flist);
14061419
aior->cfis = cfis;
14071420
aior->slot = slot;
@@ -1418,7 +1431,8 @@ atapi_read(struct ahci_port *p, int slot, uint8_t *cfis, uint32_t done)
14181431
TAILQ_INSERT_HEAD(&p->iobhd, aior, io_blist);
14191432

14201433
err = blockif_read(p->bctx, breq);
1421-
assert(err == 0);
1434+
if (err)
1435+
WPRINTF("%s: blockif read failed\n", __func__);
14221436
}
14231437

14241438
static void
@@ -1999,7 +2013,7 @@ atapi_ioreq_cb(struct blockif_req *br, int err)
19992013
DPRINTF("%s exit\n", __func__);
20002014
}
20012015

2002-
static void
2016+
static int
20032017
pci_ahci_ioreq_init(struct ahci_port *pr)
20042018
{
20052019
struct ahci_ioreq *vr;
@@ -2008,7 +2022,10 @@ pci_ahci_ioreq_init(struct ahci_port *pr)
20082022
pr->ioqsz = blockif_queuesz(pr->bctx);
20092023
pr->ioreq = calloc(pr->ioqsz, sizeof(struct ahci_ioreq));
20102024

2011-
assert(pr->ioreq != NULL);
2025+
if (pr->ioreq == NULL) {
2026+
WPRINTF("%s: failed to calloc for ioreq\n", __func__);
2027+
return -1;
2028+
}
20122029

20132030
STAILQ_INIT(&pr->iofhd);
20142031

@@ -2027,6 +2044,7 @@ pci_ahci_ioreq_init(struct ahci_port *pr)
20272044
}
20282045

20292046
TAILQ_INIT(&pr->iobhd);
2047+
return 0;
20302048
}
20312049

20322050
static void
@@ -2177,8 +2195,16 @@ pci_ahci_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
21772195
{
21782196
struct pci_ahci_vdev *ahci_dev = dev->arg;
21792197

2180-
assert(baridx == 5);
2181-
assert((offset % 4) == 0 && size == 4);
2198+
if (baridx != 5) {
2199+
WPRINTF("%s: baridx=%d not support \n", __func__, baridx);
2200+
return;
2201+
}
2202+
2203+
if (!((offset % 4) == 0 && size == 4)) {
2204+
WPRINTF("%s: offset=%ld, size=%d not support \n",
2205+
__func__, offset, size);
2206+
return;
2207+
}
21822208

21832209
pthread_mutex_lock(&ahci_dev->mtx);
21842210

@@ -2278,9 +2304,19 @@ pci_ahci_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, int baridx,
22782304
uint64_t offset;
22792305
uint32_t value;
22802306

2281-
assert(baridx == 5);
2282-
assert(size == 1 || size == 2 || size == 4);
2283-
assert((regoff & (size - 1)) == 0);
2307+
value = 0;
2308+
if (baridx != 5) {
2309+
WPRINTF("%s: baridx=%d error", __func__, baridx);
2310+
return value;
2311+
}
2312+
if (size != 1 && size != 2 && size != 4) {
2313+
WPRINTF("%s: size=%d not support", __func__, size);
2314+
return value;
2315+
}
2316+
if ((regoff & (size - 1)) != 0) {
2317+
WPRINTF("%s: regoff=%ld not support", __func__, regoff);
2318+
return value;
2319+
}
22842320

22852321
pthread_mutex_lock(&ahci_dev->mtx);
22862322

@@ -2390,7 +2426,10 @@ pci_ahci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts, int atapi)
23902426
* Allocate blockif request structures and add them
23912427
* to the free list
23922428
*/
2393-
pci_ahci_ioreq_init(&ahci_dev->port[p]);
2429+
if (pci_ahci_ioreq_init(&ahci_dev->port[p])) {
2430+
ret = -1;
2431+
goto open_fail;
2432+
}
23942433

23952434
ahci_dev->pi |= (1 << p);
23962435
if (ahci_dev->port[p].ioqsz < slots)

0 commit comments

Comments
 (0)