On 4 December 2012 14:35, <fred.kon...@greensocs.com> wrote: > From: KONRAD Frederic <fred.kon...@greensocs.com> > > Create the virtio-device which is abstract. All the virtio-device can extend > this class. > > Signed-off-by: KONRAD Frederic <fred.kon...@greensocs.com> > --- > hw/virtio.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > hw/virtio.h | 29 +++++++++++++++++++++++++++++ > 2 files changed, 85 insertions(+) > > diff --git a/hw/virtio.c b/hw/virtio.c > index f40a8c5..cd46af1 100644 > --- a/hw/virtio.c > +++ b/hw/virtio.c > @@ -16,6 +16,7 @@ > #include "trace.h" > #include "qemu-error.h" > #include "virtio.h" > +#include "virtio-bus.h" > #include "qemu-barrier.h" > > /* The alignment to use between consumer and producer parts of vring. > @@ -934,6 +935,38 @@ VirtIODevice *virtio_common_init(const char *name, > uint16_t device_id, > return vdev; > } > > +/* > + * The same initialization as above without allocating the structure. > + */ > +void virtio_common_init_(VirtIODevice *vdev, const char *name, > + uint16_t device_id, size_t config_size, > + size_t struct_size)
If you find yourself cut-and-pasting 25 lines of code, think again. In this case, just make virtio_common_init() a wrapper that does a malloc and calls your non-allocation init. Also, find a better function name than "just add a random underscore". -- PMM