From c78efae5e721287a3c7e9c9ca045220d6e433a30 Mon Sep 17 00:00:00 2001 From: Deepak Nibade Date: Mon, 26 Apr 2021 14:57:32 +0530 Subject: [PATCH] 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 Change-Id: I03e79a3f8981f959ab5f75f442911253d166aa87 Signed-off-by: Deepak Nibade Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2520465 Reviewed-by: Konsta Holtta Reviewed-by: Alex Waterman Reviewed-by: mobile promotions GVS: Gerrit_Virtual_Submit Tested-by: mobile promotions --- drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c | 19 +++++++++---------- drivers/gpu/nvgpu/os/linux/ioctl_tsg.c | 21 ++++++++++----------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c index b3d8e5092..da2b702bf 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_ctrl.c @@ -621,12 +621,6 @@ static int gk20a_ctrl_alloc_as( (void) snprintf(name, sizeof(name), "nvhost-%s-fd%d", g->name, fd); - file = anon_inode_getfile(name, &gk20a_as_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), @@ -635,16 +629,21 @@ static int gk20a_ctrl_alloc_as( args->va_range_split, &as_share); if (err) - goto clean_up_file; + goto clean_up; + + file = anon_inode_getfile(name, &gk20a_as_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 94dcd01d3..b3a5872e9 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_tsg.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_tsg.c @@ -361,17 +361,10 @@ static int gk20a_tsg_event_id_enable(struct nvgpu_tsg *tsg, (void) 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; @@ -382,19 +375,25 @@ static int gk20a_tsg_event_id_enable(struct nvgpu_tsg *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; return 0; -clean_up_file: - fput(file); +clean_up_free: + nvgpu_kfree(g, event_id_data); clean_up: put_unused_fd(local_fd); free_ref: