On Wed, Apr 15, 2020 at 06:05:03PM +0900, Johannes Thumshirn wrote: > In case scsi_setup_fs_cmnd() fails we're not freeing the sgtables > allocated by scsi_init_io(), thus we leak the allocated memory. > > So free the sgtables allocated by scsi_init_io() in case > scsi_setup_fs_cmnd() fails. > > Technically scsi_setup_scsi_cmnd() does not suffer from this problem, as > it can only fail if scsi_init_io() fails, so it does not have sgtables > allocated. But to maintain symmetry and as a measure of defensive > programming, free the sgtables on scsi_setup_scsi_cmnd() failure as well. > scsi_mq_free_sgtables() has safeguards against double-freeing of memory so > this is safe to do. > > While we're at it, rename scsi_mq_free_sgtables() to scsi_free_sgtables(). Looks good, Reviewed-by: Christoph Hellwig <hch@xxxxxx>