Skip to content

Commit cfa86bc

Browse files
pm215mdroth
authored andcommitted
hw/ppc/spapr_pci.c: Avoid functions not in glib 2.12 (g_hash_table_iter_*)
The g_hash_table_iter_* functions for iterating through a hash table are not present in glib 2.12, which is our current minimum requirement. Rewrite the code to use g_hash_table_foreach() instead. Signed-off-by: Peter Maydell <[email protected]> Signed-off-by: Alexander Graf <[email protected]> (cherry picked from commit f8833a3) Signed-off-by: Michael Roth <[email protected]>
1 parent b57b7ec commit cfa86bc

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

hw/ppc/spapr_pci.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -700,28 +700,34 @@ static const VMStateDescription vmstate_spapr_pci_msi = {
700700
},
701701
};
702702

703+
static void spapr_pci_fill_msi_devs(gpointer key, gpointer value,
704+
gpointer opaque)
705+
{
706+
sPAPRPHBState *sphb = opaque;
707+
708+
sphb->msi_devs[sphb->msi_devs_num].key = *(uint32_t *)key;
709+
sphb->msi_devs[sphb->msi_devs_num].value = *(spapr_pci_msi *)value;
710+
sphb->msi_devs_num++;
711+
}
712+
703713
static void spapr_pci_pre_save(void *opaque)
704714
{
705715
sPAPRPHBState *sphb = opaque;
706-
GHashTableIter iter;
707-
gpointer key, value;
708-
int i;
716+
int msi_devs_num;
709717

710718
if (sphb->msi_devs) {
711719
g_free(sphb->msi_devs);
712720
sphb->msi_devs = NULL;
713721
}
714-
sphb->msi_devs_num = g_hash_table_size(sphb->msi);
715-
if (!sphb->msi_devs_num) {
722+
sphb->msi_devs_num = 0;
723+
msi_devs_num = g_hash_table_size(sphb->msi);
724+
if (!msi_devs_num) {
716725
return;
717726
}
718-
sphb->msi_devs = g_malloc(sphb->msi_devs_num * sizeof(spapr_pci_msi_mig));
727+
sphb->msi_devs = g_malloc(msi_devs_num * sizeof(spapr_pci_msi_mig));
719728

720-
g_hash_table_iter_init(&iter, sphb->msi);
721-
for (i = 0; g_hash_table_iter_next(&iter, &key, &value); ++i) {
722-
sphb->msi_devs[i].key = *(uint32_t *) key;
723-
sphb->msi_devs[i].value = *(spapr_pci_msi *) value;
724-
}
729+
g_hash_table_foreach(sphb->msi, spapr_pci_fill_msi_devs, sphb);
730+
assert(sphb->msi_devs_num == msi_devs_num);
725731
}
726732

727733
static int spapr_pci_post_load(void *opaque, int version_id)

0 commit comments

Comments
 (0)