Patchwork [08/21] block: Avoid unchecked casts for AIOCBs

login
register
mail settings
Submitter Kevin Wolf
Date May 14, 2010, 5:10 p.m.
Message ID <1273857055-26715-9-git-send-email-kwolf@redhat.com>
Download mbox | patch
Permalink /patch/52635/
State New
Headers show

Comments

Kevin Wolf - May 14, 2010, 5:10 p.m.
Use container_of for one direction and &acb->common for the other one.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c          |    3 ++-
 block/blkdebug.c |    4 ++--
 block/qcow.c     |    2 +-
 block/qcow2.c    |    2 +-
 block/vdi.c      |    2 +-
 5 files changed, 7 insertions(+), 6 deletions(-)

Patch

diff --git a/block.c b/block.c
index 48305b7..6345599 100644
--- a/block.c
+++ b/block.c
@@ -2108,7 +2108,8 @@  typedef struct BlockDriverAIOCBSync {
 
 static void bdrv_aio_cancel_em(BlockDriverAIOCB *blockacb)
 {
-    BlockDriverAIOCBSync *acb = (BlockDriverAIOCBSync *)blockacb;
+    BlockDriverAIOCBSync *acb =
+        container_of(blockacb, BlockDriverAIOCBSync, common);
     qemu_bh_delete(acb->bh);
     acb->bh = NULL;
     qemu_aio_release(acb);
diff --git a/block/blkdebug.c b/block/blkdebug.c
index bb4a91a..8325f75 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -320,7 +320,7 @@  static void error_callback_bh(void *opaque)
 
 static void blkdebug_aio_cancel(BlockDriverAIOCB *blockacb)
 {
-    BlkdebugAIOCB *acb = (BlkdebugAIOCB*) blockacb;
+    BlkdebugAIOCB *acb = container_of(blockacb, BlkdebugAIOCB, common);
     qemu_aio_release(acb);
 }
 
@@ -347,7 +347,7 @@  static BlockDriverAIOCB *inject_error(BlockDriverState *bs,
     acb->bh = bh;
     qemu_bh_schedule(bh);
 
-    return (BlockDriverAIOCB*) acb;
+    return &acb->common;
 }
 
 static BlockDriverAIOCB *blkdebug_aio_readv(BlockDriverState *bs,
diff --git a/block/qcow.c b/block/qcow.c
index 2883c40..449858f 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -502,7 +502,7 @@  typedef struct QCowAIOCB {
 
 static void qcow_aio_cancel(BlockDriverAIOCB *blockacb)
 {
-    QCowAIOCB *acb = (QCowAIOCB *)blockacb;
+    QCowAIOCB *acb = container_of(blockacb, QCowAIOCB, common);
     if (acb->hd_aiocb)
         bdrv_aio_cancel(acb->hd_aiocb);
     qemu_aio_release(acb);
diff --git a/block/qcow2.c b/block/qcow2.c
index ebad4e1..0ce7150 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -338,7 +338,7 @@  typedef struct QCowAIOCB {
 
 static void qcow_aio_cancel(BlockDriverAIOCB *blockacb)
 {
-    QCowAIOCB *acb = (QCowAIOCB *)blockacb;
+    QCowAIOCB *acb = container_of(blockacb, QCowAIOCB, common);
     if (acb->hd_aiocb)
         bdrv_aio_cancel(acb->hd_aiocb);
     qemu_aio_release(acb);
diff --git a/block/vdi.c b/block/vdi.c
index 1d257b4..2b4d2c2 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -469,7 +469,7 @@  static int vdi_is_allocated(BlockDriverState *bs, int64_t sector_num,
 static void vdi_aio_cancel(BlockDriverAIOCB *blockacb)
 {
     /* TODO: This code is untested. How can I get it executed? */
-    VdiAIOCB *acb = (VdiAIOCB *)blockacb;
+    VdiAIOCB *acb = container_of(blockacb, VdiAIOCB, common);
     logout("\n");
     if (acb->hd_aiocb) {
         bdrv_aio_cancel(acb->hd_aiocb);