Index: sys/dev/xen/bus/xen_intr.c =================================================================== --- sys/dev/xen/bus/xen_intr.c +++ sys/dev/xen/bus/xen_intr.c @@ -433,7 +433,8 @@ *isrcp = NULL; if (port_handlep == NULL) { printf("%s: %s: Bad event handle\n", intr_owner, __func__); - return (EINVAL); + error = EINVAL; + goto failearly; } *port_handlep = NULL; @@ -443,8 +444,10 @@ params->xi_type)); isrc = xen_intr_alloc_isrc(params); - if (isrc == NULL) - return (ENOSPC); + if (isrc == NULL) { + error = ENOSPC; + goto failearly; + } refcount_init(&isrc->xi_refcount, 1); #ifdef SMP cpu = isrc->xi_cpu; @@ -502,6 +505,15 @@ /* Assign the opaque handler */ *port_handlep = xen_intr_handle_from_isrc(isrc); return (0); + +failearly: + if (params->xi_close) { + evtchn_close_t close = { .port = params->xi_port }; + if (HYPERVISOR_event_channel_op(EVTCHNOP_close, &close)) + panic("EVTCHNOP_close failed"); + } + + return (error); } /**