Skip to content

Commit cab95d4

Browse files
Artem BityutskiyArtem Bityutskiy
authored andcommitted
UBIFS: allocate lpt dump buffer on demand
Instead of using pre-allocated 'c->dbg->buf' buffer in 'dump_lpt_leb()', dynamically allocate it when needed. The intend is to get rid of the pre-allocated 'c->dbg->buf' buffer and save 128KiB of RAM (or more if PEB size is larger). Indeed, currently we allocate this memory even if the user never enables any self-check, which is wasteful. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
1 parent 6fb324a commit cab95d4

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

‎fs/ubifs/lpt_commit.c‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,25 +1881,31 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len)
18811881
static void dump_lpt_leb(const struct ubifs_info *c, int lnum)
18821882
{
18831883
int err, len = c->leb_size, node_type, node_num, node_len, offs;
1884-
void *buf = c->dbg->buf;
1884+
void *buf, *p;
18851885

18861886
printk(KERN_DEBUG "(pid %d) start dumping LEB %d\n",
18871887
current->pid, lnum);
1888+
buf = p = __vmalloc(c->leb_size, GFP_KERNEL | GFP_NOFS, PAGE_KERNEL);
1889+
if (!buf) {
1890+
ubifs_err("cannot allocate memory to dump LPT");
1891+
return;
1892+
}
1893+
18881894
err = ubi_read(c->ubi, lnum, buf, 0, c->leb_size);
18891895
if (err) {
18901896
ubifs_err("cannot read LEB %d, error %d", lnum, err);
1891-
return;
1897+
goto out;
18921898
}
18931899
while (1) {
18941900
offs = c->leb_size - len;
1895-
if (!is_a_node(c, buf, len)) {
1901+
if (!is_a_node(c, p, len)) {
18961902
int pad_len;
18971903

1898-
pad_len = get_pad_len(c, buf, len);
1904+
pad_len = get_pad_len(c, p, len);
18991905
if (pad_len) {
19001906
printk(KERN_DEBUG "LEB %d:%d, pad %d bytes\n",
19011907
lnum, offs, pad_len);
1902-
buf += pad_len;
1908+
p += pad_len;
19031909
len -= pad_len;
19041910
continue;
19051911
}
@@ -1909,7 +1915,7 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum)
19091915
break;
19101916
}
19111917

1912-
node_type = get_lpt_node_type(c, buf, &node_num);
1918+
node_type = get_lpt_node_type(c, p, &node_num);
19131919
switch (node_type) {
19141920
case UBIFS_LPT_PNODE:
19151921
{
@@ -1934,7 +1940,7 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum)
19341940
else
19351941
printk(KERN_DEBUG "LEB %d:%d, nnode, ",
19361942
lnum, offs);
1937-
err = ubifs_unpack_nnode(c, buf, &nnode);
1943+
err = ubifs_unpack_nnode(c, p, &nnode);
19381944
for (i = 0; i < UBIFS_LPT_FANOUT; i++) {
19391945
printk(KERN_CONT "%d:%d", nnode.nbranch[i].lnum,
19401946
nnode.nbranch[i].offs);
@@ -1955,15 +1961,18 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum)
19551961
break;
19561962
default:
19571963
ubifs_err("LPT node type %d not recognized", node_type);
1958-
return;
1964+
goto out;
19591965
}
19601966

1961-
buf += node_len;
1967+
p += node_len;
19621968
len -= node_len;
19631969
}
19641970

19651971
printk(KERN_DEBUG "(pid %d) finish dumping LEB %d\n",
19661972
current->pid, lnum);
1973+
out:
1974+
vfree(buf);
1975+
return;
19671976
}
19681977

19691978
/**

0 commit comments

Comments
 (0)