mirror of https://gerrit.osmocom.org/libosmocore
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."
This commit is contained in:
parent
73fa6427aa
commit
9b037a6a7a
|
@ -150,10 +150,8 @@ static void lapd_dl_flush_send(struct lapd_datalink *dl)
|
||||||
msgb_free(msg);
|
msgb_free(msg);
|
||||||
|
|
||||||
/* Clear send-buffer */
|
/* Clear send-buffer */
|
||||||
if (dl->send_buffer) {
|
msgb_free(dl->send_buffer);
|
||||||
msgb_free(dl->send_buffer);
|
dl->send_buffer = NULL;
|
||||||
dl->send_buffer = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lapd_dl_flush_hist(struct lapd_datalink *dl)
|
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 */
|
/* stop T203 on leaving MF EST state, if running */
|
||||||
lapd_stop_t203(dl);
|
lapd_stop_t203(dl);
|
||||||
/* remove content res. (network side) on leaving MF EST state */
|
/* remove content res. (network side) on leaving MF EST state */
|
||||||
if (dl->cont_res) {
|
msgb_free(dl->cont_res);
|
||||||
msgb_free(dl->cont_res);
|
dl->cont_res = NULL;
|
||||||
dl->cont_res = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* start T203 on entering MF EST state, if enabled */
|
/* 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_tx(dl);
|
||||||
lapd_dl_flush_send(dl);
|
lapd_dl_flush_send(dl);
|
||||||
/* Discard partly received L3 message */
|
/* Discard partly received L3 message */
|
||||||
if (dl->rcv_buffer) {
|
msgb_free(dl->rcv_buffer);
|
||||||
msgb_free(dl->rcv_buffer);
|
dl->rcv_buffer = NULL;
|
||||||
dl->rcv_buffer = NULL;
|
|
||||||
}
|
|
||||||
/* stop Timers */
|
/* stop Timers */
|
||||||
lapd_stop_t200(dl);
|
lapd_stop_t200(dl);
|
||||||
lapd_stop_t203(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));
|
memcpy(&dl->lctx, lctx, sizeof(dl->lctx));
|
||||||
|
|
||||||
/* Discard partly received L3 message */
|
/* Discard partly received L3 message */
|
||||||
if (dl->rcv_buffer) {
|
msgb_free(dl->rcv_buffer);
|
||||||
msgb_free(dl->rcv_buffer);
|
dl->rcv_buffer = NULL;
|
||||||
dl->rcv_buffer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* assemble message */
|
/* assemble message */
|
||||||
memcpy(&nctx, &dl->lctx, sizeof(nctx));
|
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));
|
memcpy(&dl->lctx, lctx, sizeof(dl->lctx));
|
||||||
|
|
||||||
/* Replace message in the send-buffer (reconnect) */
|
/* 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;
|
dl->send_out = 0;
|
||||||
if (msg->len) {
|
if (msg->len) {
|
||||||
/* Write data into the send buffer, to be sent first */
|
/* 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 */
|
/* Discard partly received L3 message */
|
||||||
if (dl->rcv_buffer) {
|
msgb_free(dl->rcv_buffer);
|
||||||
msgb_free(dl->rcv_buffer);
|
dl->rcv_buffer = NULL;
|
||||||
dl->rcv_buffer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create new msgb (old one is now free) */
|
/* Create new msgb (old one is now free) */
|
||||||
msg = lapd_msgb_alloc(0, "LAPD SABM");
|
msg = lapd_msgb_alloc(0, "LAPD SABM");
|
||||||
|
|
Loading…
Reference in New Issue