From 74fe1caa2b56aab24c17ad4dd2524128fc237894 Mon Sep 17 00:00:00 2001 From: David Nieto Date: Mon, 13 Feb 2017 11:22:59 -0800 Subject: gpu: nvgpu: Add refcounting to driver fds The main driver structure is not refcounted properly, so when the driver unload, file desciptors associated to the driver are kept open with dangling references to the main object. This change adds referencing to the gk20a structure. bug 200277762 JIRA: EVLR-1023 Change-Id: Id892e9e1677a344789e99bf649088c076f0bf8de Signed-off-by: David Nieto Reviewed-on: http://git-master/r/1317420 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/gk20a/channel_gk20a.c | 35 ++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'drivers/gpu/nvgpu/gk20a/channel_gk20a.c') diff --git a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c index 73cc18d2..c09539ff 100644 --- a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c @@ -1234,7 +1234,7 @@ int gk20a_channel_release(struct inode *inode, struct file *filp) err = gk20a_busy(g->dev); if (err) { gk20a_err(dev_from_gk20a(g), "failed to release a channel!"); - return err; + goto channel_release; } trace_gk20a_channel_release(dev_name(g->dev)); @@ -1242,6 +1242,8 @@ int gk20a_channel_release(struct inode *inode, struct file *filp) gk20a_channel_close(ch); gk20a_idle(g->dev); +channel_release: + gk20a_put(g); kfree(filp->private_data); filp->private_data = NULL; return 0; @@ -1382,11 +1384,17 @@ static int __gk20a_channel_open(struct gk20a *g, struct file *filp, s32 runlist_ gk20a_dbg_fn(""); + g = gk20a_get(g); + if (!g) + return -ENODEV; + trace_gk20a_channel_open(dev_name(g->dev)); priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; + if (!priv) { + err = -ENOMEM; + goto free_ref; + } err = gk20a_busy(g->dev); if (err) { @@ -1414,6 +1422,8 @@ static int __gk20a_channel_open(struct gk20a *g, struct file *filp, s32 runlist_ fail_busy: kfree(priv); +free_ref: + gk20a_put(g); return err; } @@ -3509,6 +3519,7 @@ static int gk20a_event_id_release(struct inode *inode, struct file *filp) } nvgpu_mutex_destroy(&event_id_data->lock); + gk20a_put(g); kfree(event_id_data); filp->private_data = NULL; @@ -3573,20 +3584,28 @@ static int gk20a_channel_event_id_enable(struct channel_gk20a *ch, int event_id, int *fd) { + struct gk20a *g; int err = 0; int local_fd; struct file *file; char *name; struct gk20a_event_id_data *event_id_data; + g = gk20a_get(ch->g); + if (!g) + return -ENODEV; + err = gk20a_channel_get_event_data_from_id(ch, event_id, &event_id_data); - if (err == 0) /* We already have event enabled */ - return -EINVAL; + if (err == 0) { + /* We already have event enabled */ + err = -EINVAL; + goto free_ref; + } err = get_unused_fd_flags(O_RDWR); if (err < 0) - return err; + goto free_ref; local_fd = err; name = kasprintf(GFP_KERNEL, "nvgpu-event%d-fd%d", @@ -3605,7 +3624,7 @@ static int gk20a_channel_event_id_enable(struct channel_gk20a *ch, err = -ENOMEM; goto clean_up_file; } - event_id_data->g = ch->g; + event_id_data->g = g; event_id_data->id = ch->hw_chid; event_id_data->is_tsg = false; event_id_data->event_id = event_id; @@ -3633,6 +3652,8 @@ clean_up_file: fput(file); clean_up: put_unused_fd(local_fd); +free_ref: + gk20a_put(g); return err; } -- cgit v1.2.2