diff --git a/openair3/NAS/COMMON/EMM/MSG/emm_msg.c b/openair3/NAS/COMMON/EMM/MSG/emm_msg.c
index b067b9c0d1584929fdcab190bca92de17e470af9..c357e8784f803827e9e83041033472d1b571bb86 100644
--- a/openair3/NAS/COMMON/EMM/MSG/emm_msg.c
+++ b/openair3/NAS/COMMON/EMM/MSG/emm_msg.c
@@ -464,6 +464,9 @@ int emm_msg_encode(EMM_msg *msg, uint8_t *buffer, uint32_t len)
 #endif
   }
 
+  if (encode_result < 0)
+    LOG_FUNC_RETURN (encode_result);
+
   LOG_FUNC_RETURN (header_result + encode_result);
 }