diff options
author | Rom Lemarchand <romlem@google.com> | 2014-10-27 16:42:10 -0700 |
---|---|---|
committer | Rom Lemarchand <romlem@google.com> | 2014-10-28 15:50:19 +0000 |
commit | 5cdcdce50ea5ede7dd5bf627f6f0252501e08eea (patch) | |
tree | d11cb1619ef3c4911841270c3ee96585bb4865da /libion | |
parent | d1abdeac3ef0a2a7cc32e687269260db9c6c9e1c (diff) | |
download | system_core-5cdcdce50ea5ede7dd5bf627f6f0252501e08eea.zip system_core-5cdcdce50ea5ede7dd5bf627f6f0252501e08eea.tar.gz system_core-5cdcdce50ea5ede7dd5bf627f6f0252501e08eea.tar.bz2 |
libion: only modify parameters on success
Wait until a call is successful before modifying the value of pointers
passed
Change-Id: Iaeb2517c8cefeca2f60ebf610d38f264b48e59a0
Diffstat (limited to 'libion')
-rw-r--r-- | libion/ion.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/libion/ion.c b/libion/ion.c index 80bdc2a..32781f7 100644 --- a/libion/ion.c +++ b/libion/ion.c @@ -90,6 +90,7 @@ int ion_map(int fd, ion_user_handle_t handle, size_t length, int prot, int flags, off_t offset, unsigned char **ptr, int *map_fd) { int ret; + unsigned char *tmp_ptr; struct ion_fd_data data = { .handle = handle, }; @@ -102,16 +103,17 @@ int ion_map(int fd, ion_user_handle_t handle, size_t length, int prot, ret = ion_ioctl(fd, ION_IOC_MAP, &data); if (ret < 0) return ret; - *map_fd = data.fd; - if (*map_fd < 0) { + if (data.fd < 0) { ALOGE("map ioctl returned negative fd\n"); return -EINVAL; } - *ptr = mmap(NULL, length, prot, flags, *map_fd, offset); - if (*ptr == MAP_FAILED) { + tmp_ptr = mmap(NULL, length, prot, flags, data.fd, offset); + if (tmp_ptr == MAP_FAILED) { ALOGE("mmap failed: %s\n", strerror(errno)); return -errno; } + *map_fd = data.fd; + *ptr = tmp_ptr; return ret; } @@ -129,11 +131,11 @@ int ion_share(int fd, ion_user_handle_t handle, int *share_fd) ret = ion_ioctl(fd, ION_IOC_SHARE, &data); if (ret < 0) return ret; - *share_fd = data.fd; - if (*share_fd < 0) { + if (data.fd < 0) { ALOGE("share ioctl returned negative fd\n"); return -EINVAL; } + *share_fd = data.fd; return ret; } |