drm/tegra: gem: Do not try to dereference ERR_PTR()
authorThierry Reding <treding@nvidia.com>
Fri, 6 May 2022 13:52:49 +0000 (15:52 +0200)
committerThierry Reding <treding@nvidia.com>
Fri, 6 May 2022 13:52:49 +0000 (15:52 +0200)
When mapping the DMA-BUF attachment fails, map->sgt will be an ERR_PTR-
encoded error code and the cleanup code would try to free that memory,
which obviously would fail.

Zero out that pointer after extracting the error code when this happens
so that kfree() can do the right thing.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
drivers/gpu/drm/tegra/gem.c

index 0063403ab5e187f1321990b090af1a2383eda12d..7c7dd84e6db84ad1fcf5eadc3c6d7f5285d9e9f0 100644 (file)
@@ -88,6 +88,7 @@ static struct host1x_bo_mapping *tegra_bo_pin(struct device *dev, struct host1x_
                if (IS_ERR(map->sgt)) {
                        dma_buf_detach(buf, map->attach);
                        err = PTR_ERR(map->sgt);
+                       map->sgt = NULL;
                        goto free;
                }