diff --git a/drivers/video/msm/msm_fb.c b/drivers/video/msm/msm_fb.c index a019a3a46e1b..8e7ebd434167 100644 --- a/drivers/video/msm/msm_fb.c +++ b/drivers/video/msm/msm_fb.c @@ -3613,18 +3613,24 @@ static int msmfb_handle_buf_sync_ioctl(struct msm_fb_data_type *mfd, } /* create fd */ mfd->cur_rel_fen_fd = get_unused_fd_flags(0); + if (mfd->cur_rel_fen_fd < 0) { + pr_err("%s: get_unused_fd_flags failed", __func__); + ret = -EIO; + goto buf_sync_err_2; + } sync_fence_install(mfd->cur_rel_fence, mfd->cur_rel_fen_fd); ret = copy_to_user(buf_sync->rel_fen_fd, &mfd->cur_rel_fen_fd, sizeof(int)); if (ret) { pr_err("%s:copy_to_user failed", __func__); - goto buf_sync_err_2; + goto buf_sync_err_3; } mutex_unlock(&mfd->sync_mutex); return ret; +buf_sync_err_3: + put_unused_fd(mfd->cur_rel_fen_fd); buf_sync_err_2: sync_fence_put(mfd->cur_rel_fence); - put_unused_fd(mfd->cur_rel_fen_fd); mfd->cur_rel_fence = NULL; mfd->cur_rel_fen_fd = 0; buf_sync_err_1: @@ -3679,6 +3685,11 @@ static int buf_fence_process(struct msm_fb_data_type *mfd, } /* create fd */ mfd->cur_rel_fen_fd = get_unused_fd_flags(0); + if (mfd->cur_rel_fen_fd < 0) { + pr_err("%s: get_unused_fd_flags failed", __func__); + ret = -EIO; + goto buf_fence_err_2; + } sync_fence_install(mfd->cur_rel_fence, mfd->cur_rel_fen_fd); buf_fence->rel_fen_fd[0] = mfd->cur_rel_fen_fd; /* Only one released fd for now, -1 indicates an end */ @@ -3686,6 +3697,10 @@ static int buf_fence_process(struct msm_fb_data_type *mfd, mfd->acq_fen_cnt = buf_fence->acq_fen_fd_cnt; mutex_unlock(&mfd->sync_mutex); return ret; +buf_fence_err_2: + sync_fence_put(mfd->cur_rel_fence); + mfd->cur_rel_fence = NULL; + mfd->cur_rel_fen_fd = 0; buf_fence_err_1: for (i = 0; i < fence_cnt; i++) sync_fence_put(mfd->acq_fen[i]);