[PATCH] mrsas: Fix possible sleep-under-mutex bugs
    Jia-Ju Bai 
    baijiaju1990 at 163.com
       
    Mon Jun 19 02:12:42 UTC 2017
    
    
  
The driver may sleep under a mutex, and the function call paths are:
mrsas_reset_ctrl [line 2959: acquire the mutex]
  mrsas_ioc_init [line 3050]
    mrsas_alloc_ioc_cmd [line 2450]
      bus_dma_tag_create(BUS_DMA_ALLOCNOW) --> may sleep
mrsas_reset_ctrl [line 2959: acquire the mutex]
  megasas_setup_jbod_map [line 3089]
    bus_dma_tag_create(BUS_DMA_ALLOCNOW) --> may sleep
The possible fix of these bugs is to add "BUS_DMA_NOWAIT" in bus_dma_tag_create.
These bugs are found by a static analysis tool written by myself, and it is
checked by my review of the FreeBSD code.
Signed-off-by: Jia-Ju Bai <baijiaju1990 at 163.com>
---
 sys/dev/mrsas/mrsas.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sys/dev/mrsas/mrsas.c b/sys/dev/mrsas/mrsas.c
index d5e83494284..06f26c95841 100644
--- a/sys/dev/mrsas/mrsas.c
+++ b/sys/dev/mrsas/mrsas.c
@@ -2087,7 +2087,7 @@ megasas_setup_jbod_map(struct mrsas_softc *sc)
 		    pd_seq_map_sz,
 		    1,
 		    pd_seq_map_sz,
-		    BUS_DMA_ALLOCNOW,
+		    BUS_DMA_ALLOCNOW | BUS_DMA_NOWAIT,
 		    NULL, NULL,
 		    &sc->jbodmap_tag[i])) {
 			device_printf(sc->mrsas_dev,
@@ -2391,7 +2391,7 @@ mrsas_alloc_ioc_cmd(struct mrsas_softc *sc)
 	    ioc_init_size,
 	    1,
 	    ioc_init_size,
-	    BUS_DMA_ALLOCNOW,
+	    BUS_DMA_ALLOCNOW | BUS_DMA_NOWAIT,
 	    NULL, NULL,
 	    &sc->ioc_init_tag)) {
 		device_printf(sc->mrsas_dev, "Cannot allocate ioc init tag\n");
-- 
2.13.0
    
    
More information about the freebsd-drivers
mailing list