static struct XenDevice *xen_be_del_xendev(int dom, int dev)

{

    struct XenDevice *xendev, *xnext;



    /*

     * This is pretty much like QTAILQ_FOREACH(xendev, &xendevs, next) but

     * we save the next pointer in xnext because we might free xendev.

     */

    xnext = xendevs.tqh_first;

    while (xnext) {

        xendev = xnext;

        xnext = xendev->next.tqe_next;



        if (xendev->dom != dom) {

            continue;

        }

        if (xendev->dev != dev && dev != -1) {

            continue;

        }



        if (xendev->ops->free) {

            xendev->ops->free(xendev);

        }



        if (xendev->fe) {

            char token[XEN_BUFSIZE];

            snprintf(token, sizeof(token), "fe:%p", xendev);

            xs_unwatch(xenstore, xendev->fe, token);

            g_free(xendev->fe);

        }



        if (xendev->evtchndev != XC_HANDLER_INITIAL_VALUE) {

            xc_evtchn_close(xendev->evtchndev);

        }

        if (xendev->gnttabdev != XC_HANDLER_INITIAL_VALUE) {

            xc_gnttab_close(xendev->gnttabdev);

        }



        QTAILQ_REMOVE(&xendevs, xendev, next);

        g_free(xendev);

    }

    return NULL;

}

static struct XenDevice *xen_be_del_xendev(int dom, int dev)

{

    struct XenDevice *xendev, *xnext;



    







    xnext = xendevs.tqh_first;

    while (xnext) {

        xendev = xnext;

        xnext = xendev->next.tqe_next;



        if (xendev->dom != dom) {

            continue;

        }

        if (xendev->dev != dev && dev != -1) {

            continue;

        }



        if (xendev->ops->free) {

            xendev->ops->free(xendev);

        }



        if (xendev->fe) {

            char token[XEN_BUFSIZE];

            snprintf(token, sizeof(token), "fe:%p", xendev);

            xs_unwatch(xenstore, xendev->fe, token);

            g_free(xendev->fe);

        }



        if (xendev->evtchndev != XC_HANDLER_INITIAL_VALUE) {

            xc_evtchn_close(xendev->evtchndev);

        }

        if (xendev->gnttabdev != XC_HANDLER_INITIAL_VALUE) {

            xc_gnttab_close(xendev->gnttabdev);

        }



        QTAILQ_REMOVE(&xendevs, xendev, next);

        g_free(xendev);

    }

    return NULL;

}

static struct XenDevice *FUNC_0(int VAR_0, int VAR_1)

{

    struct XenDevice *VAR_2, *VAR_3;



    







    VAR_3 = xendevs.tqh_first;

    while (VAR_3) {

        VAR_2 = VAR_3;

        VAR_3 = VAR_2->next.tqe_next;



        if (VAR_2->VAR_0 != VAR_0) {

            continue;

        }

        if (VAR_2->VAR_1 != VAR_1 && VAR_1 != -1) {

            continue;

        }



        if (VAR_2->ops->free) {

            VAR_2->ops->free(VAR_2);

        }



        if (VAR_2->fe) {

            char VAR_4[XEN_BUFSIZE];

            snprintf(VAR_4, sizeof(VAR_4), "fe:%p", VAR_2);

            xs_unwatch(xenstore, VAR_2->fe, VAR_4);

            g_free(VAR_2->fe);

        }



        if (VAR_2->evtchndev != XC_HANDLER_INITIAL_VALUE) {

            xc_evtchn_close(VAR_2->evtchndev);

        }

        if (VAR_2->gnttabdev != XC_HANDLER_INITIAL_VALUE) {

            xc_gnttab_close(VAR_2->gnttabdev);

        }



        QTAILQ_REMOVE(&xendevs, VAR_2, next);

        g_free(VAR_2);

    }

    return NULL;

}

static struct XenDevice *FUNC_0(int VAR_0, int VAR_1)
{ struct XenDevice *VAR_2, *VAR_3; VAR_3 = xendevs.tqh_first; while (VAR_3) { VAR_2 = VAR_3; VAR_3 = VAR_2->next.tqe_next; if (VAR_2->VAR_0 != VAR_0) { continue; } if (VAR_2->VAR_1 != VAR_1 && VAR_1 != -1) { continue; } if (VAR_2->ops->free) { VAR_2->ops->free(VAR_2); } if (VAR_2->fe) { char VAR_4[XEN_BUFSIZE]; snprintf(VAR_4, sizeof(VAR_4), "fe:%p", VAR_2); xs_unwatch(xenstore, VAR_2->fe, VAR_4); g_free(VAR_2->fe); } if (VAR_2->evtchndev != XC_HANDLER_INITIAL_VALUE) { xc_evtchn_close(VAR_2->evtchndev); } if (VAR_2->gnttabdev != XC_HANDLER_INITIAL_VALUE) { xc_gnttab_close(VAR_2->gnttabdev); } QTAILQ_REMOVE(&xendevs, VAR_2, next); g_free(VAR_2); } return NULL; }