Index: head/sys/net/iflib.c =================================================================== --- head/sys/net/iflib.c +++ head/sys/net/iflib.c @@ -4368,11 +4368,8 @@ ctx->ifc_softc = sc; if ((err = iflib_register(ctx)) != 0) { - if (ctx->ifc_flags & IFC_SC_ALLOCATED) - free(sc, M_IFLIB); - free(ctx, M_IFLIB); device_printf(dev, "iflib_register failed %d\n", err); - return (err); + goto fail_ctx_free; } iflib_add_device_sysctl_pre(ctx); @@ -4382,9 +4379,8 @@ iflib_reset_qvalues(ctx); CTX_LOCK(ctx); if ((err = IFDI_ATTACH_PRE(ctx)) != 0) { - CTX_UNLOCK(ctx); device_printf(dev, "IFDI_ATTACH_PRE failed %d\n", err); - return (err); + goto fail_unlock; } _iflib_pre_assert(scctx); ctx->ifc_txrx = *scctx->isc_txrx; @@ -4414,7 +4410,7 @@ /* round down instead? */ device_printf(dev, "# rx descriptors must be a power of 2\n"); err = EINVAL; - goto fail; + goto fail_iflib_detach; } } for (i = 0; i < sctx->isc_ntxqs; i++) { @@ -4422,7 +4418,7 @@ device_printf(dev, "# tx descriptors must be a power of 2"); err = EINVAL; - goto fail; + goto fail_iflib_detach; } } @@ -4492,7 +4488,7 @@ /* Get memory for the station queues */ if ((err = iflib_queues_alloc(ctx))) { device_printf(dev, "Unable to allocate queue memory\n"); - goto fail; + goto fail_intr_free; } if ((err = iflib_qset_structures_setup(ctx))) @@ -4511,7 +4507,7 @@ IFDI_INTR_DISABLE(ctx); if (msix > 1 && (err = IFDI_MSIX_INTR_ASSIGN(ctx, msix)) != 0) { device_printf(dev, "IFDI_MSIX_INTR_ASSIGN failed %d\n", err); - goto fail_intr_free; + goto fail_queues; } if (msix <= 1) { rid = 0; @@ -4521,7 +4517,7 @@ } if ((err = iflib_legacy_setup(ctx, ctx->isc_legacy_intr, ctx->ifc_softc, &rid, "irq0")) != 0) { device_printf(dev, "iflib_legacy_setup failed %d\n", err); - goto fail_intr_free; + goto fail_queues; } } @@ -4557,14 +4553,18 @@ fail_detach: ether_ifdetach(ctx->ifc_ifp); fail_intr_free: + iflib_free_intr_mem(ctx); fail_queues: iflib_tx_structures_free(ctx); iflib_rx_structures_free(ctx); -fail: - iflib_free_intr_mem(ctx); +fail_iflib_detach: IFDI_DETACH(ctx); +fail_unlock: CTX_UNLOCK(ctx); - +fail_ctx_free: + if (ctx->ifc_flags & IFC_SC_ALLOCATED) + free(ctx->ifc_softc, M_IFLIB); + free(ctx, M_IFLIB); return (err); } @@ -4593,9 +4593,7 @@ if ((err = iflib_register(ctx)) != 0) { device_printf(dev, "%s: iflib_register failed %d\n", __func__, err); - free(sc, M_IFLIB); - free(ctx, M_IFLIB); - return (err); + goto fail_ctx_free; } iflib_add_device_sysctl_pre(ctx); @@ -4609,14 +4607,14 @@ if ((err = IFDI_ATTACH_PRE(ctx)) != 0) { device_printf(dev, "IFDI_ATTACH_PRE failed %d\n", err); - return (err); + goto fail_ctx_free; } if (sctx->isc_flags & IFLIB_GEN_MAC) iflib_gen_mac(ctx); if ((err = IFDI_CLONEATTACH(ctx, clctx->cc_ifc, clctx->cc_name, clctx->cc_params)) != 0) { device_printf(dev, "IFDI_CLONEATTACH failed %d\n", err); - return (err); + goto fail_ctx_free; } ifmedia_add(&ctx->ifc_media, IFM_ETHER | IFM_1000_T | IFM_FDX, 0, NULL); ifmedia_add(&ctx->ifc_media, IFM_ETHER | IFM_AUTO, 0, NULL); @@ -4674,7 +4672,7 @@ /* round down instead? */ device_printf(dev, "# rx descriptors must be a power of 2\n"); err = EINVAL; - goto fail; + goto fail_iflib_detach; } } for (i = 0; i < sctx->isc_ntxqs; i++) { @@ -4682,7 +4680,7 @@ device_printf(dev, "# tx descriptors must be a power of 2"); err = EINVAL; - goto fail; + goto fail_iflib_detach; } } @@ -4728,7 +4726,7 @@ /* Get memory for the station queues */ if ((err = iflib_queues_alloc(ctx))) { device_printf(dev, "Unable to allocate queue memory\n"); - goto fail; + goto fail_iflib_detach; } if ((err = iflib_qset_structures_setup(ctx))) { @@ -4768,8 +4766,11 @@ fail_queues: iflib_tx_structures_free(ctx); iflib_rx_structures_free(ctx); -fail: +fail_iflib_detach: IFDI_DETACH(ctx); +fail_ctx_free: + free(ctx->ifc_softc, M_IFLIB); + free(ctx, M_IFLIB); return (err); }