Commit fd323e9e authored by Dmitry Osipenko's avatar Dmitry Osipenko Committed by Thierry Reding

gpu: host1x: Put gather's BO on pinning error

This patch fixes gather's BO refcounting on a pinning error. Gather's BO
won't be leaked now if something goes wrong.
Signed-off-by: default avatarDmitry Osipenko <digetx@gmail.com>
Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
parent 26c8de5e
...@@ -105,6 +105,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) ...@@ -105,6 +105,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
{ {
struct host1x_client *client = job->client; struct host1x_client *client = job->client;
struct device *dev = client->dev; struct device *dev = client->dev;
struct host1x_job_gather *g;
struct iommu_domain *domain; struct iommu_domain *domain;
unsigned int i; unsigned int i;
int err; int err;
...@@ -194,7 +195,6 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) ...@@ -194,7 +195,6 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
return 0; return 0;
for (i = 0; i < job->num_gathers; i++) { for (i = 0; i < job->num_gathers; i++) {
struct host1x_job_gather *g = &job->gathers[i];
size_t gather_size = 0; size_t gather_size = 0;
struct scatterlist *sg; struct scatterlist *sg;
struct sg_table *sgt; struct sg_table *sgt;
...@@ -204,6 +204,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) ...@@ -204,6 +204,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
dma_addr_t *phys; dma_addr_t *phys;
unsigned int j; unsigned int j;
g = &job->gathers[i];
g->bo = host1x_bo_get(g->bo); g->bo = host1x_bo_get(g->bo);
if (!g->bo) { if (!g->bo) {
err = -EINVAL; err = -EINVAL;
...@@ -223,7 +224,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) ...@@ -223,7 +224,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
sgt = host1x_bo_pin(host->dev, g->bo, phys); sgt = host1x_bo_pin(host->dev, g->bo, phys);
if (IS_ERR(sgt)) { if (IS_ERR(sgt)) {
err = PTR_ERR(sgt); err = PTR_ERR(sgt);
goto unpin; goto put;
} }
if (host->domain) { if (host->domain) {
...@@ -236,7 +237,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) ...@@ -236,7 +237,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
host->iova_end >> shift, true); host->iova_end >> shift, true);
if (!alloc) { if (!alloc) {
err = -ENOMEM; err = -ENOMEM;
goto unpin; goto put;
} }
err = iommu_map_sg(host->domain, err = iommu_map_sg(host->domain,
...@@ -245,7 +246,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) ...@@ -245,7 +246,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
if (err == 0) { if (err == 0) {
__free_iova(&host->iova, alloc); __free_iova(&host->iova, alloc);
err = -EINVAL; err = -EINVAL;
goto unpin; goto put;
} }
job->unpins[job->num_unpins].size = gather_size; job->unpins[job->num_unpins].size = gather_size;
...@@ -255,7 +256,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) ...@@ -255,7 +256,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
DMA_TO_DEVICE); DMA_TO_DEVICE);
if (!err) { if (!err) {
err = -ENOMEM; err = -ENOMEM;
goto unpin; goto put;
} }
job->unpins[job->num_unpins].dir = DMA_TO_DEVICE; job->unpins[job->num_unpins].dir = DMA_TO_DEVICE;
...@@ -273,6 +274,8 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) ...@@ -273,6 +274,8 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
return 0; return 0;
put:
host1x_bo_put(g->bo);
unpin: unpin:
host1x_job_unpin(job); host1x_job_unpin(job);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment