On Thu, Apr 09, 2020 at 11:18:22PM -0700, Christoph Hellwig wrote: > On Fri, Apr 10, 2020 at 01:53:49AM +0900, Johannes Thumshirn wrote: > > + if (req_op(rq) == REQ_OP_ZONE_APPEND) { > > + ret = sd_zbc_prepare_zone_append(cmd, &lba, nr_blocks); > > + if (ret) { > > + scsi_free_sgtables(cmd); > > + return ret; > > + } > > + } > > So actually. > > I've been trying to understand the lifetime of the sgtables. Shouldn't > we free them in the midayer ->init_command returned BLK_STS_*RESOURCE > instead? It seems like this just catches one particular error instead > of the whole category? The end of scsi_queue_rq seem like a particular > good place, as that also releases the resources for the "hard" errors. Looking more the situation seems even worse. If scsi_mq_prep_fn isn't successfull we never seem to free the sgtables, even for fatal errors. So I think we need a real bug fix here in front of the series.