From: Gleb C. <lna...@ya...> - 2023-06-30 07:56:55
|
Commit: 86d5b21 GitHub URL: https://github.com/SCST-project/scst/commit/86d5b218e4cbf98da04db81b8e320e490fbbe472 Author: Gleb Chesnokov Date: 2023-06-30T10:56:09+03:00 Log Message: ----------- scst_targ: Check prepare_to_wait_exclusive_head() return value The prepare_to_wait_exclusive_head() function was modified in commit d8894cbd1157 ("scst.h: Refactor wait_event_locked() to enhance usability and clarity"). It now returns an error if the current interruptible thread has pending signals. This patch introduces the scst_wait_for_cmd() helper function for the scst_cmd_thread(). This new function handles the return value of the prepare_to_wait_exclusive_head() appropriately. This patch fixes the following Coverity complaint: CID 321410 (#1 of 1): Unchecked return value (CHECKED_RETURN) check_return: Calling prepare_to_wait_exclusive_head without checking return value. Modified Paths: -------------- scst/src/scst_targ.c | 51 ++++++++++----- 1 file changed, 34 insertions(+), 17 deletions(-) =================================================================== diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 70e212e..4b4eac7 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -4800,6 +4800,39 @@ static inline int test_cmd_threads(struct scst_cmd_thread_t *thr) return res; } +static inline int +scst_wait_for_cmd(struct scst_cmd_threads *p_cmd_threads, struct scst_cmd_thread_t *thr) +{ + DEFINE_WAIT(wq_entry); + int ret = 0; + + if (test_cmd_threads(thr)) + return 0; + + for (;;) { + long __int = prepare_to_wait_exclusive_head(&p_cmd_threads->cmd_list_waitQ, + &wq_entry, TASK_INTERRUPTIBLE); + + if (test_cmd_threads(thr)) + break; + + if (__int) { + ret = __int; + goto out; + } + + spin_unlock(&thr->thr_cmd_list_lock); + spin_unlock_irq(&p_cmd_threads->cmd_list_lock); + schedule(); + spin_lock_irq(&p_cmd_threads->cmd_list_lock); + spin_lock(&thr->thr_cmd_list_lock); + } + finish_wait(&p_cmd_threads->cmd_list_waitQ, &wq_entry); + +out: + return ret; +} + int scst_cmd_thread(void *arg) { struct scst_cmd_thread_t *thr = arg; @@ -4822,23 +4855,7 @@ int scst_cmd_thread(void *arg) spin_lock_irq(&p_cmd_threads->cmd_list_lock); spin_lock(&thr->thr_cmd_list_lock); while (!kthread_should_stop()) { - if (!test_cmd_threads(thr)) { - DEFINE_WAIT(wait); - - do { - prepare_to_wait_exclusive_head( - &p_cmd_threads->cmd_list_waitQ, - &wait, TASK_INTERRUPTIBLE); - if (test_cmd_threads(thr)) - break; - spin_unlock(&thr->thr_cmd_list_lock); - spin_unlock_irq(&p_cmd_threads->cmd_list_lock); - schedule(); - spin_lock_irq(&p_cmd_threads->cmd_list_lock); - spin_lock(&thr->thr_cmd_list_lock); - } while (!test_cmd_threads(thr)); - finish_wait(&p_cmd_threads->cmd_list_waitQ, &wait); - } + scst_wait_for_cmd(p_cmd_threads, thr); if (tm_dbg_is_release()) { spin_unlock_irq(&p_cmd_threads->cmd_list_lock); |