git: a0d7f3d90046 - stable/12 - safexcel: Stop using a stack buffer for the ring lock name

Mark Johnston markj at FreeBSD.org
Mon Jan 11 14:53:59 UTC 2021


The branch stable/12 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=a0d7f3d9004675b0da39745a0e17747a8d55beb4

commit a0d7f3d9004675b0da39745a0e17747a8d55beb4
Author:     Mark Johnston <markj at FreeBSD.org>
AuthorDate: 2021-01-08 18:32:04 +0000
Commit:     Mark Johnston <markj at FreeBSD.org>
CommitDate: 2021-01-11 14:42:15 +0000

    safexcel: Stop using a stack buffer for the ring lock name
    
    mtx_init() does not make a copy of the name so the buffer must be valid
    for the lifetime of the driver instance.  Store each ring's lock's name
    in the ring structure.
    
    (cherry picked from commit 8ba6acbbe6995efcd12c375e1826d55e35a8bdc9)
---
 sys/dev/safexcel/safexcel.c     | 6 +++---
 sys/dev/safexcel/safexcel_var.h | 2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/sys/dev/safexcel/safexcel.c b/sys/dev/safexcel/safexcel.c
index 9762a20e7c4d..079e9653bfb1 100644
--- a/sys/dev/safexcel/safexcel.c
+++ b/sys/dev/safexcel/safexcel.c
@@ -783,15 +783,15 @@ safexcel_init_rings(struct safexcel_softc *sc)
 {
 	struct safexcel_cmd_descr *cdesc;
 	struct safexcel_ring *ring;
-	char buf[32];
 	uint64_t atok;
 	int i, j;
 
 	for (i = 0; i < sc->sc_config.rings; i++) {
 		ring = &sc->sc_ring[i];
 
-		snprintf(buf, sizeof(buf), "safexcel_ring%d", i);
-		mtx_init(&ring->mtx, buf, NULL, MTX_DEF);
+		snprintf(ring->lockname, sizeof(ring->lockname),
+		    "safexcel_ring%d", i);
+		mtx_init(&ring->mtx, ring->lockname, NULL, MTX_DEF);
 		STAILQ_INIT(&ring->free_requests);
 		STAILQ_INIT(&ring->ready_requests);
 		STAILQ_INIT(&ring->queued_requests);
diff --git a/sys/dev/safexcel/safexcel_var.h b/sys/dev/safexcel/safexcel_var.h
index 4c6b9b73642a..b35ea8cead7b 100644
--- a/sys/dev/safexcel/safexcel_var.h
+++ b/sys/dev/safexcel/safexcel_var.h
@@ -392,6 +392,8 @@ struct safexcel_ring {
 
 	struct safexcel_dma_mem		dma_atok;
 	bus_dma_tag_t   		data_dtag;
+
+	char				lockname[32];
 };
 
 struct safexcel_intr_handle {


More information about the dev-commits-src-all mailing list