From 794cbc26eb94ce13c75d105eea9ff0afff56e2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 16 Oct 2013 15:24:01 +0200 Subject: sd: Avoid access to NULL BlockDriverState MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 4f8a066b5fc254eeaabbbde56ba4f5b29cc68fdf (blockdev: Remove IF_* check for read-only blockdev_init) added a usage of bdrv_is_read_only() to sd_init(), which is called for versatilepb, versatileab and xilinx-zynq-a9 machines among others with NULL argument by default, causing the new qom-test to fail. Add a check to prevent this. Suggested-by: Kevin Wolf Signed-off-by: Andreas Färber Signed-off-by: Stefan Hajnoczi --- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'hw') diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 7380f063f7..4502ad143d 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -494,7 +494,7 @@ SDState *sd_init(BlockDriverState *bs, bool is_spi) { SDState *sd; - if (bdrv_is_read_only(bs)) { + if (bs && bdrv_is_read_only(bs)) { fprintf(stderr, "sd_init: Cannot use read-only drive\n"); return NULL; } -- cgit v1.2.3 From b432779a9fe9c2a1bb8cbd98feb341af6e32f892 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Thu, 17 Oct 2013 21:23:26 +0200 Subject: virtio: Remove unneeded memcpy Report from valgrind: ==19521== Source and destination overlap in memcpy(0x31d38938, 0x31d38938, 64) ==19521== at 0x4A0A343: memcpy@@GLIBC_2.14 (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) ==19521== by 0x42774E: virtio_blk_device_init (virtio-blk.c:686) ==19521== by 0x46EE9E: virtio_device_init (virtio.c:1158) ==19521== by 0x25405E: device_realize (qdev.c:178) ==19521== by 0x2559B5: device_set_realized (qdev.c:699) ==19521== by 0x3A819B: property_set_bool (object.c:1315) ==19521== by 0x3A6CE0: object_property_set (object.c:803) Valgrind is right: blk == &s->blks, so it is a memcpy of 64 byte with source == destination which can be removed. Reported-by: Dave Airlie Signed-off-by: Stefan Weil Reviewed-by: Peter Maydell Signed-off-by: Stefan Hajnoczi --- hw/block/virtio-blk.c | 1 - 1 file changed, 1 deletion(-) (limited to 'hw') diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 49a23c33f7..13f6d8276e 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -703,7 +703,6 @@ static int virtio_blk_device_init(VirtIODevice *vdev) s->bs = blk->conf.bs; s->conf = &blk->conf; - memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf)); s->rq = NULL; s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1; -- cgit v1.2.3