From 19d1121cdad6cf30a8238c2e152a2a7c40f75bea Mon Sep 17 00:00:00 2001 From: Wook Song Date: Thu, 6 Aug 2020 17:00:52 +0900 Subject: [PATCH] [Core/HwInputSrv] Use dev_t instead of the path of device node 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 --- src/core/ne-hw-input-service.cc | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/core/ne-hw-input-service.cc b/src/core/ne-hw-input-service.cc index 017f984..5fca920 100644 --- a/src/core/ne-hw-input-service.cc +++ b/src/core/ne-hw-input-service.cc @@ -12,6 +12,8 @@ * @note this input service does not use a thread pool. */ +#include + #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) -- 2.7.4