Remove duplicate device index calculations.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4818 c046a42c-6fe2-441c-8c8c-71466251a162
diff --git a/vl.c b/vl.c
index 84eab32..cde008e 100644
--- a/vl.c
+++ b/vl.c
@@ -6060,6 +6060,8 @@
static SaveStateEntry *first_se;
+/* TODO: Individual devices generally have very little idea about the rest
+ of the system, so instance_id should be removed/replaced. */
int register_savevm(const char *idstr,
int instance_id,
int version_id,
@@ -6073,7 +6075,7 @@
if (!se)
return -1;
pstrcpy(se->idstr, sizeof(se->idstr), idstr);
- se->instance_id = instance_id;
+ se->instance_id = (instance_id == -1) ? 0 : instance_id;
se->version_id = version_id;
se->save_state = save_state;
se->load_state = load_state;
@@ -6082,8 +6084,13 @@
/* add at the end of list */
pse = &first_se;
- while (*pse != NULL)
+ while (*pse != NULL) {
+ if (instance_id == -1
+ && strcmp(se->idstr, (*pse)->idstr) == 0
+ && se->instance_id <= (*pse)->instance_id)
+ se->instance_id = (*pse)->instance_id + 1;
pse = &(*pse)->next;
+ }
*pse = se;
return 0;
}