From 9b037a6a7a16bf580906e3197a54a366ac26060c Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 11 Jul 2013 08:17:02 +0200 Subject: lapd: Remove the double NULL check idiom with msgb_free if (ptr) msgb_free(ptr) extends to: if (ptr) talloc_free(ptr) And according to the talloc documentation a talloc_free(NULL) will not crash: "... Likewise, if "ptr" is NULL, then the function will make no modifications and returns -1." --- src/gsm/lapd_core.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'src/gsm') diff --git a/src/gsm/lapd_core.c b/src/gsm/lapd_core.c index 3288ee86..ccfa4b43 100644 --- a/src/gsm/lapd_core.c +++ b/src/gsm/lapd_core.c @@ -150,10 +150,8 @@ static void lapd_dl_flush_send(struct lapd_datalink *dl) msgb_free(msg); /* Clear send-buffer */ - if (dl->send_buffer) { - msgb_free(dl->send_buffer); - dl->send_buffer = NULL; - } + msgb_free(dl->send_buffer); + dl->send_buffer = NULL; } static void lapd_dl_flush_hist(struct lapd_datalink *dl) @@ -232,10 +230,8 @@ static void lapd_dl_newstate(struct lapd_datalink *dl, uint32_t state) /* stop T203 on leaving MF EST state, if running */ lapd_stop_t203(dl); /* remove content res. (network side) on leaving MF EST state */ - if (dl->cont_res) { - msgb_free(dl->cont_res); - dl->cont_res = NULL; - } + msgb_free(dl->cont_res); + dl->cont_res = NULL; } /* start T203 on entering MF EST state, if enabled */ @@ -311,10 +307,8 @@ void lapd_dl_reset(struct lapd_datalink *dl) lapd_dl_flush_tx(dl); lapd_dl_flush_send(dl); /* Discard partly received L3 message */ - if (dl->rcv_buffer) { - msgb_free(dl->rcv_buffer); - dl->rcv_buffer = NULL; - } + msgb_free(dl->rcv_buffer); + dl->rcv_buffer = NULL; /* stop Timers */ lapd_stop_t200(dl); lapd_stop_t203(dl); @@ -1703,10 +1697,8 @@ static int lapd_est_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx) memcpy(&dl->lctx, lctx, sizeof(dl->lctx)); /* Discard partly received L3 message */ - if (dl->rcv_buffer) { - msgb_free(dl->rcv_buffer); - dl->rcv_buffer = NULL; - } + msgb_free(dl->rcv_buffer); + dl->rcv_buffer = NULL; /* assemble message */ memcpy(&nctx, &dl->lctx, sizeof(nctx)); @@ -1959,8 +1951,9 @@ static int lapd_res_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx) memcpy(&dl->lctx, lctx, sizeof(dl->lctx)); /* Replace message in the send-buffer (reconnect) */ - if (dl->send_buffer) - msgb_free(dl->send_buffer); + msgb_free(dl->send_buffer); + dl->send_buffer = NULL; + dl->send_out = 0; if (msg->len) { /* Write data into the send buffer, to be sent first */ @@ -1972,10 +1965,8 @@ static int lapd_res_req(struct osmo_dlsap_prim *dp, struct lapd_msg_ctx *lctx) } /* Discard partly received L3 message */ - if (dl->rcv_buffer) { - msgb_free(dl->rcv_buffer); - dl->rcv_buffer = NULL; - } + msgb_free(dl->rcv_buffer); + dl->rcv_buffer = NULL; /* Create new msgb (old one is now free) */ msg = lapd_msgb_alloc(0, "LAPD SABM"); -- cgit v1.2.3