Skip to content

Commit

Permalink
libion: Save errno value
Browse files Browse the repository at this point in the history
Ensure that the errno value is saved in ion_ioctl before calling ALOGE
in case ALOGE changes the errno which then changes the return value of
ion_ioctl.

Returning the wrong errno from ion_ioctl can be bad because it can cause
functions like ion_is_legacy to not behave properly.

Also apply the same fix to ion_map.

Change-Id: Ib994b465bfaccdf20963cfdc3f67d1cc5ff3cf8e
  • Loading branch information
Liam Mark authored and YumeMichi committed Dec 9, 2018
1 parent eced216 commit e5dc5bf
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions libion/ion.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ int ion_close(int fd) {
static int ion_ioctl(int fd, int req, void* arg) {
int ret = ioctl(fd, req, arg);
if (ret < 0) {
ALOGE("ioctl %x failed with code %d: %s\n", req, ret, strerror(errno));
return -errno;
int ret_errno = errno;

ALOGE("ioctl %x failed with code %d: %s\n", req, ret, strerror(ret_errno));
return -ret_errno;
}
return ret;
}
Expand Down Expand Up @@ -120,8 +122,10 @@ int ion_map(int fd, ion_user_handle_t handle, size_t length, int prot, int flags
}
tmp_ptr = mmap(NULL, length, prot, flags, data.fd, offset);
if (tmp_ptr == MAP_FAILED) {
ALOGE("mmap failed: %s\n", strerror(errno));
return -errno;
int ret_errno = errno;

ALOGE("mmap failed: %s\n", strerror(ret_errno));
return -ret_errno;
}
*map_fd = data.fd;
*ptr = tmp_ptr;
Expand Down

0 comments on commit e5dc5bf

Please sign in to comment.