* @note this input service does not use a thread pool.
*/
+#include <unistd.h>
+
#include "ne-inputservice.h"
#define TAG _N41
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) {
/** 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)