firmware: tegra: Reduce stack usage
authorArnd Bergmann <arnd@arndb.de>
Mon, 27 Sep 2021 12:41:40 +0000 (14:41 +0200)
committerThierry Reding <treding@nvidia.com>
Thu, 7 Oct 2021 18:52:17 +0000 (20:52 +0200)
Building the bpmp-debugfs driver for Arm results in a warning for stack usage:

drivers/firmware/tegra/bpmp-debugfs.c:321:16: error: stack frame size of 1224 bytes in function 'bpmp_debug_store' [-Werror,-Wframe-larger-than=]
static ssize_t bpmp_debug_store(struct file *file, const char __user *buf,

It should be possible to rearrange the code to not require two separate
buffers for the file name, but the easiest workaround is to use dynamic
allocation.

Fixes: 5e37b9c137ee ("firmware: tegra: Add support for in-band debug")
Link: https://lore.kernel.org/all/20201204193714.3134651-1-arnd@kernel.org/
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
[treding@nvidia.com: consistently return NULL on failure]
Signed-off-by: Thierry Reding <treding@nvidia.com>
drivers/firmware/tegra/bpmp-debugfs.c

index 3e9fa4b543588e81ee60c90c2212e31fe375bef7..6d66fe03fb6afbbd3c6dd74236f24abee92eea8e 100644 (file)
@@ -74,28 +74,36 @@ static void seqbuf_seek(struct seqbuf *seqbuf, ssize_t offset)
 static const char *get_filename(struct tegra_bpmp *bpmp,
                                const struct file *file, char *buf, int size)
 {
-       char root_path_buf[512];
-       const char *root_path;
-       const char *filename;
+       const char *root_path, *filename = NULL;
+       char *root_path_buf;
        size_t root_len;
 
+       root_path_buf = kzalloc(512, GFP_KERNEL);
+       if (!root_path_buf)
+               goto out;
+
        root_path = dentry_path(bpmp->debugfs_mirror, root_path_buf,
                                sizeof(root_path_buf));
        if (IS_ERR(root_path))
-               return NULL;
+               goto out;
 
        root_len = strlen(root_path);
 
        filename = dentry_path(file->f_path.dentry, buf, size);
-       if (IS_ERR(filename))
-               return NULL;
+       if (IS_ERR(filename)) {
+               filename = NULL;
+               goto out;
+       }
 
-       if (strlen(filename) < root_len ||
-                       strncmp(filename, root_path, root_len))
-               return NULL;
+       if (strlen(filename) < root_len || strncmp(filename, root_path, root_len)) {
+               filename = NULL;
+               goto out;
+       }
 
        filename += root_len;
 
+out:
+       kfree(root_path_buf);
        return filename;
 }