1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 16:42:56 -08:00

Use mtx_init() to initialize stack-based mutexes

mtx_init() ensures the mutex' lock_object has static storage duration.
This makes it safe to re-enable WITNESS with stack-based mutexes.

OK bluhm@ miod@
This commit is contained in:
visa 2023-07-06 10:17:43 +00:00
parent dc2df9f71c
commit 4e4f5ce5df
5 changed files with 20 additions and 15 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mfi.c,v 1.189 2023/05/25 19:35:58 kurt Exp $ */
/* $OpenBSD: mfi.c,v 1.190 2023/07/06 10:17:43 visa Exp $ */
/*
* Copyright (c) 2006 Marco Peereboom <marco@peereboom.us>
*
@ -925,8 +925,9 @@ mfi_poll(struct mfi_softc *sc, struct mfi_ccb *ccb)
void
mfi_exec(struct mfi_softc *sc, struct mfi_ccb *ccb)
{
struct mutex m = MUTEX_INITIALIZER_FLAGS(IPL_BIO, __MTX_NAME,
MTX_NOWITNESS);
struct mutex m;
mtx_init(&m, IPL_BIO);
#ifdef DIAGNOSTIC
if (ccb->ccb_cookie != NULL || ccb->ccb_done != NULL)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mpi.c,v 1.225 2023/05/25 19:35:58 kurt Exp $ */
/* $OpenBSD: mpi.c,v 1.226 2023/07/06 10:17:43 visa Exp $ */
/*
* Copyright (c) 2005, 2006, 2009 David Gwynne <dlg@openbsd.org>
@ -1263,10 +1263,11 @@ mpi_poll_done(struct mpi_ccb *ccb)
void
mpi_wait(struct mpi_softc *sc, struct mpi_ccb *ccb)
{
struct mutex cookie = MUTEX_INITIALIZER_FLAGS(
IPL_BIO, __MTX_NAME, MTX_NOWITNESS);
struct mutex cookie;
void (*done)(struct mpi_ccb *);
mtx_init(&cookie, IPL_BIO);
done = ccb->ccb_done;
ccb->ccb_done = mpi_wait_done;
ccb->ccb_cookie = &cookie;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mfii.c,v 1.88 2023/05/25 19:35:58 kurt Exp $ */
/* $OpenBSD: mfii.c,v 1.89 2023/07/06 10:17:43 visa Exp $ */
/*
* Copyright (c) 2012 David Gwynne <dlg@openbsd.org>
@ -1764,8 +1764,9 @@ mfii_poll_done(struct mfii_softc *sc, struct mfii_ccb *ccb)
int
mfii_exec(struct mfii_softc *sc, struct mfii_ccb *ccb)
{
struct mutex m = MUTEX_INITIALIZER_FLAGS(IPL_BIO, __MTX_NAME,
MTX_NOWITNESS);
struct mutex m;
mtx_init(&m, IPL_BIO);
#ifdef DIAGNOSTIC
if (ccb->ccb_cookie != NULL || ccb->ccb_done != NULL)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mpii.c,v 1.145 2023/05/25 19:35:58 kurt Exp $ */
/* $OpenBSD: mpii.c,v 1.146 2023/07/06 10:17:43 visa Exp $ */
/*
* Copyright (c) 2010, 2012 Mike Belopuhov
* Copyright (c) 2009 James Giannoules
@ -2857,11 +2857,12 @@ mpii_init_queues(struct mpii_softc *sc)
void
mpii_wait(struct mpii_softc *sc, struct mpii_ccb *ccb)
{
struct mutex mtx = MUTEX_INITIALIZER_FLAGS(IPL_BIO,
__MTX_NAME, MTX_NOWITNESS);
struct mutex mtx;
void (*done)(struct mpii_ccb *);
void *cookie;
mtx_init(&mtx, IPL_BIO);
done = ccb->ccb_done;
cookie = ccb->ccb_cookie;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: scsi_base.c,v 1.281 2023/05/25 19:35:58 kurt Exp $ */
/* $OpenBSD: scsi_base.c,v 1.282 2023/07/06 10:17:43 visa Exp $ */
/* $NetBSD: scsi_base.c,v 1.43 1997/04/02 02:29:36 mycroft Exp $ */
/*
@ -1497,10 +1497,11 @@ scsi_done(struct scsi_xfer *xs)
int
scsi_xs_sync(struct scsi_xfer *xs)
{
struct mutex cookie = MUTEX_INITIALIZER_FLAGS(IPL_BIO, __MTX_NAME,
MTX_NOWITNESS);
struct mutex cookie;
int error;
mtx_init(&cookie, IPL_BIO);
#ifdef DIAGNOSTIC
if (xs->cookie != NULL)
panic("xs->cookie != NULL in scsi_xs_sync");