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."
diff --git a/src/gsm/lapd_core.c b/src/gsm/lapd_core.c
index 3288ee8..ccfa4b4 100644
--- a/src/gsm/lapd_core.c
+++ b/src/gsm/lapd_core.c
@@ -150,10 +150,8 @@
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 @@
/* 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 @@
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 @@
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 @@
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 @@
}
/* 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");