Skip to content

Commit

Permalink
zebra: Remove goto's that do not do anything special
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
donaldsharp committed Oct 8, 2022
1 parent 8614d57 commit e3296ff
Showing 1 changed file with 32 additions and 62 deletions.
94 changes: 32 additions & 62 deletions zebra/zebra_dplane.c
Original file line number Diff line number Diff line change
Expand Up @@ -2633,7 +2633,7 @@ int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
struct dplane_intf_extra *if_extra;

if (!ctx || !rn || !re)
goto done;
return ret;

TAILQ_INIT(&ctx->u.rinfo.intf_extra_q);

Expand Down Expand Up @@ -2724,8 +2724,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 */
if (op == DPLANE_OP_SYS_ROUTE_ADD ||
op == DPLANE_OP_SYS_ROUTE_DELETE) {
ret = AOK;
goto done;
return AOK;
}

/* Extract ns info - can't use pointers to 'core' structs */
Expand All @@ -2746,14 +2745,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
* matters for INSTALL/UPDATE.
*/
if (zebra_nhg_kernel_nexthops_enabled()
&& (((op == DPLANE_OP_ROUTE_INSTALL)
|| (op == DPLANE_OP_ROUTE_UPDATE))
&& !CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED)
&& !CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_QUEUED))) {
ret = ENOENT;
goto done;
}
if (zebra_nhg_kernel_nexthops_enabled() &&
(((op == DPLANE_OP_ROUTE_INSTALL) ||
(op == DPLANE_OP_ROUTE_UPDATE)) &&
!CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_INSTALLED) &&
!CHECK_FLAG(nhe->flags, NEXTHOP_GROUP_QUEUED)))
return ENOENT;

re->nhe_installed_id = nhe->id;
}
Expand All @@ -2765,10 +2762,7 @@ int dplane_ctx_route_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
re->dplane_sequence = zebra_router_get_next_sequence();
ctx->zd_seq = re->dplane_sequence;

ret = AOK;

done:
return ret;
return AOK;
}

int dplane_ctx_tc_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op)
Expand Down Expand Up @@ -2807,7 +2801,7 @@ int dplane_ctx_nexthop_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
int ret = EINVAL;

if (!ctx || !nhe)
goto done;
return ret;

ctx->zd_op = op;
ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS;
Expand Down Expand Up @@ -2842,7 +2836,6 @@ int dplane_ctx_nexthop_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,

ret = AOK;

done:
return ret;
}

Expand All @@ -2864,7 +2857,7 @@ int dplane_ctx_intf_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
bool set_pdown, unset_pdown;

if (!ctx || !ifp)
goto done;
return ret;

ctx->zd_op = op;
ctx->zd_status = ZEBRA_DPLANE_REQUEST_SUCCESS;
Expand Down Expand Up @@ -2909,7 +2902,6 @@ int dplane_ctx_intf_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,

ret = AOK;

done:
return ret;
}

Expand Down Expand Up @@ -2937,10 +2929,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
* to copy an lsp object.
*/
if (lsp == NULL) {
ret = AOK;
goto done;
}
if (lsp == NULL)
return ret;

if (IS_ZEBRA_DEBUG_DPLANE_DETAIL)
zlog_debug("init dplane ctx %s: in-label %u ecmp# %d",
Expand Down Expand Up @@ -2983,7 +2973,7 @@ int dplane_ctx_lsp_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
}

if (ret != AOK)
goto done;
return ret;

