From 3f257bc63c0dcf50135971727e10e54f938d7fd7 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Tue, 10 Oct 2023 17:26:14 +0200 Subject: [PATCH] drm/tegra: gem: Do not return NULL in tegra_bo_mmap() It's confusing for a function to return NULL and ERR_PTR()-encoded error codes on failure. Make sure we only ever return the latter since that's what callers already expect. Reported-by: Sui Jingfeng Reviewed-by: Sui Jingfeng Signed-off-by: Thierry Reding Link: https://patchwork.freedesktop.org/patch/msgid/ZSVuVcqdGfGtQIQj@orome.fritz.box --- drivers/gpu/drm/tegra/gem.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c index 363e02f86382d9..b4eb030ea96144 100644 --- a/drivers/gpu/drm/tegra/gem.c +++ b/drivers/gpu/drm/tegra/gem.c @@ -178,6 +178,7 @@ static void *tegra_bo_mmap(struct host1x_bo *bo) { struct tegra_bo *obj = host1x_to_tegra_bo(bo); struct iosys_map map = { 0 }; + void *vaddr; int ret; if (obj->vaddr) @@ -185,10 +186,18 @@ static void *tegra_bo_mmap(struct host1x_bo *bo) if (obj->gem.import_attach) { ret = dma_buf_vmap_unlocked(obj->gem.import_attach->dmabuf, &map); - return ret ? NULL : map.vaddr; + if (ret < 0) + return ERR_PTR(ret); + + return map.vaddr; } - return vmap(obj->pages, obj->num_pages, VM_MAP, pgprot_writecombine(PAGE_KERNEL)); + vaddr = vmap(obj->pages, obj->num_pages, VM_MAP, + pgprot_writecombine(PAGE_KERNEL)); + if (!vaddr) + return ERR_PTR(-ENOMEM); + + return vaddr; } static void tegra_bo_munmap(struct host1x_bo *bo, void *addr)