int spapr_populate_vdevice(VIOsPAPRBus *bus, void *fdt)

{

    DeviceState *qdev, **qdevs;

    BusChild *kid;

    int i, num, ret = 0;



    /* Count qdevs on the bus list */

    num = 0;

    QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {

        num++;

    }



    /* Copy out into an array of pointers */

    qdevs = g_malloc(sizeof(qdev) * num);

    num = 0;

    QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {

        qdevs[num++] = kid->child;

    }



    /* Sort the array */

    qsort(qdevs, num, sizeof(qdev), compare_reg);



    /* Hack alert. Give the devices to libfdt in reverse order, we happen

     * to know that will mean they are in forward order in the tree. */

    for (i = num - 1; i >= 0; i--) {

        VIOsPAPRDevice *dev = (VIOsPAPRDevice *)(qdevs[i]);



        ret = vio_make_devnode(dev, fdt);



        if (ret < 0) {

            goto out;

        }

    }



    ret = 0;

out:

    free(qdevs);



    return ret;

}

int spapr_populate_vdevice(VIOsPAPRBus *bus, void *fdt)

{

    DeviceState *qdev, **qdevs;

    BusChild *kid;

    int i, num, ret = 0;



    

    num = 0;

    QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {

        num++;

    }



    

    qdevs = g_malloc(sizeof(qdev) * num);

    num = 0;

    QTAILQ_FOREACH(kid, &bus->bus.children, sibling) {

        qdevs[num++] = kid->child;

    }



    

    qsort(qdevs, num, sizeof(qdev), compare_reg);



    



    for (i = num - 1; i >= 0; i--) {

        VIOsPAPRDevice *dev = (VIOsPAPRDevice *)(qdevs[i]);



        ret = vio_make_devnode(dev, fdt);



        if (ret < 0) {

            goto out;

        }

    }



    ret = 0;

out:

    free(qdevs);



    return ret;

}

int FUNC_0(VIOsPAPRBus *VAR_0, void *VAR_1)

{

    DeviceState *qdev, **qdevs;

    BusChild *kid;

    int VAR_2, VAR_3, VAR_4 = 0;



    

    VAR_3 = 0;

    QTAILQ_FOREACH(kid, &VAR_0->VAR_0.children, sibling) {

        VAR_3++;

    }



    

    qdevs = g_malloc(sizeof(qdev) * VAR_3);

    VAR_3 = 0;

    QTAILQ_FOREACH(kid, &VAR_0->VAR_0.children, sibling) {

        qdevs[VAR_3++] = kid->child;

    }



    

    qsort(qdevs, VAR_3, sizeof(qdev), compare_reg);



    



    for (VAR_2 = VAR_3 - 1; VAR_2 >= 0; VAR_2--) {

        VIOsPAPRDevice *dev = (VIOsPAPRDevice *)(qdevs[VAR_2]);



        VAR_4 = vio_make_devnode(dev, VAR_1);



        if (VAR_4 < 0) {

            goto out;

        }

    }



    VAR_4 = 0;

out:

    free(qdevs);



    return VAR_4;

}

int FUNC_0(VIOsPAPRBus *VAR_0, void *VAR_1)
{ DeviceState *qdev, **qdevs; BusChild *kid; int VAR_2, VAR_3, VAR_4 = 0; VAR_3 = 0; QTAILQ_FOREACH(kid, &VAR_0->VAR_0.children, sibling) { VAR_3++; } qdevs = g_malloc(sizeof(qdev) * VAR_3); VAR_3 = 0; QTAILQ_FOREACH(kid, &VAR_0->VAR_0.children, sibling) { qdevs[VAR_3++] = kid->child; } qsort(qdevs, VAR_3, sizeof(qdev), compare_reg); for (VAR_2 = VAR_3 - 1; VAR_2 >= 0; VAR_2--) { VIOsPAPRDevice *dev = (VIOsPAPRDevice *)(qdevs[VAR_2]); VAR_4 = vio_make_devnode(dev, VAR_1); if (VAR_4 < 0) { goto out; } } VAR_4 = 0; out:
free(qdevs); return VAR_4; }