megasas: do not call pci_dma_unmap after having freed the frame once
PATCH 1/1 megasas: do not call pci_dma_unmap after having freed the frame once
Commit 8cc4678 ("megasas: remove useless check for cmd->frame", 2016-07-17) was wrong because I trusted Coverity too much. It turns out that there _is_ a path through which cmd->frame can become NULL. After megasas_handle_frame's switch (md->frame->header.frame_cmd), megasas_init_firmware can be called.
Quoted 1 line
From there,
megasas_reset_frameswill callmegasas_unmap_framewhich resets
cmd->frame = NULL.
However, there is another bug to fix in there, because megasas_unmap_frame is called again after setting the command status. In this case QEMU should not do anything, instead it calls pci_dma_unmap again. Harmless, but better fix it.
--- hw/scsi/megasas.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
hw/scsi/megasas.c +4 -1
@@ -461,9 +461,12 @@ static void megasas_unmap_frame(MegasasState *s, MegasasCmd *cmd) {PCIDevice *p =PCI_DEVICE (s); -pci_dma_unmap (p, cmd->frame, cmd->pa_size,0 ,0 ); +if (cmd->pa_size) { +pci_dma_unmap (p, cmd->frame, cmd->pa_size,0 ,0 ); + } cmd->frame =NULL ; cmd->pa =0 ; + cmd->pa_size =0 ;clear_bit (cmd->index, s->frame_map); }
Signature · 1 line
2.9.3
Quoted 12 lines · Paolo Bonzini
Commit 8cc4678 ("megasas: remove useless check for
cmd->frame", 2016-07-17) was wrong because I trusted Coverity too much. It turns out that there _is_ a path through whichcmd->framecan become NULL. After megasas_handle_frame's switch (md->frame->header.frame_cmd),megasas_init_firmwarecan be called. From there,megasas_reset_frameswill callmegasas_unmap_framewhich resetscmd->frame= NULL.However, there is another bug to fix in there, because
megasas_unmap_frameis called again after setting the command status. In this case QEMU should not do anything, instead it callspci_dma_unmapagain. Harmless, but better fix it.
Quoted 4 lines
Signed-off-by Paolo Bonzini <[email protected]>--- hw/scsi/megasas.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)