Message ID | 20200326152438.6218-17-alexandru.elisei@arm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add reassignable BARs and PCIE 1.1 support | expand |
On 26/03/2020 15:24, Alexandru Elisei wrote: > Failling an mmap call or creating a memslot means that device emulation > will not work, don't ignore it. > > Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com> Reviewed-by: Andre Przywara <andre.przywara@arm.com> Cheers, Andre > --- > hw/vesa.c | 28 ++++++++++++++++++++-------- > 1 file changed, 20 insertions(+), 8 deletions(-) > > diff --git a/hw/vesa.c b/hw/vesa.c > index b92cc990b730..ad09373ea2ff 100644 > --- a/hw/vesa.c > +++ b/hw/vesa.c > @@ -63,22 +63,25 @@ struct framebuffer *vesa__init(struct kvm *kvm) > > if (!kvm->cfg.vnc && !kvm->cfg.sdl && !kvm->cfg.gtk) > return NULL; > - r = pci_get_io_port_block(PCI_IO_SIZE); > - r = ioport__register(kvm, r, &vesa_io_ops, PCI_IO_SIZE, NULL); > + vesa_base_addr = pci_get_io_port_block(PCI_IO_SIZE); > + r = ioport__register(kvm, vesa_base_addr, &vesa_io_ops, PCI_IO_SIZE, NULL); > if (r < 0) > - return ERR_PTR(r); > + goto out_error; > > - vesa_base_addr = (u16)r; > vesa_pci_device.bar[0] = cpu_to_le32(vesa_base_addr | PCI_BASE_ADDRESS_SPACE_IO); > r = device__register(&vesa_device); > if (r < 0) > - return ERR_PTR(r); > + goto unregister_ioport; > > mem = mmap(NULL, VESA_MEM_SIZE, PROT_RW, MAP_ANON_NORESERVE, -1, 0); > - if (mem == MAP_FAILED) > - ERR_PTR(-errno); > + if (mem == MAP_FAILED) { > + r = -errno; > + goto unregister_device; > + } > > - kvm__register_dev_mem(kvm, VESA_MEM_ADDR, VESA_MEM_SIZE, mem); > + r = kvm__register_dev_mem(kvm, VESA_MEM_ADDR, VESA_MEM_SIZE, mem); > + if (r < 0) > + goto unmap_dev; > > vesafb = (struct framebuffer) { > .width = VESA_WIDTH, > @@ -90,4 +93,13 @@ struct framebuffer *vesa__init(struct kvm *kvm) > .kvm = kvm, > }; > return fb__register(&vesafb); > + > +unmap_dev: > + munmap(mem, VESA_MEM_SIZE); > +unregister_device: > + device__unregister(&vesa_device); > +unregister_ioport: > + ioport__unregister(kvm, vesa_base_addr); > +out_error: > + return ERR_PTR(r); > } >
diff --git a/hw/vesa.c b/hw/vesa.c index b92cc990b730..ad09373ea2ff 100644 --- a/hw/vesa.c +++ b/hw/vesa.c @@ -63,22 +63,25 @@ struct framebuffer *vesa__init(struct kvm *kvm) if (!kvm->cfg.vnc && !kvm->cfg.sdl && !kvm->cfg.gtk) return NULL; - r = pci_get_io_port_block(PCI_IO_SIZE); - r = ioport__register(kvm, r, &vesa_io_ops, PCI_IO_SIZE, NULL); + vesa_base_addr = pci_get_io_port_block(PCI_IO_SIZE); + r = ioport__register(kvm, vesa_base_addr, &vesa_io_ops, PCI_IO_SIZE, NULL); if (r < 0) - return ERR_PTR(r); + goto out_error; - vesa_base_addr = (u16)r; vesa_pci_device.bar[0] = cpu_to_le32(vesa_base_addr | PCI_BASE_ADDRESS_SPACE_IO); r = device__register(&vesa_device); if (r < 0) - return ERR_PTR(r); + goto unregister_ioport; mem = mmap(NULL, VESA_MEM_SIZE, PROT_RW, MAP_ANON_NORESERVE, -1, 0); - if (mem == MAP_FAILED) - ERR_PTR(-errno); + if (mem == MAP_FAILED) { + r = -errno; + goto unregister_device; + } - kvm__register_dev_mem(kvm, VESA_MEM_ADDR, VESA_MEM_SIZE, mem); + r = kvm__register_dev_mem(kvm, VESA_MEM_ADDR, VESA_MEM_SIZE, mem); + if (r < 0) + goto unmap_dev; vesafb = (struct framebuffer) { .width = VESA_WIDTH, @@ -90,4 +93,13 @@ struct framebuffer *vesa__init(struct kvm *kvm) .kvm = kvm, }; return fb__register(&vesafb); + +unmap_dev: + munmap(mem, VESA_MEM_SIZE); +unregister_device: + device__unregister(&vesa_device); +unregister_ioport: + ioport__unregister(kvm, vesa_base_addr); +out_error: + return ERR_PTR(r); }
Failling an mmap call or creating a memslot means that device emulation will not work, don't ignore it. Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com> --- hw/vesa.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)