From: Rafael Zalamena Date: Mon, 13 Apr 2020 17:23:03 +0000 (-0300) Subject: bfdd: simplify code flow X-Git-Tag: base_7.4~84^2~5 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=08de92aff34ac1734633a99aed543657e1069192;p=matthieu%2Ffrr.git bfdd: simplify code flow Don't attempt to handle out-of-memory situations: XMALLOC/XCALLOC will `assert` if there is no memory left. Signed-off-by: Rafael Zalamena --- diff --git a/bfdd/bfd.c b/bfdd/bfd.c index 80bfae632f..0d2c61ac7d 100644 --- a/bfdd/bfd.c +++ b/bfdd/bfd.c @@ -526,8 +526,7 @@ int bfd_session_update_label(struct bfd_session *bs, const char *nlabel) return -1; } - if (pl_new(nlabel, bs) == NULL) - return -1; + pl_new(nlabel, bs); return 0; } @@ -685,10 +684,6 @@ struct bfd_session *ptm_bfd_sess_new(struct bfd_peer_cfg *bpc) /* Get BFD session storage with its defaults. */ bfd = bfd_session_new(); - if (bfd == NULL) { - zlog_err("session-new: allocation failed"); - return NULL; - } /* * Store interface/VRF name in case we need to delay session diff --git a/bfdd/bfdd_nb_config.c b/bfdd/bfdd_nb_config.c index c1123c4c33..7b95bd23c6 100644 --- a/bfdd/bfdd_nb_config.c +++ b/bfdd/bfdd_nb_config.c @@ -107,8 +107,6 @@ static int bfd_session_create(enum nb_event event, const struct lyd_node *dnode, } bs = bfd_session_new(); - if (bs == NULL) - return NB_ERR_RESOURCE; /* Fill the session key. */ bfd_session_get_key(mhop, dnode, &bs->key); diff --git a/bfdd/control.c b/bfdd/control.c index 4adc54a64a..3b954c64f8 100644 --- a/bfdd/control.c +++ b/bfdd/control.c @@ -168,8 +168,7 @@ int control_accept(struct thread *t) return 0; } - if (control_new(csock) == NULL) - close(csock); + control_new(csock); bglobal.bg_csockev = NULL; thread_add_read(master, control_accept, NULL, sd, &bglobal.bg_csockev); @@ -334,8 +333,6 @@ static int control_queue_enqueue(struct bfd_control_socket *bcs, struct bfd_control_buffer *bcb; bcq = control_queue_new(bcs); - if (bcq == NULL) - return -1; bcb = &bcq->bcq_bcb; bcb->bcb_left = sizeof(struct bfd_control_msg) + ntohl(bcm->bcm_length); @@ -656,8 +653,7 @@ static int notify_add_cb(struct bfd_peer_cfg *bpc, void *arg) if (bs == NULL) return -1; - if (control_notifypeer_new(bcs, bs) == NULL) - return -1; + control_notifypeer_new(bcs, bs); /* Notify peer status. */ _control_notify(bcs, bs); diff --git a/bfdd/ptm_adapter.c b/bfdd/ptm_adapter.c index 0f1c4d06c0..d3fb26c348 100644 --- a/bfdd/ptm_adapter.c +++ b/bfdd/ptm_adapter.c @@ -315,10 +315,6 @@ static int _ptm_msg_read(struct stream *msg, int command, vrf_id_t vrf_id, STREAM_GETL(msg, pid); *pc = pc_new(pid); - if (*pc == NULL) { - zlog_debug("ptm-read: failed to allocate memory"); - return -1; - } /* Register/update peer information. */ _ptm_msg_read_address(msg, &bpc->bpc_peer); @@ -404,7 +400,6 @@ stream_failure: static void bfdd_dest_register(struct stream *msg, vrf_id_t vrf_id) { struct ptm_client *pc; - struct ptm_client_notification *pcn; struct bfd_session *bs; struct bfd_peer_cfg bpc; @@ -432,11 +427,7 @@ static void bfdd_dest_register(struct stream *msg, vrf_id_t vrf_id) } /* Create client peer notification register. */ - pcn = pcn_new(pc, bs); - if (pcn == NULL) { - zlog_err("ptm-add-dest: failed to registrate notifications"); - return; - } + pcn_new(pc, bs); ptm_bfd_notify(bs, bs->ses_state); } @@ -481,17 +472,12 @@ static void bfdd_dest_deregister(struct stream *msg, vrf_id_t vrf_id) */ static void bfdd_client_register(struct stream *msg) { - struct ptm_client *pc; uint32_t pid; /* Find or allocate process context data. */ STREAM_GETL(msg, pid); - pc = pc_new(pid); - if (pc == NULL) { - zlog_err("ptm-add-client: failed to register client: %u", pid); - return; - } + pc_new(pid); return;