Commit 9001ad2d authored by Robert Schmidt's avatar Robert Schmidt

Correct calloc_or_fail() signature

parent 9a57514b
...@@ -568,8 +568,6 @@ void itti_set_task_real_time(task_id_t task_id); ...@@ -568,8 +568,6 @@ void itti_set_task_real_time(task_id_t task_id);
void itti_send_terminate_message(task_id_t task_id); void itti_send_terminate_message(task_id_t task_id);
void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize_t size); void *itti_malloc(task_id_t origin_task_id, task_id_t destination_task_id, ssize_t size);
void *calloc_or_fail(size_t size);
void *malloc_or_fail(size_t size);
int memory_read(const char *datafile, void *data, size_t size); int memory_read(const char *datafile, void *data, size_t size);
int itti_free(task_id_t task_id, void *ptr); int itti_free(task_id_t task_id, void *ptr);
......
...@@ -56,23 +56,24 @@ static inline void *malloc16_clear( size_t size ) { ...@@ -56,23 +56,24 @@ static inline void *malloc16_clear( size_t size ) {
return ptr; return ptr;
} }
static inline void *calloc_or_fail(size_t nmemb, size_t size)
static inline void *calloc_or_fail(size_t size) { {
void *ptr = calloc(1, size); void *ptr = calloc(nmemb, size);
if (ptr == NULL) { if (ptr == NULL) {
fprintf(stderr, "[UE] Failed to calloc %zu bytes", size); fprintf(stderr, "Failed to calloc() %zu elements of %zu bytes: out of memory", nmemb, size);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
return ptr; return ptr;
} }
static inline void *malloc_or_fail(size_t size) { static inline void *malloc_or_fail(size_t size)
{
void *ptr = malloc(size); void *ptr = malloc(size);
if (ptr == NULL) { if (ptr == NULL) {
fprintf(stderr, "[UE] Failed to malloc %zu bytes", size); fprintf(stderr, "Failed to malloc() %zu bytes: out of memory", size);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
......
...@@ -107,7 +107,7 @@ static IdleMode_callback_t _emm_indication_notify; ...@@ -107,7 +107,7 @@ static IdleMode_callback_t _emm_indication_notify;
***************************************************************************/ ***************************************************************************/
void IdleMode_initialize(nas_user_t *user, IdleMode_callback_t cb) void IdleMode_initialize(nas_user_t *user, IdleMode_callback_t cb)
{ {
emm_plmn_list_t *emm_plmn_list = calloc_or_fail( sizeof(emm_plmn_list_t)); emm_plmn_list_t *emm_plmn_list = calloc_or_fail(1, sizeof(emm_plmn_list_t));
user->emm_plmn_list = emm_plmn_list; user->emm_plmn_list = emm_plmn_list;
/* Initialize the list of available PLMNs */ /* Initialize the list of available PLMNs */
emm_plmn_list->n_plmns = 0; emm_plmn_list->n_plmns = 0;
......
...@@ -135,7 +135,7 @@ void _emm_detach_initialize(emm_detach_data_t *emm_detach) { ...@@ -135,7 +135,7 @@ void _emm_detach_initialize(emm_detach_data_t *emm_detach) {
void emm_main_initialize(nas_user_t *user, emm_indication_callback_t cb, const char *imei) void emm_main_initialize(nas_user_t *user, emm_indication_callback_t cb, const char *imei)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
user->emm_data = calloc_or_fail(sizeof(emm_data_t)); user->emm_data = calloc_or_fail(1, sizeof(emm_data_t));
/* USIM validity indicator */ /* USIM validity indicator */
user->emm_data->usim_is_valid = false; user->emm_data->usim_is_valid = false;
/* The IMEI read from the UE's non-volatile memory */ /* The IMEI read from the UE's non-volatile memory */
...@@ -433,19 +433,19 @@ void emm_main_initialize(nas_user_t *user, emm_indication_callback_t cb, const c ...@@ -433,19 +433,19 @@ void emm_main_initialize(nas_user_t *user, emm_indication_callback_t cb, const c
/* /*
* Initialize EMM timers * Initialize EMM timers
*/ */
user->emm_data->emm_timers = calloc_or_fail(sizeof(emm_timers_t)); user->emm_data->emm_timers = calloc_or_fail(1, sizeof(emm_timers_t));
_emm_timers_initialize(user->emm_data->emm_timers); _emm_timers_initialize(user->emm_data->emm_timers);
/* /*
* Initialize Internal data used for detach procedure * Initialize Internal data used for detach procedure
*/ */
user->emm_data->emm_detach_data = calloc_or_fail(sizeof(emm_detach_data_t)); user->emm_data->emm_detach_data = calloc_or_fail(1, sizeof(emm_detach_data_t));
_emm_detach_initialize(user->emm_data->emm_detach_data); _emm_detach_initialize(user->emm_data->emm_detach_data);
/* /*
* Initialize Internal data used for attach procedure * Initialize Internal data used for attach procedure
*/ */
user->emm_data->emm_attach_data = calloc_or_fail(sizeof(emm_attach_data_t)); user->emm_data->emm_attach_data = calloc_or_fail(1, sizeof(emm_attach_data_t));
_emm_attach_initialize(user->emm_data->emm_attach_data); _emm_attach_initialize(user->emm_data->emm_attach_data);
/* /*
......
...@@ -119,7 +119,7 @@ esm_ebr_data_t *esm_ebr_initialize(void) ...@@ -119,7 +119,7 @@ esm_ebr_data_t *esm_ebr_initialize(void)
LOG_FUNC_IN; LOG_FUNC_IN;
int i; int i;
esm_ebr_data_t *esm_ebr_data = calloc_or_fail(sizeof(esm_ebr_data_t)); esm_ebr_data_t *esm_ebr_data = calloc_or_fail(1, sizeof(esm_ebr_data_t));
esm_ebr_data->index = 0; esm_ebr_data->index = 0;
......
...@@ -79,7 +79,7 @@ void esm_main_initialize(nas_user_t *user, esm_indication_callback_t cb) ...@@ -79,7 +79,7 @@ void esm_main_initialize(nas_user_t *user, esm_indication_callback_t cb)
int i; int i;
esm_data_t *esm_data = calloc_or_fail(sizeof(esm_data_t)); esm_data_t *esm_data = calloc_or_fail(1, sizeof(esm_data_t));
user->esm_data = esm_data; user->esm_data = esm_data;
default_eps_bearer_context_data_t *default_eps_bearer_context = calloc(1, sizeof(default_eps_bearer_context_data_t)); default_eps_bearer_context_data_t *default_eps_bearer_context = calloc(1, sizeof(default_eps_bearer_context_data_t));
......
...@@ -88,7 +88,7 @@ static int _esm_pt_get_available_entry(esm_pt_data_t *esm_pt_data); ...@@ -88,7 +88,7 @@ static int _esm_pt_get_available_entry(esm_pt_data_t *esm_pt_data);
esm_pt_data_t *esm_pt_initialize(void) esm_pt_data_t *esm_pt_initialize(void)
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
esm_pt_data_t *esm_pt_data = calloc_or_fail(sizeof(esm_pt_data_t)); esm_pt_data_t *esm_pt_data = calloc_or_fail(1, sizeof(esm_pt_data_t));
int i; int i;
esm_pt_data->index = 0; esm_pt_data->index = 0;
......
...@@ -97,8 +97,8 @@ void nas_proc_initialize(nas_user_t *user, emm_indication_callback_t emm_cb, ...@@ -97,8 +97,8 @@ void nas_proc_initialize(nas_user_t *user, emm_indication_callback_t emm_cb,
user->proc.rsrq = NAS_PROC_RSRQ_UNKNOWN; user->proc.rsrq = NAS_PROC_RSRQ_UNKNOWN;
user->proc.rsrp = NAS_PROC_RSRP_UNKNOWN; user->proc.rsrp = NAS_PROC_RSRP_UNKNOWN;
user->authentication_data = calloc_or_fail(sizeof(authentication_data_t)); user->authentication_data = calloc_or_fail(1, sizeof(authentication_data_t));
user->security_data = calloc_or_fail( sizeof(security_data_t)); user->security_data = calloc_or_fail(1, sizeof(security_data_t));
/* Initialize the EMM procedure manager */ /* Initialize the EMM procedure manager */
emm_main_initialize(user, emm_cb, imei); emm_main_initialize(user, emm_cb, imei);
......
...@@ -67,7 +67,7 @@ static bool nas_ue_process_events(nas_user_container_t *users, struct epoll_even ...@@ -67,7 +67,7 @@ static bool nas_ue_process_events(nas_user_container_t *users, struct epoll_even
// Initialize user api id and port number // Initialize user api id and port number
void nas_user_api_id_initialize(nas_user_t *user) { void nas_user_api_id_initialize(nas_user_t *user) {
user_api_id_t *user_api_id = calloc_or_fail(sizeof(user_api_id_t)); user_api_id_t *user_api_id = calloc_or_fail(1, sizeof(user_api_id_t));
user->user_api_id = user_api_id; user->user_api_id = user_api_id;
char *port = make_port_str_from_ueid(NAS_PARSER_DEFAULT_USER_PORT_NUMBER, user->ueid); char *port = make_port_str_from_ueid(NAS_PARSER_DEFAULT_USER_PORT_NUMBER, user->ueid);
if ( port == NULL ) { if ( port == NULL ) {
...@@ -130,9 +130,9 @@ void *nas_ue_task(void *args_p) ...@@ -130,9 +130,9 @@ void *nas_ue_task(void *args_p)
/* Initialize user interface (to exchange AT commands with user process) */ /* Initialize user interface (to exchange AT commands with user process) */
nas_user_api_id_initialize(user); nas_user_api_id_initialize(user);
/* allocate needed structures */ /* allocate needed structures */
user->user_at_commands = calloc_or_fail(sizeof(user_at_commands_t)); user->user_at_commands = calloc_or_fail(1, sizeof(user_at_commands_t));
user->at_response = calloc_or_fail(sizeof(at_response_t)); user->at_response = calloc_or_fail(1, sizeof(at_response_t));
user->lowerlayer_data = calloc_or_fail(sizeof(lowerlayer_data_t)); user->lowerlayer_data = calloc_or_fail(1, sizeof(lowerlayer_data_t));
/* Initialize NAS user */ /* Initialize NAS user */
nas_user_initialize(user, &user_api_emm_callback, &user_api_esm_callback, FIRMWARE_VERSION); nas_user_initialize(user, &user_api_emm_callback, &user_api_esm_callback, FIRMWARE_VERSION);
} }
...@@ -170,9 +170,9 @@ void *nas_ue_task(void *args_p) ...@@ -170,9 +170,9 @@ void *nas_ue_task(void *args_p)
/* Initialize user interface (to exchange AT commands with user process) */ /* Initialize user interface (to exchange AT commands with user process) */
nas_user_api_id_initialize(user); nas_user_api_id_initialize(user);
/* allocate needed structures */ /* allocate needed structures */
user->user_at_commands = calloc_or_fail(sizeof(user_at_commands_t)); user->user_at_commands = calloc_or_fail(1, sizeof(user_at_commands_t));
user->at_response = calloc_or_fail(sizeof(at_response_t)); user->at_response = calloc_or_fail(1, sizeof(at_response_t));
user->lowerlayer_data = calloc_or_fail(sizeof(lowerlayer_data_t)); user->lowerlayer_data = calloc_or_fail(1, sizeof(lowerlayer_data_t));
/* Initialize NAS user */ /* Initialize NAS user */
nas_user_initialize(user, &user_api_emm_callback, &user_api_esm_callback, FIRMWARE_VERSION); nas_user_initialize(user, &user_api_emm_callback, &user_api_esm_callback, FIRMWARE_VERSION);
user->ueid = 0; user->ueid = 0;
......
...@@ -154,7 +154,7 @@ void nas_user_initialize(nas_user_t *user, emm_indication_callback_t emm_cb, ...@@ -154,7 +154,7 @@ void nas_user_initialize(nas_user_t *user, emm_indication_callback_t emm_cb,
{ {
LOG_FUNC_IN; LOG_FUNC_IN;
user->nas_user_nvdata = calloc_or_fail(sizeof(user_nvdata_t)); user->nas_user_nvdata = calloc_or_fail(1, sizeof(user_nvdata_t));
/* Get UE data stored in the non-volatile memory device */ /* Get UE data stored in the non-volatile memory device */
int rc = memory_read(user->user_nvdata_store, user->nas_user_nvdata, sizeof(user_nvdata_t)); int rc = memory_read(user->user_nvdata_store, user->nas_user_nvdata, sizeof(user_nvdata_t));
...@@ -163,7 +163,7 @@ void nas_user_initialize(nas_user_t *user, emm_indication_callback_t emm_cb, ...@@ -163,7 +163,7 @@ void nas_user_initialize(nas_user_t *user, emm_indication_callback_t emm_cb,
abort(); abort();
} }
user->nas_user_context = calloc_or_fail(sizeof(nas_user_context_t)); user->nas_user_context = calloc_or_fail(1, sizeof(nas_user_context_t));
_nas_user_context_initialize(user->nas_user_context, version); _nas_user_context_initialize(user->nas_user_context, version);
/* Initialize the internal NAS processing data */ /* Initialize the internal NAS processing data */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment