From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MHCE6-0002pD-8O for qemu-devel@nongnu.org; Thu, 18 Jun 2009 03:40:02 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MHCE1-0002nz-Hd for qemu-devel@nongnu.org; Thu, 18 Jun 2009 03:40:01 -0400 Received: from [199.232.76.173] (port=43786 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MHCE1-0002nw-CC for qemu-devel@nongnu.org; Thu, 18 Jun 2009 03:39:57 -0400 Received: from mx2.redhat.com ([66.187.237.31]:45367) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MHCE0-0003ff-Th for qemu-devel@nongnu.org; Thu, 18 Jun 2009 03:39:57 -0400 Subject: Re: [Qemu-devel] [PATCH] replace duplicated code. From: Mark McLoughlin In-Reply-To: <1245279129-6768-1-git-send-email-glommer@redhat.com> References: <1245279129-6768-1-git-send-email-glommer@redhat.com> Content-Type: text/plain Date: Thu, 18 Jun 2009 08:39:53 +0100 Message-Id: <1245310793.675.47.camel@blaa> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Reply-To: Mark McLoughlin List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Glauber Costa Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org On Wed, 2009-06-17 at 18:52 -0400, Glauber Costa wrote: > pci_register_simple() does exactly the same of great part of the code > in pci nic initialization. Replace it. > > Signed-off-by: Glauber Costa > --- > hw/pci.c | 12 ++++-------- > hw/qdev.c | 1 + > 2 files changed, 5 insertions(+), 8 deletions(-) > > diff --git a/hw/pci.c b/hw/pci.c > index baffadd..0169b78 100644 > --- a/hw/pci.c > +++ b/hw/pci.c > @@ -818,20 +818,16 @@ static const char * const pci_nic_names[] = { > PCIDevice *pci_nic_init(PCIBus *bus, NICInfo *nd, int devfn, > const char *default_model) > { > - DeviceState *dev; > int i; > > qemu_check_nic_model_list(nd, pci_nic_models, default_model); > > for (i = 0; pci_nic_models[i]; i++) { > if (strcmp(nd->model, pci_nic_models[i]) == 0) { > - dev = qdev_create(&bus->qbus, pci_nic_names[i]); > - qdev_set_prop_int(dev, "devfn", devfn); > - qdev_set_prop_ptr(dev, "name", (void *)pci_nic_names[i]); So, this patch depends on your "allow for name property" patch - resend as a series, maybe with this one first? > - qdev_set_netdev(dev, nd); > - qdev_init(dev); > - nd->private = dev; > - return (PCIDevice *)dev; > + PCIDevice *d; > + d = pci_create_simple(bus, devfn, pci_nic_names[i]); > + qdev_set_netdev((DeviceState *)d, nd); I'd prefer &d->qdev here for type safety. Cheers, Mark.