Message ID | 20200417121536.5393-2-johannes.thumshirn@wdc.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Introduce Zone Append for writing to zoned block devices | expand |
On 2020-04-17 05:15, Johannes Thumshirn wrote: > @@ -1190,6 +1190,7 @@ static blk_status_t scsi_setup_cmnd(struct scsi_device *sdev, > struct request *req) > { > struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); > + blk_status_t ret; > > if (!blk_rq_bytes(req)) > cmd->sc_data_direction = DMA_NONE; > @@ -1199,9 +1200,14 @@ static blk_status_t scsi_setup_cmnd(struct scsi_device *sdev, > cmd->sc_data_direction = DMA_FROM_DEVICE; > > if (blk_rq_is_scsi(req)) > - return scsi_setup_scsi_cmnd(sdev, req); > + ret = scsi_setup_scsi_cmnd(sdev, req); > else > - return scsi_setup_fs_cmnd(sdev, req); > + ret = scsi_setup_fs_cmnd(sdev, req); > + > + if (ret != BLK_STS_OK) > + scsi_free_sgtables(cmd); > + > + return ret; > } If this patch fixes the bug reported in https://bugzilla.kernel.org/show_bug.cgi?id=205595, please mention this. How about adding __must_check to scsi_setup_fs_cmnd()? Thanks, Bart.
On 18/04/2020 18:02, Bart Van Assche wrote: > If this patch fixes the bug reported in > https://bugzilla.kernel.org/show_bug.cgi?id=205595, please mention this. > > How about adding __must_check to scsi_setup_fs_cmnd()? Oh thanks for the Link, I didn't know there was a bug report for the memory leak. I've encountered the leak in testing this series with custom error injection via SG_IO. I'll add the link to the bug report if I need a re-send.
On 18/04/2020 18:02, Bart Van Assche wrote:
> How about adding __must_check to scsi_setup_fs_cmnd()?
I'm actually not sure if __must_check helps us anything given that with
this patch applied:
johannes@redsun60:linux(zone-append-wip)$ git --no-pager grep -n \
scsi_setup_fs_cmnd drivers/scsi
drivers/scsi/scsi_lib.c:1173:
static blk_status_t scsi_setup_fs_cmnd(struct scsi_device *sdev,
drivers/scsi/scsi_lib.c:1205:
ret = scsi_setup_fs_cmnd(sdev, req);
there's only one caller of scsi_setup_fs_cmnd(), in the same file, 32
lines below the implementation.
I do agree about the Link or an eventual Cc: stable, but I think Martin
or Jens can add this when applying the patch.
On Mon, Apr 20, 2020 at 10:46:21AM +0000, Johannes Thumshirn wrote: > On 18/04/2020 18:02, Bart Van Assche wrote: > > How about adding __must_check to scsi_setup_fs_cmnd()? > > I'm actually not sure if __must_check helps us anything given that with > this patch applied: It doesn't. __must_check on static functions with a single caller does not make any sense.
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 47835c4b4ee0..ad97369ffabd 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -548,7 +548,7 @@ static void scsi_uninit_cmd(struct scsi_cmnd *cmd) } } -static void scsi_mq_free_sgtables(struct scsi_cmnd *cmd) +static void scsi_free_sgtables(struct scsi_cmnd *cmd) { if (cmd->sdb.table.nents) sg_free_table_chained(&cmd->sdb.table, @@ -560,7 +560,7 @@ static void scsi_mq_free_sgtables(struct scsi_cmnd *cmd) static void scsi_mq_uninit_cmd(struct scsi_cmnd *cmd) { - scsi_mq_free_sgtables(cmd); + scsi_free_sgtables(cmd); scsi_uninit_cmd(cmd); } @@ -1059,7 +1059,7 @@ blk_status_t scsi_init_io(struct scsi_cmnd *cmd) return BLK_STS_OK; out_free_sgtables: - scsi_mq_free_sgtables(cmd); + scsi_free_sgtables(cmd); return ret; } EXPORT_SYMBOL(scsi_init_io); @@ -1190,6 +1190,7 @@ static blk_status_t scsi_setup_cmnd(struct scsi_device *sdev, struct request *req) { struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(req); + blk_status_t ret; if (!blk_rq_bytes(req)) cmd->sc_data_direction = DMA_NONE; @@ -1199,9 +1200,14 @@ static blk_status_t scsi_setup_cmnd(struct scsi_device *sdev, cmd->sc_data_direction = DMA_FROM_DEVICE; if (blk_rq_is_scsi(req)) - return scsi_setup_scsi_cmnd(sdev, req); + ret = scsi_setup_scsi_cmnd(sdev, req); else - return scsi_setup_fs_cmnd(sdev, req); + ret = scsi_setup_fs_cmnd(sdev, req); + + if (ret != BLK_STS_OK) + scsi_free_sgtables(cmd); + + return ret; } static blk_status_t