generic: 5.15: add pending patch fixing compilation warning in jffs2
[openwrt/staging/hauke.git] / target / linux / generic / pending-5.15 / 143-jffs2-reduce-stack-usage-in-jffs2_build_xattr_subsys.patch
1 From eee53f6eb7561f516b9c4bac829ce31c48096130 Mon Sep 17 00:00:00 2001
2 From: Fabian Frederick <fabf@skynet.be>
3 Date: Tue, 9 May 2017 22:30:03 +0200
4 Subject: [PATCH] jffs2: reduce stack usage in jffs2_build_xattr_subsystem()
5
6 Use kcalloc() for allocation/flush of 128 pointers table to
7 reduce stack usage.
8
9 Function now returns -ENOMEM or 0 on success.
10
11 stackusage
12 Before:
13 ./fs/jffs2/xattr.c:775 jffs2_build_xattr_subsystem 1208
14 dynamic,bounded
15
16 After:
17 ./fs/jffs2/xattr.c:775 jffs2_build_xattr_subsystem 192
18 dynamic,bounded
19
20 Also update definition when CONFIG_JFFS2_FS_XATTR is not enabled
21
22 Tested with an MTD mount point and some user set/getfattr.
23
24 Many current target on OpenWRT also suffer from a compilation warning
25 (that become an error with CONFIG_WERROR) with the following output:
26
27 fs/jffs2/xattr.c: In function 'jffs2_build_xattr_subsystem':
28 fs/jffs2/xattr.c:887:1: error: the frame size of 1088 bytes is larger than 1024 bytes [-Werror=frame-larger-than=]
29 887 | }
30 | ^
31
32 Using dynamic allocation fix this compilation warning.
33
34 Fixes: c9f700f840bd ("[JFFS2][XATTR] using 'delete marker' for xdatum/xref deletion")
35 Reported-by: Tim Gardner <tim.gardner@canonical.com>
36 Reported-by: kernel test robot <lkp@intel.com>
37 Reported-by: Ron Economos <re@w6rz.net>
38 Reported-by: Nathan Chancellor <nathan@kernel.org>
39 Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
40 Signed-off-by: Fabian Frederick <fabf@skynet.be>
41 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
42 Cc: stable@vger.kernel.org
43 ---
44 fs/jffs2/build.c | 5 ++++-
45 fs/jffs2/xattr.c | 13 +++++++++----
46 fs/jffs2/xattr.h | 4 ++--
47 3 files changed, 15 insertions(+), 7 deletions(-)
48
49 --- a/fs/jffs2/build.c
50 +++ b/fs/jffs2/build.c
51 @@ -211,7 +211,10 @@ static int jffs2_build_filesystem(struct
52 ic->scan_dents = NULL;
53 cond_resched();
54 }
55 - jffs2_build_xattr_subsystem(c);
56 + ret = jffs2_build_xattr_subsystem(c);
57 + if (ret)
58 + goto exit;
59 +
60 c->flags &= ~JFFS2_SB_FLAG_BUILDING;
61
62 dbg_fsbuild("FS build complete\n");
63 --- a/fs/jffs2/xattr.c
64 +++ b/fs/jffs2/xattr.c
65 @@ -772,10 +772,10 @@ void jffs2_clear_xattr_subsystem(struct
66 }
67
68 #define XREF_TMPHASH_SIZE (128)
69 -void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
70 +int jffs2_build_xattr_subsystem(struct jffs2_sb_info *c)
71 {
72 struct jffs2_xattr_ref *ref, *_ref;
73 - struct jffs2_xattr_ref *xref_tmphash[XREF_TMPHASH_SIZE];
74 + struct jffs2_xattr_ref **xref_tmphash;
75 struct jffs2_xattr_datum *xd, *_xd;
76 struct jffs2_inode_cache *ic;
77 struct jffs2_raw_node_ref *raw;
78 @@ -784,9 +784,12 @@ void jffs2_build_xattr_subsystem(struct
79
80 BUG_ON(!(c->flags & JFFS2_SB_FLAG_BUILDING));
81
82 + xref_tmphash = kcalloc(XREF_TMPHASH_SIZE,
83 + sizeof(struct jffs2_xattr_ref *), GFP_KERNEL);
84 + if (!xref_tmphash)
85 + return -ENOMEM;
86 +
87 /* Phase.1 : Merge same xref */
88 - for (i=0; i < XREF_TMPHASH_SIZE; i++)
89 - xref_tmphash[i] = NULL;
90 for (ref=c->xref_temp; ref; ref=_ref) {
91 struct jffs2_xattr_ref *tmp;
92
93 @@ -884,6 +887,8 @@ void jffs2_build_xattr_subsystem(struct
94 "%u of xref (%u dead, %u orphan) found.\n",
95 xdatum_count, xdatum_unchecked_count, xdatum_orphan_count,
96 xref_count, xref_dead_count, xref_orphan_count);
97 + kfree(xref_tmphash);
98 + return 0;
99 }
100
101 struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c,
102 --- a/fs/jffs2/xattr.h
103 +++ b/fs/jffs2/xattr.h
104 @@ -71,7 +71,7 @@ static inline int is_xattr_ref_dead(stru
105 #ifdef CONFIG_JFFS2_FS_XATTR
106
107 extern void jffs2_init_xattr_subsystem(struct jffs2_sb_info *c);
108 -extern void jffs2_build_xattr_subsystem(struct jffs2_sb_info *c);
109 +extern int jffs2_build_xattr_subsystem(struct jffs2_sb_info *c);
110 extern void jffs2_clear_xattr_subsystem(struct jffs2_sb_info *c);
111
112 extern struct jffs2_xattr_datum *jffs2_setup_xattr_datum(struct jffs2_sb_info *c,
113 @@ -103,7 +103,7 @@ extern ssize_t jffs2_listxattr(struct de
114 #else
115
116 #define jffs2_init_xattr_subsystem(c)
117 -#define jffs2_build_xattr_subsystem(c)
118 +#define jffs2_build_xattr_subsystem(c) (0)
119 #define jffs2_clear_xattr_subsystem(c)
120
121 #define jffs2_xattr_do_crccheck_inode(c, ic)