[PATCH] tws: Fix a possible sleep-under-mutex bug in tws_init_reqs

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


The driver may sleep under a mutex, and the code path is:
tws_init_reqs [line 684: acquire the mutex]
tws_init_reqs [line 685]
  bus_dmamap_create(BUS_DMA_WAITOK) [line 687] --> 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/tws/tws.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sys/dev/tws/tws.c b/sys/dev/tws/tws.c
index 480f6f95489..6d21a524f18 100644
--- a/sys/dev/tws/tws.c
+++ b/sys/dev/tws/tws.c
@@ -684,7 +684,8 @@ tws_init_reqs(struct tws_softc *sc, u_int32_t dma_mem_size)
     mtx_lock(&sc->q_lock);
     for ( i=0; i< tws_queue_depth; i++)
     {
-        if (bus_dmamap_create(sc->data_tag, 0, &sc->reqs[i].dma_map)) {
+        if (bus_dmamap_create(sc->data_tag, BUS_DMA_NOWAIT, 
+							&sc->reqs[i].dma_map)) {
             /* log a ENOMEM failure msg here */
             mtx_unlock(&sc->q_lock);
             return(FAILURE);
-- 
2.13.0




More information about the freebsd-drivers mailing list