qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Glauber Costa <glommer@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com
Subject: [Qemu-devel] [PATCH] replace duplicated code.
Date: Wed, 17 Jun 2009 18:52:09 -0400	[thread overview]
Message-ID: <1245279129-6768-1-git-send-email-glommer@redhat.com> (raw)

pci_register_simple() does exactly the same of great part of the code
in pci nic initialization. Replace it.

Signed-off-by: Glauber Costa <glommer@redhat.com>
---
 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]);
-            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);
+            return d;
         }
     }
 
diff --git a/hw/qdev.c b/hw/qdev.c
index 5175fe1..c7446d5 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -164,6 +164,7 @@ void qdev_set_netdev(DeviceState *dev, NICInfo *nd)
 {
     assert(!dev->nd);
     dev->nd = nd;
+    nd->private = dev;
 }
 
 
-- 
1.6.2.2

             reply	other threads:[~2009-06-17 22:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-17 22:52 Glauber Costa [this message]
2009-06-18  7:39 ` [Qemu-devel] [PATCH] replace duplicated code Mark McLoughlin
2009-06-18  9:48 ` Gerd Hoffmann
2009-06-18 13:59   ` Glauber Costa
2009-06-18 14:33     ` Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1245279129-6768-1-git-send-email-glommer@redhat.com \
    --to=glommer@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).