summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
diff options
context:
space:
mode:
authorTerje Bergstrom <tbergstrom@nvidia.com>2016-12-20 17:48:35 -0500
committermobile promotions <svcmobile_promotions@nvidia.com>2017-01-04 04:44:24 -0500
commitfef7083e516ff6da4681ea8aaeedc114c6f2c821 (patch)
treeeab34b2dcf4465e69b1b3cda7afc8857deb2601c /drivers/gpu/nvgpu/gk20a/channel_gk20a.c
parentb6031e4e15f4afe4bed9965ecca1e2cf6d08342e (diff)
gpu: nvgpu: Do not dereference NULL wait_cmd
In gk20a_submit_prepare_syncs(), after we have allocated wait_cmd we check the results. If we failed to allocate wait_cmd, we still jump to the error label that tries to free wait_cmd. Create an own error labal for allocation before wait_cmd, and use that if we fail to allocate wait_cmd. Similarly create an error label for incr_cmd, and use that only once incr_cmd has actually been allocated. Change-Id: I1f8bc1d947c524038f5f237358a5e6b0dc2e6ac3 Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com> Reviewed-on: http://git-master/r/1275742 GVS: Gerrit_Virtual_Submit
Diffstat (limited to 'drivers/gpu/nvgpu/gk20a/channel_gk20a.c')
-rw-r--r--drivers/gpu/nvgpu/gk20a/channel_gk20a.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
index 26285729..15170820 100644
--- a/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
+++ b/drivers/gpu/nvgpu/gk20a/channel_gk20a.c
@@ -2548,11 +2548,16 @@ static int gk20a_submit_prepare_syncs(struct channel_gk20a *c,
2548 */ 2548 */
2549 if (flags & NVGPU_SUBMIT_GPFIFO_FLAGS_FENCE_WAIT) { 2549 if (flags & NVGPU_SUBMIT_GPFIFO_FLAGS_FENCE_WAIT) {
2550 job->pre_fence = gk20a_alloc_fence(c); 2550 job->pre_fence = gk20a_alloc_fence(c);
2551 if (!job->pre_fence) {
2552 err = -ENOMEM;
2553 goto fail;
2554 }
2555
2551 if (!pre_alloc_enabled) 2556 if (!pre_alloc_enabled)
2552 job->wait_cmd = kzalloc(sizeof(struct priv_cmd_entry), 2557 job->wait_cmd = kzalloc(sizeof(struct priv_cmd_entry),
2553 GFP_KERNEL); 2558 GFP_KERNEL);
2554 2559
2555 if (!job->wait_cmd || !job->pre_fence) { 2560 if (!job->wait_cmd) {
2556 err = -ENOMEM; 2561 err = -ENOMEM;
2557 goto clean_up_pre_fence; 2562 goto clean_up_pre_fence;
2558 } 2563 }
@@ -2572,7 +2577,7 @@ static int gk20a_submit_prepare_syncs(struct channel_gk20a *c,
2572 *wait_cmd = job->wait_cmd; 2577 *wait_cmd = job->wait_cmd;
2573 *pre_fence = job->pre_fence; 2578 *pre_fence = job->pre_fence;
2574 } else 2579 } else
2575 goto clean_up_pre_fence; 2580 goto clean_up_wait_cmd;
2576 } 2581 }
2577 2582
2578 if ((flags & NVGPU_SUBMIT_GPFIFO_FLAGS_FENCE_GET) && 2583 if ((flags & NVGPU_SUBMIT_GPFIFO_FLAGS_FENCE_GET) &&
@@ -2585,11 +2590,15 @@ static int gk20a_submit_prepare_syncs(struct channel_gk20a *c,
2585 * sync_pt/semaphore PB is added to the GPFIFO later on in submit. 2590 * sync_pt/semaphore PB is added to the GPFIFO later on in submit.
2586 */ 2591 */
2587 job->post_fence = gk20a_alloc_fence(c); 2592 job->post_fence = gk20a_alloc_fence(c);
2593 if (!job->post_fence) {
2594 err = -ENOMEM;
2595 goto clean_up_wait_cmd;
2596 }
2588 if (!pre_alloc_enabled) 2597 if (!pre_alloc_enabled)
2589 job->incr_cmd = kzalloc(sizeof(struct priv_cmd_entry), 2598 job->incr_cmd = kzalloc(sizeof(struct priv_cmd_entry),
2590 GFP_KERNEL); 2599 GFP_KERNEL);
2591 2600
2592 if (!job->incr_cmd || !job->post_fence) { 2601 if (!job->incr_cmd) {
2593 err = -ENOMEM; 2602 err = -ENOMEM;
2594 goto clean_up_post_fence; 2603 goto clean_up_post_fence;
2595 } 2604 }
@@ -2606,25 +2615,27 @@ static int gk20a_submit_prepare_syncs(struct channel_gk20a *c,
2606 *incr_cmd = job->incr_cmd; 2615 *incr_cmd = job->incr_cmd;
2607 *post_fence = job->post_fence; 2616 *post_fence = job->post_fence;
2608 } else 2617 } else
2609 goto clean_up_post_fence; 2618 goto clean_up_incr_cmd;
2610 2619
2611 return 0; 2620 return 0;
2612 2621
2622clean_up_incr_cmd:
2623 free_priv_cmdbuf(c, job->incr_cmd);
2624 if (!pre_alloc_enabled)
2625 job->incr_cmd = NULL;
2613clean_up_post_fence: 2626clean_up_post_fence:
2614 gk20a_fence_put(job->post_fence); 2627 gk20a_fence_put(job->post_fence);
2615 job->post_fence = NULL; 2628 job->post_fence = NULL;
2616 free_priv_cmdbuf(c, job->incr_cmd); 2629clean_up_wait_cmd:
2630 free_priv_cmdbuf(c, job->wait_cmd);
2617 if (!pre_alloc_enabled) 2631 if (!pre_alloc_enabled)
2618 job->incr_cmd = NULL; 2632 job->wait_cmd = NULL;
2619clean_up_pre_fence: 2633clean_up_pre_fence:
2620 gk20a_fence_put(job->pre_fence); 2634 gk20a_fence_put(job->pre_fence);
2621 job->pre_fence = NULL; 2635 job->pre_fence = NULL;
2622 free_priv_cmdbuf(c, job->wait_cmd); 2636fail:
2623 if (!pre_alloc_enabled)
2624 job->wait_cmd = NULL;
2625 *wait_cmd = NULL; 2637 *wait_cmd = NULL;
2626 *pre_fence = NULL; 2638 *pre_fence = NULL;
2627fail:
2628 return err; 2639 return err;
2629} 2640}
2630 2641