31
31
#include <stdio.h>
32
32
#include <stdlib.h>
33
33
#include <string.h>
34
- #include <assert.h>
35
34
#include <pthread.h>
36
35
#include <inttypes.h>
37
36
#include <openssl/md5.h>
@@ -626,7 +625,6 @@ ahci_build_iov(struct ahci_port *p, struct ahci_ioreq *aior,
626
625
if (j == BLOCKIF_IOV_MAX ) {
627
626
extra = todo % blockif_sectsz (p -> bctx );
628
627
todo -= extra ;
629
- assert (todo > 0 );
630
628
while (extra > 0 ) {
631
629
if (breq -> iov [j - 1 ].iov_len > extra ) {
632
630
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)
702
700
703
701
/* Pull request off free list */
704
702
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
+ }
706
707
STAILQ_REMOVE_HEAD (& p -> iofhd , io_flist );
707
708
708
709
aior -> cfis = cfis ;
@@ -726,7 +727,8 @@ ahci_handle_rw(struct ahci_port *p, int slot, uint8_t *cfis, uint32_t done)
726
727
err = blockif_read (p -> bctx , breq );
727
728
else
728
729
err = blockif_write (p -> bctx , breq );
729
- assert (err == 0 );
730
+ if (err )
731
+ WPRINTF ("%s: blockif read or write error\n" , __func__ );
730
732
}
731
733
732
734
static void
@@ -740,7 +742,10 @@ ahci_handle_flush(struct ahci_port *p, int slot, uint8_t *cfis)
740
742
* Pull request off free list
741
743
*/
742
744
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
+ }
744
749
STAILQ_REMOVE_HEAD (& p -> iofhd , io_flist );
745
750
aior -> cfis = cfis ;
746
751
aior -> slot = slot ;
@@ -760,7 +765,8 @@ ahci_handle_flush(struct ahci_port *p, int slot, uint8_t *cfis)
760
765
TAILQ_INSERT_HEAD (& p -> iobhd , aior , io_blist );
761
766
762
767
err = blockif_flush (p -> bctx , breq );
763
- assert (err == 0 );
768
+ if (err )
769
+ WPRINTF ("%s: blockif flush failed\n" , __func__ );
764
770
}
765
771
766
772
static inline void
@@ -849,7 +855,10 @@ ahci_handle_dsm_trim(struct ahci_port *p, int slot, uint8_t *cfis,
849
855
* Pull request off free list
850
856
*/
851
857
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
+ }
853
862
STAILQ_REMOVE_HEAD (& p -> iofhd , io_flist );
854
863
aior -> cfis = cfis ;
855
864
aior -> slot = slot ;
@@ -875,7 +884,8 @@ ahci_handle_dsm_trim(struct ahci_port *p, int slot, uint8_t *cfis,
875
884
ahci_write_fis_d2h_ncq (p , slot );
876
885
877
886
err = blockif_discard (p -> bctx , breq );
878
- assert (err == 0 );
887
+ if (err )
888
+ WPRINTF ("%s: blockif discard failed\n" , __func__ );
879
889
}
880
890
881
891
static inline void
@@ -1401,7 +1411,10 @@ atapi_read(struct ahci_port *p, int slot, uint8_t *cfis, uint32_t done)
1401
1411
* Pull request off free list
1402
1412
*/
1403
1413
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
+ }
1405
1418
STAILQ_REMOVE_HEAD (& p -> iofhd , io_flist );
1406
1419
aior -> cfis = cfis ;
1407
1420
aior -> slot = slot ;
@@ -1418,7 +1431,8 @@ atapi_read(struct ahci_port *p, int slot, uint8_t *cfis, uint32_t done)
1418
1431
TAILQ_INSERT_HEAD (& p -> iobhd , aior , io_blist );
1419
1432
1420
1433
err = blockif_read (p -> bctx , breq );
1421
- assert (err == 0 );
1434
+ if (err )
1435
+ WPRINTF ("%s: blockif read failed\n" , __func__ );
1422
1436
}
1423
1437
1424
1438
static void
@@ -1999,7 +2013,7 @@ atapi_ioreq_cb(struct blockif_req *br, int err)
1999
2013
DPRINTF ("%s exit\n" , __func__ );
2000
2014
}
2001
2015
2002
- static void
2016
+ static int
2003
2017
pci_ahci_ioreq_init (struct ahci_port * pr )
2004
2018
{
2005
2019
struct ahci_ioreq * vr ;
@@ -2008,7 +2022,10 @@ pci_ahci_ioreq_init(struct ahci_port *pr)
2008
2022
pr -> ioqsz = blockif_queuesz (pr -> bctx );
2009
2023
pr -> ioreq = calloc (pr -> ioqsz , sizeof (struct ahci_ioreq ));
2010
2024
2011
- assert (pr -> ioreq != NULL );
2025
+ if (pr -> ioreq == NULL ) {
2026
+ WPRINTF ("%s: failed to calloc for ioreq\n" , __func__ );
2027
+ return -1 ;
2028
+ }
2012
2029
2013
2030
STAILQ_INIT (& pr -> iofhd );
2014
2031
@@ -2027,6 +2044,7 @@ pci_ahci_ioreq_init(struct ahci_port *pr)
2027
2044
}
2028
2045
2029
2046
TAILQ_INIT (& pr -> iobhd );
2047
+ return 0 ;
2030
2048
}
2031
2049
2032
2050
static void
@@ -2177,8 +2195,16 @@ pci_ahci_write(struct vmctx *ctx, int vcpu, struct pci_vdev *dev,
2177
2195
{
2178
2196
struct pci_ahci_vdev * ahci_dev = dev -> arg ;
2179
2197
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
+ }
2182
2208
2183
2209
pthread_mutex_lock (& ahci_dev -> mtx );
2184
2210
@@ -2278,9 +2304,19 @@ pci_ahci_read(struct vmctx *ctx, int vcpu, struct pci_vdev *dev, int baridx,
2278
2304
uint64_t offset ;
2279
2305
uint32_t value ;
2280
2306
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
+ }
2284
2320
2285
2321
pthread_mutex_lock (& ahci_dev -> mtx );
2286
2322
@@ -2390,7 +2426,10 @@ pci_ahci_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts, int atapi)
2390
2426
* Allocate blockif request structures and add them
2391
2427
* to the free list
2392
2428
*/
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
+ }
2394
2433
2395
2434
ahci_dev -> pi |= (1 << p );
2396
2435
if (ahci_dev -> port [p ].ioqsz < slots )
0 commit comments