diff mbox series

[v3,05/33] serial-pci-multi: factor out multi_serial_get_nr_ports

Message ID 20191023173154.30051-6-marcandre.lureau@redhat.com
State New
Headers show
Series Clean-ups: qom-ify serial and remove QDEV_PROP_PTR | expand

Commit Message

Marc-André Lureau Oct. 23, 2019, 5:31 p.m. UTC
Reused in following patch.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/char/serial-pci-multi.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

Comments

Philippe Mathieu-Daudé Oct. 23, 2019, 10:41 p.m. UTC | #1
On 10/23/19 7:31 PM, Marc-André Lureau wrote:
> Reused in following patch.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   hw/char/serial-pci-multi.c | 26 ++++++++++++++------------
>   1 file changed, 14 insertions(+), 12 deletions(-)
> 
> diff --git a/hw/char/serial-pci-multi.c b/hw/char/serial-pci-multi.c
> index 5f13b5663b..6fa1cc6225 100644
> --- a/hw/char/serial-pci-multi.c
> +++ b/hw/char/serial-pci-multi.c
> @@ -77,24 +77,26 @@ static void multi_serial_irq_mux(void *opaque, int n, int level)
>       pci_set_irq(&pci->dev, pending);
>   }
>   
> +static int multi_serial_get_nr_ports(PCIDeviceClass *pc)

static size_t multi_serial_get_port_count()?

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> +{
> +    switch (pc->device_id) {
> +    case 0x0003:
> +        return 2;
> +    case 0x0004:
> +        return 4;
> +    }
> +
> +    g_assert_not_reached();
> +}
> +
> +
>   static void multi_serial_pci_realize(PCIDevice *dev, Error **errp)
>   {
>       PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
>       PCIMultiSerialState *pci = DO_UPCAST(PCIMultiSerialState, dev, dev);
>       SerialState *s;
>       Error *err = NULL;
> -    int i, nr_ports = 0;
> -
> -    switch (pc->device_id) {
> -    case 0x0003:
> -        nr_ports = 2;
> -        break;
> -    case 0x0004:
> -        nr_ports = 4;
> -        break;
> -    }
> -    assert(nr_ports > 0);
> -    assert(nr_ports <= PCI_SERIAL_MAX_PORTS);
> +    int i, nr_ports = multi_serial_get_nr_ports(pc);
>   
>       pci->dev.config[PCI_CLASS_PROG] = pci->prog_if;
>       pci->dev.config[PCI_INTERRUPT_PIN] = 0x01;
>
Marc-André Lureau Oct. 24, 2019, 9:59 a.m. UTC | #2
On Thu, Oct 24, 2019 at 12:41 AM Philippe Mathieu-Daudé
<philmd@redhat.com> wrote:
>
> On 10/23/19 7:31 PM, Marc-André Lureau wrote:
> > Reused in following patch.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >   hw/char/serial-pci-multi.c | 26 ++++++++++++++------------
> >   1 file changed, 14 insertions(+), 12 deletions(-)
> >
> > diff --git a/hw/char/serial-pci-multi.c b/hw/char/serial-pci-multi.c
> > index 5f13b5663b..6fa1cc6225 100644
> > --- a/hw/char/serial-pci-multi.c
> > +++ b/hw/char/serial-pci-multi.c
> > @@ -77,24 +77,26 @@ static void multi_serial_irq_mux(void *opaque, int n, int level)
> >       pci_set_irq(&pci->dev, pending);
> >   }
> >
> > +static int multi_serial_get_nr_ports(PCIDeviceClass *pc)
>
> static size_t multi_serial_get_port_count()?
>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

works for me, thanks

>
> > +{
> > +    switch (pc->device_id) {
> > +    case 0x0003:
> > +        return 2;
> > +    case 0x0004:
> > +        return 4;
> > +    }
> > +
> > +    g_assert_not_reached();
> > +}
> > +
> > +
> >   static void multi_serial_pci_realize(PCIDevice *dev, Error **errp)
> >   {
> >       PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
> >       PCIMultiSerialState *pci = DO_UPCAST(PCIMultiSerialState, dev, dev);
> >       SerialState *s;
> >       Error *err = NULL;
> > -    int i, nr_ports = 0;
> > -
> > -    switch (pc->device_id) {
> > -    case 0x0003:
> > -        nr_ports = 2;
> > -        break;
> > -    case 0x0004:
> > -        nr_ports = 4;
> > -        break;
> > -    }
> > -    assert(nr_ports > 0);
> > -    assert(nr_ports <= PCI_SERIAL_MAX_PORTS);
> > +    int i, nr_ports = multi_serial_get_nr_ports(pc);
> >
> >       pci->dev.config[PCI_CLASS_PROG] = pci->prog_if;
> >       pci->dev.config[PCI_INTERRUPT_PIN] = 0x01;
> >
diff mbox series

Patch

diff --git a/hw/char/serial-pci-multi.c b/hw/char/serial-pci-multi.c
index 5f13b5663b..6fa1cc6225 100644
--- a/hw/char/serial-pci-multi.c
+++ b/hw/char/serial-pci-multi.c
@@ -77,24 +77,26 @@  static void multi_serial_irq_mux(void *opaque, int n, int level)
     pci_set_irq(&pci->dev, pending);
 }
 
+static int multi_serial_get_nr_ports(PCIDeviceClass *pc)
+{
+    switch (pc->device_id) {
+    case 0x0003:
+        return 2;
+    case 0x0004:
+        return 4;
+    }
+
+    g_assert_not_reached();
+}
+
+
 static void multi_serial_pci_realize(PCIDevice *dev, Error **errp)
 {
     PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev);
     PCIMultiSerialState *pci = DO_UPCAST(PCIMultiSerialState, dev, dev);
     SerialState *s;
     Error *err = NULL;
-    int i, nr_ports = 0;
-
-    switch (pc->device_id) {
-    case 0x0003:
-        nr_ports = 2;
-        break;
-    case 0x0004:
-        nr_ports = 4;
-        break;
-    }
-    assert(nr_ports > 0);
-    assert(nr_ports <= PCI_SERIAL_MAX_PORTS);
+    int i, nr_ports = multi_serial_get_nr_ports(pc);
 
     pci->dev.config[PCI_CLASS_PROG] = pci->prog_if;
     pci->dev.config[PCI_INTERRUPT_PIN] = 0x01;