This is a note to let you know that I've just added the patch titled scsi: Revert "scsi: core: Do not increase scsi_device's iorequest_cnt if dispatch failed" to the 6.3-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: scsi-revert-scsi-core-do-not-increase-scsi_device-s-iorequest_cnt-if-dispatch-failed.patch and it can be found in the queue-6.3 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From 6ca9818d1624e136a76ae8faedb6b6c95ca66903 Mon Sep 17 00:00:00 2001 From: Wenchao Hao <haowenchao2@xxxxxxxxxx> Date: Mon, 15 May 2023 15:01:55 +0800 Subject: scsi: Revert "scsi: core: Do not increase scsi_device's iorequest_cnt if dispatch failed" From: Wenchao Hao <haowenchao2@xxxxxxxxxx> commit 6ca9818d1624e136a76ae8faedb6b6c95ca66903 upstream. The "atomic_inc(&cmd->device->iorequest_cnt)" in scsi_queue_rq() would cause kernel panic because cmd->device may be freed after returning from scsi_dispatch_cmd(). This reverts commit cfee29ffb45b1c9798011b19d454637d1b0fe87d. Signed-off-by: Wenchao Hao <haowenchao2@xxxxxxxxxx> Reported-by: Ming Lei <ming.lei@xxxxxxxxxx> Closes: https://lore.kernel.org/r/ZF+zB+bB7iqe0wGd@xxxxxxxxxxxxxxxxxxxxxxxxx Link: https://lore.kernel.org/r/20230515070156.1790181-2-haowenchao2@xxxxxxxxxx Reviewed-by: Ming Lei <ming.lei@xxxxxxxxxx> Signed-off-by: Martin K. Petersen <martin.petersen@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/scsi/scsi_lib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1463,6 +1463,8 @@ static int scsi_dispatch_cmd(struct scsi struct Scsi_Host *host = cmd->device->host; int rtn = 0; + atomic_inc(&cmd->device->iorequest_cnt); + /* check if the device is still usable */ if (unlikely(cmd->device->sdev_state == SDEV_DEL)) { /* in SDEV_DEL we error all commands. DID_NO_CONNECT @@ -1761,7 +1763,6 @@ static blk_status_t scsi_queue_rq(struct goto out_dec_host_busy; } - atomic_inc(&cmd->device->iorequest_cnt); return BLK_STS_OK; out_dec_host_busy: Patches currently in stable-queue which might be from haowenchao2@xxxxxxxxxx are queue-6.3/scsi-revert-scsi-core-do-not-increase-scsi_device-s-iorequest_cnt-if-dispatch-failed.patch