Skip to content

Commit

Permalink
Always free ION buffer (commaai#183)
Browse files Browse the repository at this point in the history
* always free ION buffer

* remove unused owner field
  • Loading branch information
pd0wm committed Jul 26, 2021
1 parent e2bc210 commit 9c7dbf8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
1 change: 0 additions & 1 deletion visionipc/visionbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class VisionBuf {

// ion
int handle = 0;
bool owner = false;

void allocate(size_t len);
void import();
Expand Down
11 changes: 3 additions & 8 deletions visionipc/visionbuf_ion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ void VisionBuf::allocate(size_t len) {

memset(addr, 0, ion_alloc.len);

this->owner = true;
this->len = len;
this->mmap_len = ion_alloc.len;
this->addr = addr;
Expand All @@ -82,7 +81,6 @@ void VisionBuf::import(){
err = ioctl(ion_fd, ION_IOC_IMPORT, &fd_data);
assert(err == 0);

this->owner = false;
this->handle = fd_data.handle;
this->addr = mmap(NULL, this->mmap_len, PROT_READ | PROT_WRITE, MAP_SHARED, this->fd, 0);
assert(this->addr != MAP_FAILED);
Expand Down Expand Up @@ -139,10 +137,7 @@ void VisionBuf::free() {
munmap(this->addr, this->mmap_len);
close(this->fd);

// Free the ION buffer if we also shared it
if (this->owner){
struct ion_handle_data handle_data = {.handle = this->handle};
int ret = ioctl(ion_fd, ION_IOC_FREE, &handle_data);
assert(ret == 0);
}
struct ion_handle_data handle_data = {.handle = this->handle};
int ret = ioctl(ion_fd, ION_IOC_FREE, &handle_data);
assert(ret == 0);
}
1 change: 0 additions & 1 deletion visionipc/visionipc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ void VisionIpcServer::listener(){
bufs[i].buf_cl = 0;
bufs[i].copy_q = 0;
bufs[i].handle = 0;
bufs[i].owner = false;

bufs[i].server_id = server_id;
}
Expand Down

0 comments on commit 9c7dbf8

Please sign in to comment.