[Core/HwInputSrv] Use dev_t instead of the path of device node
authorWook Song <wook16.song@samsung.com>
Thu, 6 Aug 2020 08:00:52 +0000 (17:00 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Mon, 10 Aug 2020 07:45:28 +0000 (16:45 +0900)
To indicate the device that provides the HW input, this patch uses dev_t
instead of the path of the device node.

Signed-off-by: Wook Song <wook16.song@samsung.com>
src/core/ne-hw-input-service.cc

index 017f984..5fca920 100644 (file)
@@ -12,6 +12,8 @@
  * @note this input service does not use a thread pool.
  */
 
+#include <unistd.h>
+
 #include "ne-inputservice.h"
 
 #define TAG _N41
@@ -64,6 +66,8 @@ HwInputService::invoke (const DriverAPI *api, const Model *model,
   device_state_t state;
   npuConstraint constraint;
   int ret = -EINVAL;
+  struct stat devnode_stat;
+  int fd;
 
   state = api->isReady();
   if (state != device_state_t::STATE_READY) {
@@ -102,14 +106,34 @@ HwInputService::invoke (const DriverAPI *api, const Model *model,
   /** 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_devpath = segt->getHwDevice ().c_str ();
-  input_config.hw_devlen = segt->getHwDevice ().length ();
+
+  fd = open (segt->getHwDevice ().c_str (), O_RDONLY);
+  if (fd == -1) {
+    ret = -errno;
+    goto handle_callback;
+  }
+
+  ret = fstat (fd, &devnode_stat);
+  if (ret == -1) {
+    ret = -errno;
+    goto out_close_fd;
+  }
+
+  if (!S_ISBLK(devnode_stat.st_mode) && !S_ISCHR(devnode_stat.st_mode)) {
+    ret = -EINVAL;
+    goto out_close_fd;
+  }
+
+  input_config.hw_rdev = devnode_stat.st_rdev;
 
   /** run the inference with the input */
   ret = api->runInput (&input_config);
   if (ret < 0 && ret != -ECANCELED)
     logerr (TAG, "Failed to run the NPU inference: %d\n", ret);
 
+out_close_fd:
+  close (fd);
+
 handle_callback:
   /** should call the callback regardless of failure, to avoid deadlock */
   if (callback != nullptr)