From 38b387794e43ae8af46bc32cf792400328511be9 Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Thu, 19 Jan 2017 09:57:43 +0100
Subject: [PATCH] hack in RLC AM to avoid a race

Here is the problem:
    UE comes. SRB2 is configured via message to RRC.
    At some point the RLC AM is created but not configured yet.
    At this moment (I think) MAC calls mac_rlc_status_ind
    which calls this function. But the init was not finished yet
    and we have a crash below when testing mem_block != NULL.

The "solution" is to test if rlc->input_sdus is NULL.
This is a very dirty hack. I would say the solution
is to use proper locking mechanism because RLC is used
by two threads: PHY/MAC on one hand and RRC on another
hand (I think).
---
 openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.c
index 1d930554873..4051a88ef29 100644
--- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.c
+++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am.c
@@ -557,6 +557,15 @@ rlc_am_mac_status_indication (
   status_resp.head_sdu_is_segmented            = 0;
   status_resp.rlc_info.rlc_protocol_state = rlc->protocol_state;
 
+  /* TODO: remove this hack. Problem is: there is a race.
+   * UE comes. SRB2 is configured via message to RRC.
+   * At some point the RLC AM is created but not configured yet.
+   * At this moment (I think) MAC calls mac_rlc_status_ind
+   * which calls this function. But the init was not finished yet
+   * and we have a crash below when testing mem_block != NULL.
+   */
+  if (rlc->input_sdus == NULL) return status_resp;
+
   if (rlc->last_frame_status_indication != ctxt_pP->frame) {
     rlc_am_check_timer_poll_retransmit(ctxt_pP, rlc);
     rlc_am_check_timer_reordering(ctxt_pP, rlc);
-- 
GitLab