diff options
author | Andrew F. Davis | 2019-06-11 16:12:16 -0500 |
---|---|---|
committer | Praneeth Bajjuri | 2019-06-25 17:50:46 -0500 |
commit | 9426d6fd12f3c3cf91048861670154e14570606e (patch) | |
tree | 9946ab882b93b73bc6efd7b278c9cfa6d8f60741 | |
parent | e660c717596b24b0f6e3d6576ff4077c529f7064 (diff) | |
download | hardware-ti-am57x-9426d6fd12f3c3cf91048861670154e14570606e.tar.gz hardware-ti-am57x-9426d6fd12f3c3cf91048861670154e14570606e.tar.xz hardware-ti-am57x-9426d6fd12f3c3cf91048861670154e14570606e.zip |
libhwcomposer: Rework error paths in DRMFramebuffer
Returning early in a constructor does not signal to the instantiator an
issue has happened and this can lead to problems like leaked resources
and running into errors later when this object is used. To fix this
we should throw exceptions that can be caught by higher layers.
While we are here add error code reporting to the error messages. The
passed in handle can not be null at this point, remove this extra check.
Also failing to close a handle should not stop us from trying to close
the rest, print a warning and continue.
Signed-off-by: Andrew F. Davis <afd@ti.com>
-rw-r--r-- | libhwcomposer/drmfb.cpp | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/libhwcomposer/drmfb.cpp b/libhwcomposer/drmfb.cpp index 0c193d7..a368c10 100644 --- a/libhwcomposer/drmfb.cpp +++ b/libhwcomposer/drmfb.cpp | |||
@@ -14,6 +14,9 @@ | |||
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include <cerrno> | ||
18 | #include <cstring> | ||
19 | |||
17 | #include <log/log.h> | 20 | #include <log/log.h> |
18 | #include <drm/drm_fourcc.h> | 21 | #include <drm/drm_fourcc.h> |
19 | #include <hardware/hwcomposer.h> | 22 | #include <hardware/hwcomposer.h> |
@@ -28,15 +31,12 @@ | |||
28 | DRMFramebuffer::DRMFramebuffer(int drm_fd, buffer_handle_t handle) : | 31 | DRMFramebuffer::DRMFramebuffer(int drm_fd, buffer_handle_t handle) : |
29 | bo(), pitches(), offsets() | 32 | bo(), pitches(), offsets() |
30 | { | 33 | { |
31 | if (!handle) | ||
32 | return; | ||
33 | |||
34 | uint32_t gem_handle; | 34 | uint32_t gem_handle; |
35 | IMG_native_handle_t* img_hnd = (IMG_native_handle_t*)handle; | 35 | IMG_native_handle_t* img_hnd = (IMG_native_handle_t*)handle; |
36 | int ret = drmPrimeFDToHandle(drm_fd, img_hnd->fd[0], &gem_handle); | 36 | int ret = drmPrimeFDToHandle(drm_fd, img_hnd->fd[0], &gem_handle); |
37 | if (ret) { | 37 | if (ret) { |
38 | ALOGE("Failed to get DRM buffer object from handle"); | 38 | ALOGE("Failed to get DRM buffer object from handle: %d (%s)", ret, strerror(errno)); |
39 | return; | 39 | throw std::exception(); |
40 | } | 40 | } |
41 | 41 | ||
42 | this->width = img_hnd->iWidth; | 42 | this->width = img_hnd->iWidth; |
@@ -58,8 +58,8 @@ DRMFramebuffer::DRMFramebuffer(int drm_fd, buffer_handle_t handle) : | |||
58 | case DRM_FORMAT_RGB565: | 58 | case DRM_FORMAT_RGB565: |
59 | break; | 59 | break; |
60 | default: | 60 | default: |
61 | ALOGE("Bad format for overlay"); | 61 | ALOGE("Unsupported pixel format for display"); |
62 | return; | 62 | throw std::exception(); |
63 | } | 63 | } |
64 | 64 | ||
65 | ret = drmModeAddFB2(drm_fd, this->width, this->height, | 65 | ret = drmModeAddFB2(drm_fd, this->width, this->height, |
@@ -67,16 +67,17 @@ DRMFramebuffer::DRMFramebuffer(int drm_fd, buffer_handle_t handle) : | |||
67 | this->pitches, this->offsets, | 67 | this->pitches, this->offsets, |
68 | &this->fb_id, 0); | 68 | &this->fb_id, 0); |
69 | if (ret) { | 69 | if (ret) { |
70 | ALOGE("Could not create DRM frame buffer %d", ret); | 70 | ALOGE("Could not create DRM frame buffer: %d (%s)", ret, strerror(errno)); |
71 | return; | 71 | throw std::exception(); |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | DRMFramebuffer::~DRMFramebuffer() | 75 | DRMFramebuffer::~DRMFramebuffer() |
76 | { | 76 | { |
77 | if (this->fb_id) { | 77 | if (this->fb_id) { |
78 | if (drmModeRmFB(this->drm_fd, this->fb_id)) | 78 | int ret = drmModeRmFB(this->drm_fd, this->fb_id); |
79 | ALOGE("Failed to remove DRM frame buffer"); | 79 | if (ret) |
80 | ALOGW("Failed to remove DRM frame buffer: %d (%s)", ret, strerror(errno)); | ||
80 | } | 81 | } |
81 | 82 | ||
82 | for (size_t i = 0; i < 4; i++) { | 83 | for (size_t i = 0; i < 4; i++) { |
@@ -86,10 +87,8 @@ DRMFramebuffer::~DRMFramebuffer() | |||
86 | close_args.pad = 0, | 87 | close_args.pad = 0, |
87 | }; | 88 | }; |
88 | int ret = drmIoctl(this->drm_fd, DRM_IOCTL_GEM_CLOSE, &close_args); | 89 | int ret = drmIoctl(this->drm_fd, DRM_IOCTL_GEM_CLOSE, &close_args); |
89 | if (ret) { | 90 | if (ret) |
90 | ALOGE("Failed to close GEM handle"); | 91 | ALOGW("Failed to close GEM handle: %d (%s)", ret, strerror(errno)); |
91 | return; | ||
92 | } | ||
93 | } | 92 | } |
94 | } | 93 | } |
95 | } | 94 | } |