gpu: host1x: Correct allocated size for contexts
authorJohnny Liu <johnliu@nvidia.com>
Fri, 1 Sep 2023 11:59:09 +0000 (14:59 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 20 Nov 2023 10:52:00 +0000 (11:52 +0100)
[ Upstream commit e889a311f74f4ae8bd40755a2c58d02e1c684fef ]

Original implementation over allocates the memory size for the
contexts list. The size of memory for the contexts list is based
on the number of iommu groups specified in the device tree.

Fixes: 8aa5bcb61612 ("gpu: host1x: Add context device management code")
Signed-off-by: Johnny Liu <johnliu@nvidia.com>
Signed-off-by: Mikko Perttunen <mperttunen@nvidia.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230901115910.701518-1-cyndis@kapsi.fi
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/host1x/context.c

index 047696432eb21cb637f631745458e531a9e12980..93c0c532fe5afd3a79ab16d4bae4b28c9a3545ff 100644 (file)
@@ -34,10 +34,10 @@ int host1x_memory_context_list_init(struct host1x *host1x)
        if (err < 0)
                return 0;
 
-       cdl->devs = kcalloc(err, sizeof(*cdl->devs), GFP_KERNEL);
+       cdl->len = err / 4;
+       cdl->devs = kcalloc(cdl->len, sizeof(*cdl->devs), GFP_KERNEL);
        if (!cdl->devs)
                return -ENOMEM;
-       cdl->len = err / 4;
 
        for (i = 0; i < cdl->len; i++) {
                struct iommu_fwspec *fwspec;