From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 3/6] Make it obvious that pci_nic_init() can't fail
Date: Fri, 25 Sep 2009 03:53:50 +0200 [thread overview]
Message-ID: <77f0efd64b83c1177166dd1c9a11730913857352.1253843233.git.armbru@redhat.com> (raw)
In-Reply-To: <cover.1253843232.git.armbru@redhat.com>
Before this patch, pci_nic_init() returns NULL when it can't find the
model in pci_nic_models[]. Except this can't happen, because
qemu_check_nic_model_list() just searched for model in
pci_nic_models[], and terminated the program on failure.
Repeating the search here is pointless. Instead, change
qemu_check_nic_model_list() to return the model's array index.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
hw/pci.c | 25 +++++++++----------------
net.c | 6 +++---
net.h | 4 ++--
3 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/hw/pci.c b/hw/pci.c
index 5be21d7..92262f7 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -815,22 +815,15 @@ PCIDevice *pci_nic_init(NICInfo *nd, 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) {
- pci_dev = pci_create(pci_nic_names[i], devaddr);
- dev = &pci_dev->qdev;
- if (nd->id)
- dev->id = qemu_strdup(nd->id);
- dev->nd = nd;
- qdev_init(dev);
- nd->private = dev;
- return pci_dev;
- }
- }
-
- return NULL;
+ i = qemu_check_nic_model_list(nd, pci_nic_models, default_model);
+ pci_dev = pci_create(pci_nic_names[i], devaddr);
+ dev = &pci_dev->qdev;
+ if (nd->id)
+ dev->id = qemu_strdup(nd->id);
+ dev->nd = nd;
+ qdev_init(dev);
+ nd->private = dev;
+ return pci_dev;
}
typedef struct {
diff --git a/net.c b/net.c
index 3fdf1e6..0eba08b 100644
--- a/net.c
+++ b/net.c
@@ -2358,8 +2358,8 @@ void qemu_check_nic_model(NICInfo *nd, const char *model)
qemu_check_nic_model_list(nd, models, model);
}
-void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
- const char *default_model)
+int qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
+ const char *default_model)
{
int i, exit_status = 0;
@@ -2369,7 +2369,7 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
if (strcmp(nd->model, "?") != 0) {
for (i = 0 ; models[i]; i++)
if (strcmp(nd->model, models[i]) == 0)
- return;
+ return i;
fprintf(stderr, "qemu: Unsupported NIC model: %s\n", nd->model);
exit_status = 1;
diff --git a/net.h b/net.h
index 1479826..c93cc99 100644
--- a/net.h
+++ b/net.h
@@ -76,8 +76,8 @@ void qemu_purge_queued_packets(VLANClientState *vc);
void qemu_flush_queued_packets(VLANClientState *vc);
void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
void qemu_check_nic_model(NICInfo *nd, const char *model);
-void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
- const char *default_model);
+int qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
+ const char *default_model);
void qemu_handler_true(void *opaque);
void do_info_network(Monitor *mon);
--
1.6.2.5
next prev parent reply other threads:[~2009-09-25 1:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-25 1:53 [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Markus Armbruster
2009-09-25 1:53 ` [Qemu-devel] [PATCH 1/6] Fix pci_vga_init() not to ignore bus argument Markus Armbruster
2009-09-25 1:53 ` [Qemu-devel] [PATCH 2/6] Fix pci_add storage not to exit on bad first argument Markus Armbruster
2009-09-25 16:36 ` [Qemu-devel] " Markus Armbruster
2009-09-25 1:53 ` Markus Armbruster [this message]
2009-09-25 1:53 ` [Qemu-devel] [PATCH 4/6] Fix pci_add nic not to exit on bad model Markus Armbruster
2009-09-25 1:53 ` [Qemu-devel] [PATCH 5/6] pci_create() is now unused, remove it Markus Armbruster
2009-09-25 1:53 ` [Qemu-devel] [PATCH 6/6] Rename pci_create_noinit() to pci_create() Markus Armbruster
2009-09-25 10:44 ` [Qemu-devel] [PATCH 0/6] Fix pci_add not to exit on error & other fixes Gerd Hoffmann
2009-09-25 14:12 ` Markus Armbruster
2009-09-25 16:26 ` Luiz Capitulino
2009-09-28 16:05 ` Mark McLoughlin
2009-09-28 16:16 ` Mark McLoughlin
2009-09-28 19:14 ` Markus Armbruster
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=77f0efd64b83c1177166dd1c9a11730913857352.1253843233.git.armbru@redhat.com \
--to=armbru@redhat.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).