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 <dmartineznie@nvidia.com>
Reviewed-on: http://git-master/r/1317420
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
(cherry picked from commit 74fe1caa2b)
Reviewed-on: http://git-master/r/1324637
GVS: Gerrit_Virtual_Submit
Reviewed-by: Sumeet Gupta <sumeetg@nvidia.com>
This commit is contained in:
David Nieto
2017-02-13 11:22:59 -08:00
committed by mobile promotions
parent 26f904e2b7
commit 2fce77c286
12 changed files with 193 additions and 43 deletions

View File

@@ -55,10 +55,15 @@ int gk20a_ctrl_dev_open(struct inode *inode, struct file *filp)
g = container_of(inode->i_cdev,
struct gk20a, ctrl.cdev);
g = gk20a_get(g);
if (!g)
return -ENODEV;
priv = kzalloc(sizeof(struct gk20a_ctrl_priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
if (!priv) {
err = -ENOMEM;
goto free_ref;
}
filp->private_data = priv;
priv->dev = g->dev;
/*
@@ -71,29 +76,30 @@ int gk20a_ctrl_dev_open(struct inode *inode, struct file *filp)
if (!g->gr.sw_ready) {
err = gk20a_busy(g->dev);
if (err)
return err;
goto free_ref;
gk20a_idle(g->dev);
}
#ifdef CONFIG_ARCH_TEGRA_18x_SOC
err = nvgpu_clk_arb_init_session(g, &priv->clk_session);
if (err)
return err;
#endif
free_ref:
if (err)
gk20a_put(g);
return err;
}
int gk20a_ctrl_dev_release(struct inode *inode, struct file *filp)
{
struct gk20a_ctrl_priv *priv = filp->private_data;
struct gk20a *g = priv->g;
gk20a_dbg_fn("");
#ifdef CONFIG_ARCH_TEGRA_18x_SOC
if (priv->clk_session)
nvgpu_clk_arb_release_session(gk20a_from_dev(priv->dev),
priv->clk_session);
nvgpu_clk_arb_release_session(g, priv->clk_session);
#endif
gk20a_put(g);
kfree(priv);
return 0;