From cbad9503a78c23336a32172dd701b73760969ff0 Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Mon, 26 Apr 2021 14:57:32 +0530 Subject: gpu: nvgpu: set file private data before installing fd Make sure file->private_data is set before installing file into file descriptor with fd_install(). Bug 200724607 Bug 200725718 Change-Id: I03e79a3f8981f959ab5f75f442911253d166aa87 Signed-off-by: Deepak Nibade Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2520465 (cherry picked from commit c78efae5e721287a3c7e9c9ca045220d6e433a30) Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2535099 Reviewed-by: svc-mobile-coverity Reviewed-by: Harsh Sinha Reviewed-by: Thomas Steinle Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit Tested-by: Byungkuk Seo Tested-by: mobile promotions --- drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c | 19 +++++++++---------- drivers/gpu/nvgpu/os/linux/ioctl_tsg.c | 19 ++++++++----------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c index 94162b4f..f71921cb 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c @@ -488,27 +488,26 @@ static int gk20a_ctrl_alloc_as( snprintf(name, sizeof(name), "nvhost-%s-fd%d", g->name, fd); - file = anon_inode_getfile(name, l->as_dev.cdev.ops, NULL, O_RDWR); - if (IS_ERR(file)) { - err = PTR_ERR(file); - goto clean_up; - } - err = gk20a_as_alloc_share(g, args->big_page_size, gk20a_as_translate_as_alloc_flags(g, args->flags), &as_share); if (err) - goto clean_up_file; + goto clean_up; + + file = anon_inode_getfile(name, l->as_dev.cdev.ops, as_share, O_RDWR); + if (IS_ERR(file)) { + err = PTR_ERR(file); + goto clean_up_as; + } fd_install(fd, file); - file->private_data = as_share; args->as_fd = fd; return 0; -clean_up_file: - fput(file); +clean_up_as: + gk20a_as_release_share(as_share); clean_up: put_unused_fd(fd); return err; diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_tsg.c b/drivers/gpu/nvgpu/os/linux/ioctl_tsg.c index 915a173a..296b02b2 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_tsg.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_tsg.c @@ -310,17 +310,10 @@ static int gk20a_tsg_event_id_enable(struct tsg_gk20a *tsg, snprintf(name, sizeof(name), "nvgpu-event%d-fd%d", event_id, local_fd); - file = anon_inode_getfile(name, &gk20a_event_id_ops, - NULL, O_RDWR); - if (IS_ERR(file)) { - err = PTR_ERR(file); - goto clean_up; - } - event_id_data = nvgpu_kzalloc(tsg->g, sizeof(*event_id_data)); if (!event_id_data) { err = -ENOMEM; - goto clean_up_file; + goto clean_up; } event_id_data->g = g; event_id_data->id = tsg->tsgid; @@ -333,12 +326,18 @@ static int gk20a_tsg_event_id_enable(struct tsg_gk20a *tsg, nvgpu_init_list_node(&event_id_data->event_id_node); + file = anon_inode_getfile(name, &gk20a_event_id_ops, + event_id_data, O_RDWR); + if (IS_ERR(file)) { + err = PTR_ERR(file); + goto clean_up_free; + } + nvgpu_mutex_acquire(&tsg->event_id_list_lock); nvgpu_list_add_tail(&event_id_data->event_id_node, &tsg->event_id_list); nvgpu_mutex_release(&tsg->event_id_list_lock); fd_install(local_fd, file); - file->private_data = event_id_data; *fd = local_fd; @@ -346,8 +345,6 @@ static int gk20a_tsg_event_id_enable(struct tsg_gk20a *tsg, clean_up_free: nvgpu_kfree(g, event_id_data); -clean_up_file: - fput(file); clean_up: put_unused_fd(local_fd); free_ref: -- cgit v1.2.2