From 42585a86f3fd9f92be7b4a00b331d4e26c884d10 Mon Sep 17 00:00:00 2001 From: Yash Bhatt Date: Tue, 4 Jun 2024 19:49:38 +0000 Subject: [PATCH] video: tegra: nvmap: Fix stack frame size exceeded error in nvmap Fix stack frame size exceeded error in nvmap_ioctl.c by allocating the buf array dynamically. Bug 4663827 Change-Id: I4ccb86b2f82e09417bf957830777c516dcf1ee47 Signed-off-by: Yash Bhatt Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3154936 Reviewed-by: Sachin Nikam Reviewed-by: Ketan Patil Tested-by: Bitan Biswas GVS: buildbot_gerritrpt --- drivers/video/tegra/nvmap/nvmap_ioctl.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/video/tegra/nvmap/nvmap_ioctl.c b/drivers/video/tegra/nvmap/nvmap_ioctl.c index d765a518..7410c805 100644 --- a/drivers/video/tegra/nvmap/nvmap_ioctl.c +++ b/drivers/video/tegra/nvmap/nvmap_ioctl.c @@ -1161,7 +1161,7 @@ static int compute_memory_stat(u64 *total, u64 *free, int numa_id) { struct file *file; char meminfo_path[64] = {'\0'}; - u8 buf[MEMINFO_SIZE]; + u8 *buf; loff_t pos = 0; char *buffer, *ptr; u64 mem_total, mem_free, reclaimable; @@ -1175,7 +1175,13 @@ static int compute_memory_stat(u64 *total, u64 *free, int numa_id) return -EINVAL; } - memset(buf, 0, sizeof(buf)); + buf = nvmap_altalloc(MEMINFO_SIZE * sizeof(*buf)); + if (!buf) { + pr_err("Memory allocation failed\n"); + filp_close(file, NULL); + return -ENOMEM; + } + rc = kernel_read(file, buf, MEMINFO_SIZE - 1, &pos); buf[rc] = '\n'; filp_close(file, NULL); @@ -1192,6 +1198,7 @@ static int compute_memory_stat(u64 *total, u64 *free, int numa_id) reclaimable_found = true; } + nvmap_altfree(buf, MEMINFO_SIZE * sizeof(*buf)); if (nid == numa_id && total_found && free_found && reclaimable_found) { *total = mem_total * 1024; *free = (mem_free + reclaimable / 2) * 1024;