[PATCH] dpt_scsi: Fix a possible sleep-under-mutex bug in dpt_init (different from Bug 220095)

Jia-Ju Bai baijiaju1990 at 163.com
Sun Jun 18 14:45:49 UTC 2017


The driver may sleep under a mutex, and the code path is:
dpt_init [line 1134: acquire the mutex]
  bus_dma_tag_create(BUS_DMA_WAITOK) [line 1143] --> may sleep

The possible fix of this bug is to replace "BUS_DMA_WAITOK" in bus_dma_tag_create with "BUS_DMA_NOWAIT".

This bug is 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/dpt/dpt_scsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/dev/dpt/dpt_scsi.c b/sys/dev/dpt/dpt_scsi.c
index 541b58665cf..d69a443067a 100644
--- a/sys/dev/dpt/dpt_scsi.c
+++ b/sys/dev/dpt/dpt_scsi.c
@@ -1150,7 +1150,7 @@ dpt_init(struct dpt_softc *dpt)
 				/* maxsize	*/ PAGE_SIZE,
 				/* nsegments	*/ 1,
 				/* maxsegsz	*/ BUS_SPACE_MAXSIZE_32BIT,
-				/* flags	*/ 0,
+				/* flags	*/ BUS_DMA_NOWAIT,
 				/* lockfunc	*/ NULL,
 				/* lockarg	*/ NULL,
 				&dpt->sg_dmat) != 0) {
-- 
2.13.0




More information about the freebsd-scsi mailing list