[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-hackers
Subject:    [PATCH] tws: Fix a possible sleep-under-mutex bug in tws_init_reqs
From:       Jia-Ju Bai <baijiaju1990 () 163 ! com>
Date:       2017-06-19 1:51:19
Message-ID: 20170619015119.43883-1-baijiaju1990 () 163 ! com
[Download RAW message or body]

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


_______________________________________________
freebsd-hackers@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic