]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/tegra: vic: Fix DMA API misuse
authorRobin Murphy <robin.murphy@arm.com>
Fri, 10 Dec 2021 17:54:44 +0000 (17:54 +0000)
committerThierry Reding <treding@nvidia.com>
Thu, 16 Dec 2021 13:07:07 +0000 (14:07 +0100)
Upon failure, dma_alloc_coherent() returns NULL. If that does happen,
passing some uninitialised stack contents to dma_mapping_error() - which
belongs to a different API in the first place - has precious little
chance of detecting it.

Also include the correct header, because the fragile transitive
inclusion currently providing it is going to break soon.

Fixes: 20e7dce255e9 ("drm/tegra: Remove memory allocation from Falcon library")
CC: Thierry Reding <thierry.reding@gmail.com>
CC: Mikko Perttunen <mperttunen@nvidia.com>
CC: dri-devel@lists.freedesktop.org
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Thierry Reding <treding@nvidia.com>
drivers/gpu/drm/tegra/vic.c

index b58e2b99f81a6d8ad22a097e497a6f2e81c83106..c5f4d2b13c436fb9336ba1aaaa9518ee2f1ffd66 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <linux/clk.h>
 #include <linux/delay.h>
+#include <linux/dma-mapping.h>
 #include <linux/host1x.h>
 #include <linux/iommu.h>
 #include <linux/module.h>
@@ -232,10 +233,8 @@ static int vic_load_firmware(struct vic *vic)
 
        if (!client->group) {
                virt = dma_alloc_coherent(vic->dev, size, &iova, GFP_KERNEL);
-
-               err = dma_mapping_error(vic->dev, iova);
-               if (err < 0)
-                       return err;
+               if (!virt)
+                       return -ENOMEM;
        } else {
                virt = tegra_drm_alloc(tegra, size, &iova);
        }