zbd: avoid Coverity defect report
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Fri, 9 Jun 2023 23:59:14 +0000 (08:59 +0900)
committerJens Axboe <axboe@kernel.dk>
Sat, 10 Jun 2023 00:04:45 +0000 (18:04 -0600)
Coverity reported a defect related to the local variable "in_flight":

    Using an unreliable value of "in_flight" inside the second locked
    section. If the data that "in_flight" depends on was changed by
    another thread, this use might be incorrect.

The variable "in_flight" is thread local and other threads can not
change its value. Then the report should be false-positive. Just to
suppress the report, change reference timing of the valuable.

Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Link: https://lore.kernel.org/r/20230609235914.1376567-1-shinichiro.kawasaki@wdc.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
zbd.c

diff --git a/zbd.c b/zbd.c
index 9455140ac89fd16f0279ad1b24bb530ad4809cfe..7fcf1ec432cfcf8bbaecb1232049037a8bbcead0 100644 (file)
--- a/zbd.c
+++ b/zbd.c
@@ -1547,11 +1547,11 @@ retry:
                dprint(FD_ZBD,
                       "%s(%s): wait zone write and retry write target zone selection\n",
                       __func__, f->file_name);
+               should_retry = in_flight;
                pthread_mutex_unlock(&zbdi->mutex);
                zone_unlock(z);
                io_u_quiesce(td);
                zone_lock(td, f, z);
-               should_retry = in_flight;
                goto retry;
        }