From 31318acbc8f47f9b03be4be0482c8e2089fa2099 Mon Sep 17 00:00:00 2001 From: Gleb Chesnokov Date: Wed, 9 Nov 2022 17:38:34 +0300 Subject: [PATCH] scst_targ: Use 'atomic_inc_return' to check 'dev->dev_cmd_count' 1. atomic_inc_return() avoids a race in between atomic_read() & atomic_inc(). 2. atomic_inc_return() is a few cycles faster than atomic_inc()/atomic_read() sequence. --- scst/src/scst_targ.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 9f222e8a7..63083d409 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -4345,8 +4345,7 @@ static int __scst_init_cmd(struct scst_cmd *cmd) } #ifdef CONFIG_SCST_PER_DEVICE_CMD_COUNT_LIMIT - atomic_inc(&dev->dev_cmd_count); - cnt = atomic_read(&dev->dev_cmd_count); + cnt = atomic_inc_return(&dev->dev_cmd_count); if (unlikely(cnt > SCST_MAX_DEV_COMMANDS)) { if (!failure) { TRACE(TRACE_FLOW_CONTROL,