summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author이상규/On-Device Lab(SR)/Principal Engineer/삼성전자 <sg5.lee@samsung.com>2019-09-18 01:38:08 (GMT)
committerChunseok Lee <chunseok.lee@samsung.com>2019-09-18 02:17:00 (GMT)
commit2f1aee843584dfb4c5847a1bf6b220aa9de763f3 (patch)
tree0b728777f4521af57cb56e7e198bfb7d8be0aa9b
parenta262e23b92191e7895cd675559f1bd7f9aa1c917 (diff)
downloadnnfw-2f1aee843584dfb4c5847a1bf6b220aa9de763f3.zip
nnfw-2f1aee843584dfb4c5847a1bf6b220aa9de763f3.tar.gz
nnfw-2f1aee843584dfb4c5847a1bf6b220aa9de763f3.tar.bz2
session will be null-checked before dereferencing. Change-Id: Id8bb2b743eb2079c08ca2522cebca777a60b05b2 Signed-off-by: Sanggyu Lee <sg5.lee@samsung.com> Signed-off-by: Chunseok Lee <chunseok.lee@samsung.com>
-rw-r--r--runtimes/neurun/frontend/api/nnfw_dev.cc29
1 files changed, 27 insertions, 2 deletions
diff --git a/runtimes/neurun/frontend/api/nnfw_dev.cc b/runtimes/neurun/frontend/api/nnfw_dev.cc
index e7ee7a2..ddb6dd5 100644
--- a/runtimes/neurun/frontend/api/nnfw_dev.cc
+++ b/runtimes/neurun/frontend/api/nnfw_dev.cc
@@ -41,6 +41,13 @@ NNFW_STATUS nnfw_close_session(nnfw_session *session)
return NNFW_STATUS_NO_ERROR;
}
+#define NNFW_RETURN_ERROR_IF_NULL(p) \
+ do \
+ { \
+ if ((p) == NULL) \
+ return NNFW_STATUS_ERROR; \
+ } while (0)
+
/*
* Load model from nnpackage file or directory
*
@@ -51,6 +58,7 @@ NNFW_STATUS nnfw_close_session(nnfw_session *session)
*/
NNFW_STATUS nnfw_load_model_from_file(nnfw_session *session, const char *pacakge_file_path)
{
+ NNFW_RETURN_ERROR_IF_NULL(session);
return session->load_model_from_file(pacakge_file_path);
}
@@ -61,7 +69,11 @@ NNFW_STATUS nnfw_load_model_from_file(nnfw_session *session, const char *pacakge
* @param session the session to be prepared
* @return NNFW_STATUS_NO_ERROR if successful
*/
-NNFW_STATUS nnfw_prepare(nnfw_session *session) { return session->prepare(); }
+NNFW_STATUS nnfw_prepare(nnfw_session *session)
+{
+ NNFW_RETURN_ERROR_IF_NULL(session);
+ return session->prepare();
+}
/*
* Run inference
@@ -69,7 +81,11 @@ NNFW_STATUS nnfw_prepare(nnfw_session *session) { return session->prepare(); }
* @param session the session to run inference
* @return NNFW_STATUS_NO_ERROR if successful
*/
-NNFW_STATUS nnfw_run(nnfw_session *session) { return session->run(); }
+NNFW_STATUS nnfw_run(nnfw_session *session)
+{
+ NNFW_RETURN_ERROR_IF_NULL(session);
+ return session->run();
+}
/*
* Set input
@@ -86,6 +102,7 @@ NNFW_STATUS nnfw_run(nnfw_session *session) { return session->run(); }
NNFW_STATUS nnfw_set_input(nnfw_session *session, uint32_t index, NNFW_TYPE type,
const void *buffer, size_t length)
{
+ NNFW_RETURN_ERROR_IF_NULL(session);
return session->set_input(index, type, buffer, length);
}
@@ -104,6 +121,7 @@ NNFW_STATUS nnfw_set_input(nnfw_session *session, uint32_t index, NNFW_TYPE type
NNFW_STATUS nnfw_set_output(nnfw_session *session, uint32_t index, NNFW_TYPE type, void *buffer,
size_t length)
{
+ NNFW_RETURN_ERROR_IF_NULL(session);
return session->set_output(index, type, buffer, length);
}
@@ -118,6 +136,7 @@ NNFW_STATUS nnfw_set_output(nnfw_session *session, uint32_t index, NNFW_TYPE typ
NNFW_STATUS nnfw_input_size(nnfw_session *session, uint32_t *number)
{
+ NNFW_RETURN_ERROR_IF_NULL(session);
return session->input_size(number);
}
@@ -131,6 +150,7 @@ NNFW_STATUS nnfw_input_size(nnfw_session *session, uint32_t *number)
*/
NNFW_STATUS nnfw_output_size(nnfw_session *session, uint32_t *number)
{
+ NNFW_RETURN_ERROR_IF_NULL(session);
return session->output_size(number);
}
@@ -146,6 +166,7 @@ NNFW_STATUS nnfw_output_size(nnfw_session *session, uint32_t *number)
NNFW_STATUS nnfw_input_tensorinfo(nnfw_session *session, uint32_t index,
nnfw_tensorinfo *tensor_info)
{
+ NNFW_RETURN_ERROR_IF_NULL(session);
return session->input_tensorinfo(index, tensor_info);
}
@@ -161,6 +182,7 @@ NNFW_STATUS nnfw_input_tensorinfo(nnfw_session *session, uint32_t index,
NNFW_STATUS nnfw_output_tensorinfo(nnfw_session *session, uint32_t index,
nnfw_tensorinfo *tensor_info)
{
+ NNFW_RETURN_ERROR_IF_NULL(session);
return session->output_tensorinfo(index, tensor_info);
}
@@ -174,6 +196,7 @@ NNFW_STATUS nnfw_output_tensorinfo(nnfw_session *session, uint32_t index,
NNFW_STATUS nnfw_register_custom_op_info(nnfw_session *session, const char *id,
custom_kernel_registration_info *info)
{
+ NNFW_RETURN_ERROR_IF_NULL(session);
return session->register_custom_operation(id, info->eval_function);
}
@@ -185,6 +208,7 @@ NNFW_STATUS nnfw_register_custom_op_info(nnfw_session *session, const char *id,
*/
NNFW_STATUS nnfw_set_default_backend(nnfw_session *session, const char *backend)
{
+ NNFW_RETURN_ERROR_IF_NULL(session);
return session->set_default_backend(backend);
}
@@ -199,5 +223,6 @@ NNFW_STATUS nnfw_set_default_backend(nnfw_session *session, const char *backend)
*/
NNFW_STATUS nnfw_set_op_backend(nnfw_session *session, const char *op, const char *backend)
{
+ NNFW_RETURN_ERROR_IF_NULL(session);
return session->set_op_backend(op, backend);
}