Page MenuHomeFreeBSD

D26286.id76511.diff
No OneTemporary

D26286.id76511.diff

Index: sys/cam/cam_sim.c
===================================================================
--- sys/cam/cam_sim.c
+++ sys/cam/cam_sim.c
@@ -124,14 +124,15 @@
void
cam_sim_free(struct cam_sim *sim, int free_devq)
{
- struct mtx *mtx = sim->mtx;
+ struct mtx *mtx;
int error;
- if (mtx) {
- mtx_assert(mtx, MA_OWNED);
- } else {
+ if (sim->mtx == NULL) {
mtx = &cam_sim_free_mtx;
mtx_lock(mtx);
+ } else {
+ mtx = sim->mtx;
+ mtx_assert(mtx, MA_OWNED);
}
sim->refcount--;
if (sim->refcount > 0) {
@@ -139,7 +140,7 @@
KASSERT(error == 0, ("invalid error value for msleep(9)"));
}
KASSERT(sim->refcount == 0, ("sim->refcount == 0"));
- if (sim->mtx == NULL)
+ if (mtx == &cam_sim_free_mtx) /* sim->mtx == NULL */
mtx_unlock(mtx);
if (free_devq)
@@ -150,17 +151,16 @@
void
cam_sim_release(struct cam_sim *sim)
{
- struct mtx *mtx = sim->mtx;
+ struct mtx *mtx;
- if (mtx) {
- if (!mtx_owned(mtx))
- mtx_lock(mtx);
- else
- mtx = NULL;
- } else {
+ if (sim->mtx == NULL)
mtx = &cam_sim_free_mtx;
+ else if (!mtx_owned(sim->mtx))
+ mtx = sim->mtx;
+ else
+ mtx = NULL; /* We hold the lock. */
+ if (mtx)
mtx_lock(mtx);
- }
KASSERT(sim->refcount >= 1, ("sim->refcount >= 1"));
sim->refcount--;
if (sim->refcount == 0)
@@ -172,17 +172,16 @@
void
cam_sim_hold(struct cam_sim *sim)
{
- struct mtx *mtx = sim->mtx;
+ struct mtx *mtx;
- if (mtx) {
- if (!mtx_owned(mtx))
- mtx_lock(mtx);
- else
- mtx = NULL;
- } else {
+ if (sim->mtx == NULL)
mtx = &cam_sim_free_mtx;
+ else if (!mtx_owned(sim->mtx))
+ mtx = sim->mtx;
+ else
+ mtx = NULL; /* We hold the lock. */
+ if (mtx)
mtx_lock(mtx);
- }
KASSERT(sim->refcount >= 1, ("sim->refcount >= 1"));
sim->refcount++;
if (mtx)

File Metadata

Mime Type
text/plain
Expires
Sat, Oct 25, 12:02 AM (1 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
24150558
Default Alt Text
D26286.id76511.diff (1 KB)

Event Timeline