ide: Fix segfault when flushing a device that doesn't exist
authorKevin Wolf <kwolf@redhat.com>
Tue, 12 Aug 2014 16:29:41 +0000 (18:29 +0200)
committerStefan Hajnoczi <stefanha@redhat.com>
Fri, 15 Aug 2014 17:03:13 +0000 (18:03 +0100)
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
hw/ide/core.c
tests/ide-test.c

index bdb0a80..82dd4af 100644 (file)
@@ -848,7 +848,9 @@ static void ide_flush_cb(void *opaque, int ret)
         }
     }
 
-    bdrv_acct_done(s->bs, &s->acct);
+    if (s->bs) {
+        bdrv_acct_done(s->bs, &s->acct);
+    }
     s->status = READY_STAT | SEEK_STAT;
     ide_cmd_done(s);
     ide_set_irq(s->bus);
index a77a037..ffce6ed 100644 (file)
@@ -564,6 +564,19 @@ static void test_retry_flush(void)
     ide_test_quit();
 }
 
+static void test_flush_nodev(void)
+{
+    ide_test_start("");
+
+    /* FLUSH CACHE command on device 0*/
+    outb(IDE_BASE + reg_device, 0);
+    outb(IDE_BASE + reg_command, CMD_FLUSH_CACHE);
+
+    /* Just testing that qemu doesn't crash... */
+
+    ide_test_quit();
+}
+
 int main(int argc, char **argv)
 {
     const char *arch = qtest_get_arch();
@@ -601,6 +614,7 @@ int main(int argc, char **argv)
     qtest_add_func("/ide/bmdma/teardown", test_bmdma_teardown);
 
     qtest_add_func("/ide/flush", test_flush);
+    qtest_add_func("/ide/flush_nodev", test_flush_nodev);
 
     qtest_add_func("/ide/retry/flush", test_retry_flush);