[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device.
From: |
Peter Maydell |
Subject: |
Re: [Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device. |
Date: |
Wed, 9 Jan 2013 14:33:00 +0000 |
On 9 January 2013 08:45, KONRAD Frédéric <address@hidden> wrote:
> On 08/01/2013 18:54, Peter Maydell wrote:
>> This doesn't have any code in it yet (it gets added in later patches) but
>> the final result looks very repetitive. I think you'd be better off just
>> having
>> some arrays:
>>
>> uint16_t virtio_pci_device_id[] = {
>> [VIRTIO_ID_BLOCK] = PCI_DEVICE_ID_VIRTIO_BLOCK,
>> [VIRTIO_ID_NET] = PCI_DEVICE_ID_VIRTIO_NET,
>> (etc)
>> };
>>
>> similarly for the class. Then you can just drop the switch statement.
>>
>> In fact I think you might as well put in the array entries for all
>> the virtio devices in this patch rather than adding one in each of the
>> "add virtio-foo device" patches; it will do no harm for them to be
>> there early and it makes the later patches a little smaller.
>
> And what happen when it is a bad ID ?
Error, same as before. Obviously you protect the array lookup
with a sizeof check for out of range, and you know if the array
entry is 0 it's invalid (0 being neither a valid device id or class).
If you think that looks too ugly then you could keep the switch, but
don't put calls to pci_config_set_device_id() and pci_config_set_class()
in each switch, that's just code duplication.
-- PMM
- Re: [Qemu-devel] [PATCH 03/61] virtio-pci-bus : introduce virtio-pci-bus., (continued)
[Qemu-devel] [PATCH 02/61] virtio-bus : introduce virtio-bus, fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 04/61] virtio-pci : refactor virtio-pci device., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 06/61] virtio-s390-bus : add virtio-s390-bus., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 05/61] virtio-device : refactor virtio-device., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 07/61] virtio-s390-device : create a virtio-s390-bus during init., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 08/61] virtio-blk : show VirtIOBlock structure., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 09/61] virtio-blk : don't use pointer for configuration., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 10/61] virtio-blk : add the virtio-blk device., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 12/61] virtio-blk-s390 : switch to the new API., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 11/61] virtio-blk-pci : switch to new API., fred . konrad, 2013/01/07
[Qemu-devel] [PATCH 14/61] virtio-blk : cleanup : remove qdev field., fred . konrad, 2013/01/07