Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Jun 2017 09:51:19 +0800
From:      Jia-Ju Bai <baijiaju1990@163.com>
To:        freebsdraid@lsi.com
Cc:        freebsd-drivers@freebsd.org, freebsd-bugs@freebsd.org, freebsd-hackers@freebsd.org, Jia-Ju Bai <baijiaju1990@163.com>
Subject:   [PATCH] tws: Fix a possible sleep-under-mutex bug in tws_init_reqs
Message-ID:  <20170619015119.43883-1-baijiaju1990@163.com>

next in thread | raw e-mail | index | archive | help
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@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





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170619015119.43883-1-baijiaju1990>