/* Capture backup nhlfes/nexthops */
frr_each(nhlfe_list, &lsp->backup_nhlfe_list, nhlfe) {
Expand All @@ -3004,11 +2994,6 @@ int dplane_ctx_lsp_init(struct zebra_dplane_ctx *ctx, enum dplane_op_e op,
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;
}

Expand Down Expand Up @@ -3069,11 +3054,11 @@ static int dplane_ctx_pw_init(struct zebra_dplane_ctx *ctx,
afi = (pw->af == AF_INET) ? AFI_IP : AFI_IP6;
table = zebra_vrf_table(afi, SAFI_UNICAST, pw->vrf_id);
if (table == NULL)
goto done;
return ret;

rn = route_node_match(table, &p);
if (rn == NULL)
goto done;
return ret;

re = NULL;
RNODE_FOREACH_RE(rn, re) {
Expand Down Expand Up @@ -3141,10 +3126,7 @@ static int dplane_ctx_pw_init(struct zebra_dplane_ctx *ctx,
}
route_unlock_node(rn);

ret = AOK;

done:
return ret;
return AOK;
}

/**
Expand Down Expand Up @@ -3602,12 +3584,11 @@ enum zebra_dplane_result dplane_route_add(struct route_node *rn,
enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE;

if (rn == NULL || re == NULL)
goto done;
return ret;

ret = dplane_route_update_internal(rn, re, NULL,
DPLANE_OP_ROUTE_INSTALL);

done:
return ret;
}

Expand All @@ -3621,11 +3602,11 @@ enum zebra_dplane_result dplane_route_update(struct route_node *rn,
enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE;

if (rn == NULL || re == NULL)
goto done;
return ret;

ret = dplane_route_update_internal(rn, re, old_re,
DPLANE_OP_ROUTE_UPDATE);
done:

return ret;
}

Expand All @@ -3638,12 +3619,11 @@ enum zebra_dplane_result dplane_route_delete(struct route_node *rn,
enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE;

if (rn == NULL || re == NULL)
goto done;
return ret;

ret = dplane_route_update_internal(rn, re, NULL,
DPLANE_OP_ROUTE_DELETE);

done:
return ret;
}

Expand All @@ -3656,18 +3636,16 @@ enum zebra_dplane_result dplane_sys_route_add(struct route_node *rn,
enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE;

/* Ignore this event unless a provider plugin has requested it. */
if (!zdplane_info.dg_sys_route_notifs) {
ret = ZEBRA_DPLANE_REQUEST_SUCCESS;
goto done;
}
if (!zdplane_info.dg_sys_route_notifs)
return ZEBRA_DPLANE_REQUEST_SUCCESS;


if (rn == NULL || re == NULL)
goto done;
return ret;

ret = dplane_route_update_internal(rn, re, NULL,
DPLANE_OP_SYS_ROUTE_ADD);

done:
return ret;
}

Expand All @@ -3680,18 +3658,15 @@ enum zebra_dplane_result dplane_sys_route_del(struct route_node *rn,
enum zebra_dplane_result ret = ZEBRA_DPLANE_REQUEST_FAILURE;

/* Ignore this event unless a provider plugin has requested it. */
if (!zdplane_info.dg_sys_route_notifs) {
ret = ZEBRA_DPLANE_REQUEST_SUCCESS;
goto done;
}
if (!zdplane_info.dg_sys_route_notifs)
return ZEBRA_DPLANE_REQUEST_SUCCESS;

if (rn == NULL || re == NULL)
goto done;
return ret;

ret = dplane_route_update_internal(rn, re, NULL,
DPLANE_OP_SYS_ROUTE_DELETE);

done:
return ret;
}

Expand Down Expand Up @@ -6109,7 +6084,7 @@ int dplane_clean_ctx_queue(bool (*context_cb)(struct zebra_dplane_ctx *ctx,
TAILQ_INIT(&work_list);

if (context_cb == NULL)
goto done;
return AOK;

/* Walk the pending context queue under the dplane lock. */
DPLANE_LOCK();
Expand All @@ -6133,9 +6108,7 @@ int dplane_clean_ctx_queue(bool (*context_cb)(struct zebra_dplane_ctx *ctx,
dplane_ctx_fini(&ctx);
}

done:

return 0;
return AOK;
}

/* Indicates zebra shutdown/exit is in progress. Some operations may be
Expand Down Expand Up @@ -6199,10 +6172,8 @@ static bool dplane_work_pending(void)
}
DPLANE_UNLOCK();

if (ctx != NULL) {
ret = true;
goto done;
}
if (ctx != NULL)
return true;

while (prov) {

Expand All @@ -6225,7 +6196,6 @@ static bool dplane_work_pending(void)
if (ctx != NULL)
ret = true;

done:
return ret;
}

Expand Down

0 comments on commit e3296ff

Please sign in to comment.