[Svace] Fix svace issues newly detected
authorDongju Chae <dongju.chae@samsung.com>
Mon, 10 Aug 2020 08:45:47 +0000 (17:45 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Mon, 10 Aug 2020 09:45:43 +0000 (18:45 +0900)
This patch fixes svace issues newly detected, which includes
- UNINT.CTOR
- NULL_AFTER_DEREF
- FALL_THROUGH
- ...

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
src/core/ne-hw-input-service.cc
tests/apptests/dummy_triv2_internal.cc
tests/apptests/tvn_triv2_bulk_gem.c
tests/apptests/tvn_triv2_dmabuf.cc
tests/apptests/tvn_triv2_recurring.cc

index 5fca920..a27c568 100644 (file)
@@ -61,7 +61,6 @@ int
 HwInputService::invoke (const DriverAPI *api, const Model *model,
     SegmentTable *segt, outputCallback callback)
 {
-  const Metadata * meta = model->getMetadata ();
   input_config_t input_config;
   device_state_t state;
   npuConstraint constraint;
@@ -104,8 +103,8 @@ HwInputService::invoke (const DriverAPI *api, const Model *model,
   input_config.output_mode = OUTPUT_HW;
 
   /** Assumption: only a sigle pair of input/output segments in HW input service */
-  input_config.hw_input_seg = meta->getInputSegmentIndex (0);
-  input_config.hw_output_seg = meta->getOutputSegmentIndex (0);
+  input_config.hw_input_seg = model->getMetadata ()->getInputSegmentIndex (0);
+  input_config.hw_output_seg = model->getMetadata ()->getOutputSegmentIndex (0);
 
   fd = open (segt->getHwDevice ().c_str (), O_RDONLY);
   if (fd == -1) {
index fa33b77..23e6502 100644 (file)
@@ -29,7 +29,7 @@
 /** @brief c++ class to describe how to use npu-engine library */
 class TesterTRIV2 {
   public:
-    TesterTRIV2 () : dev_ (nullptr), model_id_ (0) {
+    TesterTRIV2 () : dev_ (nullptr), meta_ (nullptr), model_id_ (0) {
       model_.size = 0;
     }
 
index 1ab5ec6..245d94e 100644 (file)
@@ -130,6 +130,13 @@ run_inference_each (npudev_h dev, const char *base_path, const char *target)
     goto out_free_meta;
   }
 
+  if (meta->input_seg_num > MAX_TENSORS ||
+      meta->output_seg_num > MAX_TENSORS) {
+    fprintf (stderr, "Invalid metadata detected\n");
+    err = -EINVAL;
+    goto out_free_meta;
+  }
+
   arg_handle = calloc (meta->input_seg_num, sizeof(*arg_handle));
   for (idx = 0; idx < meta->input_seg_num; idx++) {
     struct drm_mode_create_dumb arg_create;
@@ -141,12 +148,17 @@ run_inference_each (npudev_h dev, const char *base_path, const char *target)
     snprintf (input_path[idx], MAX_FILE_LEN, "%s/%s/input_fmap_%d.bin",
         base_path, target, idx);
     f = fopen (input_path[idx], "rb");
+    if (f == NULL) {
+      err = -errno;
+      goto out_close_drmfd;
+    }
 
     input_size = get_file_size (input_path[idx]);
     if (input_size <= 0) {
       fprintf (stderr, "Wrong metadata; need %d input tensors\n",
           meta->input_seg_num);
       err = -EINVAL;
+      fclose (f);
       goto out_close_drmfd;
     }
 
@@ -156,20 +168,25 @@ run_inference_each (npudev_h dev, const char *base_path, const char *target)
     arg_create.flags = 0;
 
     err = drmIoctl (drm_fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg_create);
-    if (err)
+    if (err) {
+      fclose (f);
       goto out_close_drmfd;
+    }
 
     arg_handle[idx].handle = arg_create.handle;
     arg_handle[idx].flags = DRM_CLOEXEC | DRM_RDWR;
     arg_handle[idx].fd = -1;
     err = drmIoctl (drm_fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg_handle[idx]);
-    if (err)
+    if (err) {
+      fclose (f);
       goto out_destroy_drm_dumb;
+    }
 
     mapped = mmap (NULL, input_size, PROT_READ | PROT_WRITE, MAP_SHARED,
         arg_handle[idx].fd, 0);
     if (mapped == MAP_FAILED) {
       err = errno;
+      fclose (f);
       goto out_destroy_drm_dumb;
     }
 
index 7802a69..049487a 100644 (file)
@@ -31,6 +31,7 @@ class TesterTRIV2 {
       meta_ (nullptr), model_id_ (0) {
       model_.size = 0;
       input_.num_buffers = 0;
+      input_tmp_.num_buffers = 0;
     }
 
     ~TesterTRIV2 () {
index a4f9a39..4c2b171 100644 (file)
@@ -258,6 +258,7 @@ main (int argc, char **argv)
         else
           std::cerr << "Unknown flag: " << c;
         std::cerr << std::endl;
+        // no-break
       case 'h':
         print_usage(argv[0]);
         return 0;