Patchwork [3/3] ide: kill ide_dma_submit_check

login
register
mail settings
Submitter Christoph Hellwig
Date Dec. 20, 2010, 12:46 p.m.
Message ID <20101220124609.GB6423@lst.de>
Download mbox | patch
Permalink /patch/76203/
State New
Headers show

Comments

Christoph Hellwig - Dec. 20, 2010, 12:46 p.m.
Merge ide_dma_submit_check into it's only caller.  Also use tail recursion
using a goto instead of a real recursion - this avoid overflowing the
stack in the pathological situation of an recurring error that is ignored.
We'll still be busy looping in ide_dma_cb, but at least won't eat up
all stack space after this.

Signed-off-by: Christoph Hellwig <hch@lst.de>

Patch

Index: qemu/hw/ide/core.c
===================================================================
--- qemu.orig/hw/ide/core.c	2010-12-20 13:16:11.379004054 +0100
+++ qemu/hw/ide/core.c	2010-12-20 13:16:11.000000000 +0100
@@ -321,14 +321,6 @@  static inline void ide_abort_command(IDE
     s->error = ABRT_ERR;
 }
 
-static inline void ide_dma_submit_check(IDEState *s,
-          BlockDriverCompletionFunc *dma_cb)
-{
-    if (s->bus->dma->aiocb)
-	return;
-    dma_cb(s, -1);
-}
-
 /* prepare data transfer and tell what to do after */
 static void ide_transfer_start(IDEState *s, uint8_t *buf, int size,
                                EndTransferFunc *end_transfer_func)
@@ -493,6 +485,7 @@  void ide_dma_cb(void *opaque, int ret)
     int n;
     int64_t sector_num;
 
+handle_rw_error:
     if (ret < 0) {
         int op = BM_STATUS_DMA_RETRY;
 
@@ -538,7 +531,11 @@  void ide_dma_cb(void *opaque, int ret)
         s->bus->dma->aiocb = dma_bdrv_write(s->bs, &s->sg, sector_num,
                                             ide_dma_cb, s);
     }
-    ide_dma_submit_check(s, ide_dma_cb);
+
+    if (!s->bus->dma->aiocb) {
+        ret = -1;
+        goto handle_rw_error;
+    }
     return;
 
 eot: