Skip to content

Commit fd323e9

Browse files
digetxthierryreding
authored andcommitted
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: Dmitry Osipenko <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent 26c8de5 commit fd323e9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

drivers/gpu/host1x/job.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
105105
{
106106
struct host1x_client *client = job->client;
107107
struct device *dev = client->dev;
108+
struct host1x_job_gather *g;
108109
struct iommu_domain *domain;
109110
unsigned int i;
110111
int err;
@@ -194,7 +195,6 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
194195
return 0;
195196

196197
for (i = 0; i < job->num_gathers; i++) {
197-
struct host1x_job_gather *g = &job->gathers[i];
198198
size_t gather_size = 0;
199199
struct scatterlist *sg;
200200
struct sg_table *sgt;
@@ -204,6 +204,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
204204
dma_addr_t *phys;
205205
unsigned int j;
206206

207+
g = &job->gathers[i];
207208
g->bo = host1x_bo_get(g->bo);
208209
if (!g->bo) {
209210
err = -EINVAL;
@@ -223,7 +224,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
223224
sgt = host1x_bo_pin(host->dev, g->bo, phys);
224225
if (IS_ERR(sgt)) {
225226
err = PTR_ERR(sgt);
226-
goto unpin;
227+
goto put;
227228
}
228229

229230
if (host->domain) {
@@ -236,7 +237,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
236237
host->iova_end >> shift, true);
237238
if (!alloc) {
238239
err = -ENOMEM;
239-
goto unpin;
240+
goto put;
240241
}
241242

242243
err = iommu_map_sg(host->domain,
@@ -245,7 +246,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
245246
if (err == 0) {
246247
__free_iova(&host->iova, alloc);
247248
err = -EINVAL;
248-
goto unpin;
249+
goto put;
249250
}
250251

251252
job->unpins[job->num_unpins].size = gather_size;
@@ -255,7 +256,7 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job)
255256
DMA_TO_DEVICE);
256257
if (!err) {
257258
err = -ENOMEM;
258-
goto unpin;
259+
goto put;
259260
}
260261

261262
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)
273274

274275
return 0;
275276

277+
put:
278+
host1x_bo_put(g->bo);
276279
unpin:
277280
host1x_job_unpin(job);
278281
return err;

0 commit comments

Comments
 (0)