aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Grohmann <davide.grohmann@arm.com>2021-10-19 13:59:27 +0200
committerDavide Grohmann <davide.grohmann@arm.com>2021-10-20 12:43:48 +0200
commitc90bfab219bff42227047329659b8dabf020953f (patch)
tree976427129fed33b01fb3dd94eb85d36471b49a95
parent4aec37655987ad7ea94349ba68f1e352d8cf30a9 (diff)
downloadethos-u-linux-driver-stack-c90bfab219bff42227047329659b8dabf020953f.tar.gz
Fix: e-functions should throw an exception on error
Change-Id: I99d77bf528ea7c6b7d444c24f6f7b712b281b181
-rw-r--r--driver_library/src/ethosu.cpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/driver_library/src/ethosu.cpp b/driver_library/src/ethosu.cpp
index 0262429..4457e3f 100644
--- a/driver_library/src/ethosu.cpp
+++ b/driver_library/src/ethosu.cpp
@@ -45,7 +45,6 @@ __attribute__((weak)) int eioctl(int fd, unsigned long cmd, void *data = nullptr
__attribute__((weak)) int eopen(const char *pathname, int flags) {
int fd = ::open(pathname, flags);
-
if (fd < 0) {
throw Exception("Failed to open device");
}
@@ -54,18 +53,38 @@ __attribute__((weak)) int eopen(const char *pathname, int flags) {
}
__attribute__((weak)) int epoll(struct pollfd *fds, nfds_t nfds, int timeout) {
- return ::poll(fds, nfds, timeout);
+ int result = ::poll(fds, nfds, timeout);
+ if (result < 0) {
+ throw Exception("Failed to wait for poll event");
+ }
+
+ return result;
}
__attribute__((weak)) int eclose(int fd) {
- return ::close(fd);
+ int result = ::close(fd);
+ if (result < 0) {
+ throw Exception("Failed to close file");
+ }
+
+ return result;
}
__attribute((weak)) void *emmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) {
- return ::mmap(addr, length, prot, flags, fd, offset);
+ void *ptr = ::mmap(addr, length, prot, flags, fd, offset);
+ if (ptr == MAP_FAILED) {
+ throw Exception("Failed to mmap file");
+ }
+
+ return ptr;
}
__attribute__((weak)) int emunmap(void *addr, size_t length) {
- return ::munmap(addr, length);
+ int result = ::munmap(addr, length);
+ if (result < 0) {
+ throw Exception("Failed to munmap file");
+ }
+
+ return result;
}
} // namespace EthosU
@@ -213,10 +232,6 @@ Buffer::Buffer(Device &device, const size_t capacity) : fd(-1), dataPtr(nullptr)
fd = device.ioctl(ETHOSU_IOCTL_BUFFER_CREATE, static_cast<void *>(&uapi));
void *d = emmap(nullptr, dataCapacity, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
- if (d == MAP_FAILED) {
- throw Exception("MMap failed");
- }
-
dataPtr = reinterpret_cast<char *>(d);
}