diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
index 21cb0805f79ebbcfcc34e3ab549fabc6e69a750a..2357ebae9a20513b8e271e2b055c37f2c90ac8cb 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
@@ -1976,7 +1976,7 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP,
   for (lcid = UL_SCH_LCID_SRB1;
        lcid < MAX_LCID; lcid++) {
 
-    buflen_remain = buflen - (total_mac_pdu_header_len + sdu_length_total + MAX_RLC_SDU_SUBHEADER_SIZE);
+    buflen_remain = buflen - (total_mac_pdu_header_len + sdu_length_total + sh_size);
 
     LOG_D(NR_MAC, "In %s: [UE %d] [%d.%d] UL-DXCH -> ULSCH, RLC with LCID 0x%02x (TBS %d bytes, sdu_length_total %d bytes, MAC header len %d bytes, buflen_remain %d bytes)\n",
           __FUNCTION__,
@@ -2047,7 +2047,7 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP,
         break;
       }
 
-      buflen_remain = buflen - (total_mac_pdu_header_len + sdu_length_total + MAX_RLC_SDU_SUBHEADER_SIZE);
+      buflen_remain = buflen - (total_mac_pdu_header_len + sdu_length_total + sh_size);
 
     }
   }
@@ -2056,7 +2056,6 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP,
 
     LOG_D(NR_MAC, "In %s copying %d bytes of MAC CEs to the UL PDU \n", __FUNCTION__, tot_mac_ce_len);
     memcpy((void *) pdu, (void *) mac_header_control_elements, tot_mac_ce_len);
-    buflen_remain = buflen - (total_mac_pdu_header_len + sdu_length_total);
     pdu += (unsigned char) tot_mac_ce_len;
 
     #ifdef ENABLE_MAC_PAYLOAD_DEBUG
@@ -2066,6 +2065,8 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP,
 
   }
 
+  buflen_remain = buflen - (total_mac_pdu_header_len + sdu_length_total);
+
   // Compute final offset for padding and fill remainder of ULSCH with 0
   if (buflen_remain > 0) {