diff options
author | Mike Christie <michael.christie@oracle.com> | 2021-02-27 10:59:43 -0600 |
---|---|---|
committer | Martin K. Petersen <martin.petersen@oracle.com> | 2021-03-04 17:37:00 -0500 |
commit | cb222a013dca1872deeb49fe8c7176f8aa656d5f (patch) | |
tree | efd69285b41c492acd0cdf9764554841145dcccc | |
parent | a9294d86743298c87fd9c39d9ddebf4b04d5da10 (diff) |
scsi: target: core: Drop kref_get_unless_zero() in target_get_sess_cmd()
The kref_get_unless_zero() use in target_get_sess_cmd() was added in:
commit 1b4c59b7a1d0 ("target: fix potential race window in
target_sess_cmd_list_waiting()")'
but it does not seem to do anything.
The original patch might have thought we could have added the cmd to the
sess_wait_list and then target_wait_for_sess_cmds could do a put before
target_get_sess_cmd did its get. That wouldn't happen because we do the get
first then grab the sess lock and put it on the list.
It is also not needed now, because the sess_cmd_list does not exist anymore
and we instead wait on the session cmd_count.
The other problem with the commit is that several
target_submit_cmd_map_sgls()/target_submit_cmd() callers do not handle the
error case properly if it were to ever happen. These drivers think they
have their normal refcount on the cmd and in many cases do a
transport_generic_free_cmd() plus target_put_sess_cmd() so they would have
fired off the refcount WARN/BUGs.
This patch just changes the kref_get_unless_zero() to kref_get().
Link: https://lore.kernel.org/r/20210227170006.5077-3-michael.christie@oracle.com
Tested-by: Laurence Oberman <loberman@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
-rw-r--r-- | drivers/target/target_core_transport.c | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 2dfbf9cb9581..b8d7edadce46 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -2778,9 +2778,7 @@ int target_get_sess_cmd(struct se_cmd *se_cmd, bool ack_kref) * invocations before se_cmd descriptor release. */ if (ack_kref) { - if (!kref_get_unless_zero(&se_cmd->cmd_kref)) - return -EINVAL; - + kref_get(&se_cmd->cmd_kref); se_cmd->se_cmd_flags |= SCF_ACK_KREF; } |