From 4fc619ef64c0e2351ec2c12c18ab77313a42bc45 Mon Sep 17 00:00:00 2001 From: avg Date: Fri, 25 Oct 2019 13:47:17 +0000 Subject: [PATCH] ow_temp: better scopes for the lock The lock is used only for start / stop signaling. It is used only for 'flags' field and the related condition variable. This change is a follow-up to r354067, it was suggested by Warner in D22107. Suggested by: imp MFC after: 1 week --- sys/dev/ow/ow_temp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sys/dev/ow/ow_temp.c b/sys/dev/ow/ow_temp.c index 1112c5d4e296..58783949961c 100644 --- a/sys/dev/ow/ow_temp.c +++ b/sys/dev/ow/ow_temp.c @@ -145,9 +145,9 @@ ow_temp_event_thread(void *arg) sc->flags |= OW_TEMP_RUNNING; mtx_unlock(&sc->temp_lock); ow_temp_read_power_supply(sc->dev, &sc->parasite); - mtx_lock(&sc->temp_lock); if (sc->parasite) device_printf(sc->dev, "Running in parasitic mode unsupported\n"); + mtx_lock(&sc->temp_lock); while ((sc->flags & OW_TEMP_DONE) == 0) { mtx_unlock(&sc->temp_lock); ow_temp_convert_t(sc->dev); @@ -155,10 +155,9 @@ ow_temp_event_thread(void *arg) msleep(sc, &sc->temp_lock, 0, "owtcvt", hz); if (sc->flags & OW_TEMP_DONE) break; + mtx_unlock(&sc->temp_lock); for (retries = 5; retries > 0; retries--) { - mtx_unlock(&sc->temp_lock); rv = ow_temp_read_scratchpad(sc->dev, scratch, sizeof(scratch)); - mtx_lock(&sc->temp_lock); if (rv == 0) { crc = own_crc(sc->dev, scratch, sizeof(scratch) - 1); if (crc == scratch[8]) { @@ -182,6 +181,7 @@ ow_temp_event_thread(void *arg) } else sc->bad_reads++; } + mtx_lock(&sc->temp_lock); msleep(sc, &sc->temp_lock, 0, "owtcvt", sc->reading_interval); } sc->flags &= ~OW_TEMP_RUNNING;