drm/tegra: gem: Do not return NULL in tegra_bo_mmap()
authorThierry Reding <treding@nvidia.com>
Tue, 10 Oct 2023 15:26:14 +0000 (17:26 +0200)
committerThierry Reding <treding@nvidia.com>
Wed, 11 Oct 2023 20:52:44 +0000 (22:52 +0200)
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 <suijingfeng@loongson.cn>
Reviewed-by: Sui Jingfeng <suijingfeng@loongson.cn>
Signed-off-by: Thierry Reding <treding@nvidia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/ZSVuVcqdGfGtQIQj@orome.fritz.box
drivers/gpu/drm/tegra/gem.c

index 363e02f..b4eb030 100644 (file)
@@ -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)