zebra: Remove goto's that do not do anything special

If we have this semantics:

int ret = FAILURE;

if (foo)
    goto done;

....

done:
    return ret;

This pattern does us no favors and makes it harder to figure out what is going
on.  Let's remove.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2022-10-03 13:13:50 -04:00
parent 7d83e13937
commit c7f0429e81

View File

@ -2784,7 +2784,7 @@ int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
struct dplane_intf_extra *if_extra; struct dplane_intf_extra *if_extra;
if (!ctx || !rn || !re) if (!ctx || !rn || !re)
goto done; return ret;
TAILQ_INIT(&ctx->u.rinfo.intf_extra_q); TAILQ_INIT(&ctx->u.rinfo.intf_extra_q);
@ -2875,8 +2875,7 @@ int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
/* Don't need some info when capturing a system notification */ /* Don't need some info when capturing a system notification */
if (op == DPLANE_OP_SYS_ROUTE_ADD || if (op == DPLANE_OP_SYS_ROUTE_ADD ||
op == DPLANE_OP_SYS_ROUTE_DELETE) { op == DPLANE_OP_SYS_ROUTE_DELETE) {
ret = AOK; return AOK;
goto done;
} }
/* Extract ns info - can't use pointers to 'core' structs */ /* Extract ns info - can't use pointers to 'core' structs */
@ -2897,14 +2896,12 @@ int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
* If its a delete we only use the prefix anyway, so this only * If its a delete we only use the prefix anyway, so this only
* matters for INSTALL/UPDATE. * matters for INSTALL/UPDATE.
*/ */
if (zebra_nhg_kernel_nexthops_enabled() if (zebra_nhg_kernel_nexthops_enabled() &&
&& (((op == DPLANE_OP_ROUTE_INSTALL) (((op == DPLANE_OP_ROUTE_INSTALL) ||
|| (op == DPLANE_OP_ROUTE_UPDATE)) (op == DPLANE_OP_ROUTE_UPDATE)) &&
&& !CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED) !CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED) &&
&& !CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_QUEUED))) { !CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_QUEUED)))
ret = ENOENT; return ENOENT;
goto done;
}
re->nhe_installed_id = nhe->id; re->nhe_installed_id = nhe->id;
} }
@ -2916,10 +2913,7 @@ int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
re->dplane_sequence = zebra_router_get_next_sequence(); re->dplane_sequence = zebra_router_get_next_sequence();
ctx->zd_seq = re->dplane_sequence; ctx->zd_seq = re->dplane_sequence;
ret = AOK; return AOK;
done:
return ret;
} }
static int dplane_ctx_tc_qdisc_init(struct zebra_dplane_ctx *ctx, static int dplane_ctx_tc_qdisc_init(struct zebra_dplane_ctx *ctx,
@ -3031,7 +3025,7 @@ int dplane_ctx_nexthop_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
int ret = EINVAL; int ret = EINVAL;
if (!ctx || !nhe) if (!ctx || !nhe)
goto done; return ret;
ctx->zd_op = op; ctx->zd_op = op;
ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS;
@ -3066,7 +3060,6 @@ int dplane_ctx_nexthop_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
ret = AOK; ret = AOK;
done:
return ret; return ret;
} }
@ -3088,7 +3081,7 @@ int dplane_ctx_intf_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
bool set_pdown, unset_pdown; bool set_pdown, unset_pdown;
if (!ctx || !ifp) if (!ctx || !ifp)
goto done; return ret;
ctx->zd_op = op; ctx->zd_op = op;
ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS; ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS;
@ -3133,7 +3126,6 @@ int dplane_ctx_intf_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
ret = AOK; ret = AOK;
done:
return ret; return ret;
} }
@ -3161,10 +3153,8 @@ int dplane_ctx_lsp_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
/* This may be called to create/init a dplane context, not necessarily /* This may be called to create/init a dplane context, not necessarily
* to copy an lsp object. * to copy an lsp object.
*/ */
if (lsp == NULL) { if (lsp == NULL)
ret = AOK; return ret;
goto done;
}
if (IS_ZEBRA_DEBUG_DPLANE_DETAIL) if (IS_ZEBRA_DEBUG_DPLANE_DETAIL)
zlog_debug("init dplane ctx %s: in-label %u ecmp# %d", zlog_debug("init dplane ctx %s: in-label %u ecmp# %d",
@ -3207,7 +3197,7 @@ int dplane_ctx_lsp_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
} }
if (ret != AOK) if (ret != AOK)
goto done; return ret;
/* Capture backup nhlfes/nexthops */ /* Capture backup nhlfes/nexthops */
frr_each(nhlfe_list, &lsp->backup_nhlfe_list, nhlfe) { frr_each(nhlfe_list, &lsp->backup_nhlfe_list, nhlfe) {
@ -3228,11 +3218,6 @@ int dplane_ctx_lsp_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
new_nhlfe->nexthop->flags = nhlfe->nexthop->flags; new_nhlfe->nexthop->flags = nhlfe->nexthop->flags;
} }
/* On error the ctx will be cleaned-up, so we don't need to
* deal with any allocated nhlfe or nexthop structs here.
*/
done:
return ret; return ret;
} }
@ -3293,11 +3278,11 @@ static int dplane_ctx_pw_init(struct zebra_dplane_ctx *ctx,
afi = (pw->af == AF_INET) ? AFI_IP : AFI_IP6; afi = (pw->af == AF_INET) ? AFI_IP : AFI_IP6;
table = zebra_vrf_table(afi, SAFI_UNICAST, pw->vrf_id); table = zebra_vrf_table(afi, SAFI_UNICAST, pw->vrf_id);
if (table == NULL) if (table == NULL)
goto done; return ret;
rn = route_node_match(table, &p); rn = route_node_match(table, &p);
if (rn == NULL) if (rn == NULL)
goto done; return ret;
re = NULL; re = NULL;
RNODE_FOREACH_RE(rn, re) { RNODE_FOREACH_RE(rn, re) {
@ -3365,10 +3350,7 @@ static int dplane_ctx_pw_init(struct zebra_dplane_ctx *ctx,
} }
route_unlock_node(rn); route_unlock_node(rn);
ret = AOK; return AOK;
done:
return ret;
} }
/** /**
@ -3943,12 +3925,11 @@ enum zebra_dplane_result dplane_route_add(struct route_node *rn,
enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE;
if (rn == NULL || re == NULL) if (rn == NULL || re == NULL)
goto done; return ret;
ret = dplane_route_update_internal(rn, re, NULL, ret = dplane_route_update_internal(rn, re, NULL,
DPLANE_OP_ROUTE_INSTALL); DPLANE_OP_ROUTE_INSTALL);
done:
return ret; return ret;
} }
@ -3962,11 +3943,11 @@ enum zebra_dplane_result dplane_route_update(struct route_node *rn,
enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE;
if (rn == NULL || re == NULL) if (rn == NULL || re == NULL)
goto done; return ret;
ret = dplane_route_update_internal(rn, re, old_re, ret = dplane_route_update_internal(rn, re, old_re,
DPLANE_OP_ROUTE_UPDATE); DPLANE_OP_ROUTE_UPDATE);
done:
return ret; return ret;
} }
@ -3979,12 +3960,11 @@ enum zebra_dplane_result dplane_route_delete(struct route_node *rn,
enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE;
if (rn == NULL || re == NULL) if (rn == NULL || re == NULL)
goto done; return ret;
ret = dplane_route_update_internal(rn, re, NULL, ret = dplane_route_update_internal(rn, re, NULL,
DPLANE_OP_ROUTE_DELETE); DPLANE_OP_ROUTE_DELETE);
done:
return ret; return ret;
} }
@ -3997,18 +3977,16 @@ enum zebra_dplane_result dplane_sys_route_add(struct route_node *rn,
enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE;
/* Ignore this event unless a provider plugin has requested it. */ /* Ignore this event unless a provider plugin has requested it. */
if (!zdplane_info.dg_sys_route_notifs) { if (!zdplane_info.dg_sys_route_notifs)
ret = ZEBRA_DPLANE_REQUEST_SUCCESS; return ZEBRA_DPLANE_REQUEST_SUCCESS;
goto done;
}
if (rn == NULL || re == NULL) if (rn == NULL || re == NULL)
goto done; return ret;
ret = dplane_route_update_internal(rn, re, NULL, ret = dplane_route_update_internal(rn, re, NULL,
DPLANE_OP_SYS_ROUTE_ADD); DPLANE_OP_SYS_ROUTE_ADD);
done:
return ret; return ret;
} }
@ -4021,18 +3999,15 @@ enum zebra_dplane_result dplane_sys_route_del(struct route_node *rn,
enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE; enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE;
/* Ignore this event unless a provider plugin has requested it. */ /* Ignore this event unless a provider plugin has requested it. */
if (!zdplane_info.dg_sys_route_notifs) { if (!zdplane_info.dg_sys_route_notifs)
ret = ZEBRA_DPLANE_REQUEST_SUCCESS; return ZEBRA_DPLANE_REQUEST_SUCCESS;
goto done;
}
if (rn == NULL || re == NULL) if (rn == NULL || re == NULL)
goto done; return ret;
ret = dplane_route_update_internal(rn, re, NULL, ret = dplane_route_update_internal(rn, re, NULL,
DPLANE_OP_SYS_ROUTE_DELETE); DPLANE_OP_SYS_ROUTE_DELETE);
done:
return ret; return ret;
} }
@ -6463,7 +6438,7 @@ int dplane_clean_ctx_queue(bool (*context_cb)(struct zebra_dplane_ctx *ctx,
TAILQ_INIT(&work_list); TAILQ_INIT(&work_list);
if (context_cb == NULL) if (context_cb == NULL)
goto done; return AOK;
/* Walk the pending context queue under the dplane lock. */ /* Walk the pending context queue under the dplane lock. */
DPLANE_LOCK(); DPLANE_LOCK();
@ -6487,9 +6462,7 @@ int dplane_clean_ctx_queue(bool (*context_cb)(struct zebra_dplane_ctx *ctx,
dplane_ctx_fini(&ctx); dplane_ctx_fini(&ctx);
} }
done: return AOK;
return 0;
} }
/* Indicates zebra shutdown/exit is in progress. Some operations may be /* Indicates zebra shutdown/exit is in progress. Some operations may be
@ -6553,10 +6526,8 @@ static bool dplane_work_pending(void)
} }
DPLANE_UNLOCK(); DPLANE_UNLOCK();
if (ctx != NULL) { if (ctx != NULL)
ret = true; return true;
goto done;
}
while (prov) { while (prov) {
@ -6579,7 +6550,6 @@ static bool dplane_work_pending(void)
if (ctx != NULL) if (ctx != NULL)
ret = true; ret = true;
done:
return ret; return ret;
} }