[PATCH] adwcam: Fix a possible sleep-under-mutex bug in adw_init

Jia-Ju Bai baijiaju1990 at 163.com
Mon Jun 19 01:11:23 UTC 2017


The driver may sleep under a sleep, and the function call path is:
adw_init [line 1098: acquire the mutex]
  adwallocacbs
    bus_dmamap_create(BUS_DMA_WAITOK) --> may sleep

The possible fix of this bug is to replace "BUS_DMA_WAITOK" in bus_dmamap_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/advansys/adwcam.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/dev/advansys/adwcam.c b/sys/dev/advansys/adwcam.c
index 02f9c49d800..6950ae49ff8 100644
--- a/sys/dev/advansys/adwcam.c
+++ b/sys/dev/advansys/adwcam.c
@@ -201,7 +201,7 @@ adwallocacbs(struct adw_softc *adw)
 	for (i = 0; adw->num_acbs < adw->max_acbs && i < newcount; i++) {
 		int error;
 
-		error = bus_dmamap_create(adw->buffer_dmat, /*flags*/0,
+		error = bus_dmamap_create(adw->buffer_dmat, /*flags*/BUS_DMA_NOWAIT,
 					  &next_acb->dmamap);
 		if (error != 0)
 			break;
-- 
2.13.0




More information about the freebsd-scsi mailing list