Skip to content

Commit c682adf

Browse files
author
Christoph Hellwig
committed
scsi: explicitly release bidi buffers
Instead of trying to guess when we have a BIDI buffer in scsi_release_buffers add a function to explicitly free the BIDI ressoures in the one place that handles them. This avoids needing a special __scsi_release_buffers for the case where we already have freed the request as well. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Mike Christie <michaelc@cs.wisc.edu>
1 parent d6d211d commit c682adf

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

drivers/scsi/scsi_lib.c

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,6 @@ void scsi_run_host_queues(struct Scsi_Host *shost)
512512
scsi_run_queue(sdev->request_queue);
513513
}
514514

515-
static void __scsi_release_buffers(struct scsi_cmnd *, int);
516-
517515
/*
518516
* Function: scsi_end_request()
519517
*
@@ -569,7 +567,7 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error,
569567
* This will goose the queue request function at the end, so we don't
570568
* need to worry about launching another command.
571569
*/
572-
__scsi_release_buffers(cmd, 0);
570+
scsi_release_buffers(cmd);
573571
scsi_next_command(cmd);
574572
return NULL;
575573
}
@@ -625,30 +623,10 @@ static void scsi_free_sgtable(struct scsi_data_buffer *sdb)
625623
__sg_free_table(&sdb->table, SCSI_MAX_SG_SEGMENTS, scsi_sg_free);
626624
}
627625

628-
static void __scsi_release_buffers(struct scsi_cmnd *cmd, int do_bidi_check)
629-
{
630-
631-
if (cmd->sdb.table.nents)
632-
scsi_free_sgtable(&cmd->sdb);
633-
634-
memset(&cmd->sdb, 0, sizeof(cmd->sdb));
635-
636-
if (do_bidi_check && scsi_bidi_cmnd(cmd)) {
637-
struct scsi_data_buffer *bidi_sdb =
638-
cmd->request->next_rq->special;
639-
scsi_free_sgtable(bidi_sdb);
640-
kmem_cache_free(scsi_sdb_cache, bidi_sdb);
641-
cmd->request->next_rq->special = NULL;
642-
}
643-
644-
if (scsi_prot_sg_count(cmd))
645-
scsi_free_sgtable(cmd->prot_sdb);
646-
}
647-
648626
/*
649627
* Function: scsi_release_buffers()
650628
*
651-
* Purpose: Completion processing for block device I/O requests.
629+
* Purpose: Free resources allocate for a scsi_command.
652630
*
653631
* Arguments: cmd - command that we are bailing.
654632
*
@@ -659,15 +637,29 @@ static void __scsi_release_buffers(struct scsi_cmnd *cmd, int do_bidi_check)
659637
* Notes: In the event that an upper level driver rejects a
660638
* command, we must release resources allocated during
661639
* the __init_io() function. Primarily this would involve
662-
* the scatter-gather table, and potentially any bounce
663-
* buffers.
640+
* the scatter-gather table.
664641
*/
665642
void scsi_release_buffers(struct scsi_cmnd *cmd)
666643
{
667-
__scsi_release_buffers(cmd, 1);
644+
if (cmd->sdb.table.nents)
645+
scsi_free_sgtable(&cmd->sdb);
646+
647+
memset(&cmd->sdb, 0, sizeof(cmd->sdb));
648+
649+
if (scsi_prot_sg_count(cmd))
650+
scsi_free_sgtable(cmd->prot_sdb);
668651
}
669652
EXPORT_SYMBOL(scsi_release_buffers);
670653

654+
static void scsi_release_bidi_buffers(struct scsi_cmnd *cmd)
655+
{
656+
struct scsi_data_buffer *bidi_sdb = cmd->request->next_rq->special;
657+
658+
scsi_free_sgtable(bidi_sdb);
659+
kmem_cache_free(scsi_sdb_cache, bidi_sdb);
660+
cmd->request->next_rq->special = NULL;
661+
}
662+
671663
/**
672664
* __scsi_error_from_host_byte - translate SCSI error code into errno
673665
* @cmd: SCSI command (unused)
@@ -801,6 +793,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
801793
req->next_rq->resid_len = scsi_in(cmd)->resid;
802794

803795
scsi_release_buffers(cmd);
796+
scsi_release_bidi_buffers(cmd);
804797
blk_end_request_all(req, 0);
805798

806799
scsi_next_command(cmd);

0 commit comments

Comments
 (0)