gpu: nvgpu: posix: fix mem leak in sgt create

nvgpu_sgt_os_create_from_mem() had a memory leak where an sgt struct was
being malloced but not being returned to the caller. This patch fixes
the bug by changing the execution sequence.

Change-Id: Id3474fc9a15a9463e589b39565a57d10d3f0804a
Signed-off-by: Adeel Raza <araza@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/2023266
Reviewed-by: svc-misra-checker <svc-misra-checker@nvidia.com>
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-misra <svc-mobile-misra@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Adeel Raza
2019-02-19 15:05:20 -08:00
committed by mobile promotions
parent a280bfc16e
commit 323dedc88d

View File

@@ -208,34 +208,35 @@ struct nvgpu_sgt *nvgpu_sgt_os_create_from_mem(struct gk20a *g,
struct nvgpu_mem *mem)
{
struct nvgpu_mem_sgl *sgl;
struct nvgpu_sgt *sgt = nvgpu_kzalloc(g, sizeof(*sgt));
struct nvgpu_sgt *sgt;
if (mem->priv.sgt != NULL) {
return mem->priv.sgt;
}
sgt = nvgpu_kzalloc(g, sizeof(*sgt));
if (sgt == NULL) {
return NULL;
}
sgt->ops = &nvgpu_sgt_posix_ops;
/*
* The userspace implementation is simple: a single 'entry' (which we
* only need the nvgpu_mem_sgl struct to describe). A unit test can
* easily replace it if needed.
*/
sgt->ops = &nvgpu_sgt_posix_ops;
if (mem->priv.sgt != NULL) {
return mem->priv.sgt;
} else {
sgl = (struct nvgpu_mem_sgl *) nvgpu_kzalloc(g, sizeof(
struct nvgpu_mem_sgl));
if (sgl == NULL) {
nvgpu_kfree(g, sgt);
return NULL;
}
sgl->length = mem->size;
sgl->phys = (u64) mem->cpu_va;
sgt->sgl = (struct nvgpu_sgl *) sgl;
sgl = (struct nvgpu_mem_sgl *) nvgpu_kzalloc(g, sizeof(
struct nvgpu_mem_sgl));
if (sgl == NULL) {
nvgpu_kfree(g, sgt);
return NULL;
}
sgl->length = mem->size;
sgl->phys = (u64) mem->cpu_va;
sgt->sgl = (struct nvgpu_sgl *) sgl;
return sgt;
}