From 037c5761e7e22152a236fc4ed1ddcf43b1016e01 Mon Sep 17 00:00:00 2001 From: Debarshi Dutta Date: Tue, 26 Nov 2019 12:51:16 +0530 Subject: [PATCH] gpu: nvgpu: handle syncpoint buffer alloc failure Add check for syncpoint buffer allocation failure in the function nvgpu_channel_sync_syncpt_create. Return NULL if the allocation fails. Also, put a reference to the syncpoint allocated if the above buffer allocation fails. Change-Id: I56ab03df3b37a3c8148ee17ec6a7829686e44de6 Signed-off-by: Debarshi Dutta Reviewed-on: https://git-master.nvidia.com/r/2247637 Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-misra Reviewed-by: svc-mobile-cert Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Vijayakumar Subbu Reviewed-by: Deepak Nibade Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/sync/channel_sync_syncpt.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/nvgpu/common/sync/channel_sync_syncpt.c b/drivers/gpu/nvgpu/common/sync/channel_sync_syncpt.c index 5e1c3b138..debf07cfd 100644 --- a/drivers/gpu/nvgpu/common/sync/channel_sync_syncpt.c +++ b/drivers/gpu/nvgpu/common/sync/channel_sync_syncpt.c @@ -365,6 +365,7 @@ nvgpu_channel_sync_syncpt_create(struct nvgpu_channel *c, bool user_managed) { struct nvgpu_channel_sync_syncpt *sp; char syncpt_name[32]; + int err; sp = nvgpu_kzalloc(c->g, sizeof(*sp)); if (sp == NULL) { @@ -396,9 +397,16 @@ nvgpu_channel_sync_syncpt_create(struct nvgpu_channel *c, bool user_managed) return NULL; } - sp->c->g->ops.sync.syncpt.alloc_buf(sp->c, sp->id, + err = sp->c->g->ops.sync.syncpt.alloc_buf(sp->c, sp->id, &sp->syncpt_buf); + if (err != 0) { + nvgpu_nvhost_syncpt_put_ref_ext(sp->nvhost_dev, sp->id); + nvgpu_kfree(c->g, sp); + nvgpu_err(c->g, "failed to allocate syncpoint buffer"); + return NULL; + } + nvgpu_nvhost_syncpt_set_min_eq_max_ext(sp->nvhost_dev, sp->id); nvgpu_atomic_set(&sp->ops.refcount, 0);