Commit cab95d44 authored by Artem Bityutskiy's avatar Artem Bityutskiy

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: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
parent 6fb324a4
...@@ -1881,25 +1881,31 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len) ...@@ -1881,25 +1881,31 @@ int dbg_chk_lpt_sz(struct ubifs_info *c, int action, int len)
static void dump_lpt_leb(const struct ubifs_info *c, int lnum) static void dump_lpt_leb(const struct ubifs_info *c, int lnum)
{ {
int err, len = c->leb_size, node_type, node_num, node_len, offs; int err, len = c->leb_size, node_type, node_num, node_len, offs;
void *buf = c->dbg->buf; void *buf, *p;
printk(KERN_DEBUG "(pid %d) start dumping LEB %d\n", printk(KERN_DEBUG "(pid %d) start dumping LEB %d\n",
current->pid, lnum); current->pid, lnum);
buf = p = __vmalloc(c->leb_size, GFP_KERNEL | GFP_NOFS, PAGE_KERNEL);
if (!buf) {
ubifs_err("cannot allocate memory to dump LPT");
return;
}
err = ubi_read(c->ubi, lnum, buf, 0, c->leb_size); err = ubi_read(c->ubi, lnum, buf, 0, c->leb_size);
if (err) { if (err) {
ubifs_err("cannot read LEB %d, error %d", lnum, err); ubifs_err("cannot read LEB %d, error %d", lnum, err);
return; goto out;
} }
while (1) { while (1) {
offs = c->leb_size - len; offs = c->leb_size - len;
if (!is_a_node(c, buf, len)) { if (!is_a_node(c, p, len)) {
int pad_len; int pad_len;
pad_len = get_pad_len(c, buf, len); pad_len = get_pad_len(c, p, len);
if (pad_len) { if (pad_len) {
printk(KERN_DEBUG "LEB %d:%d, pad %d bytes\n", printk(KERN_DEBUG "LEB %d:%d, pad %d bytes\n",
lnum, offs, pad_len); lnum, offs, pad_len);
buf += pad_len; p += pad_len;
len -= pad_len; len -= pad_len;
continue; continue;
} }
...@@ -1909,7 +1915,7 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum) ...@@ -1909,7 +1915,7 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum)
break; break;
} }
node_type = get_lpt_node_type(c, buf, &node_num); node_type = get_lpt_node_type(c, p, &node_num);
switch (node_type) { switch (node_type) {
case UBIFS_LPT_PNODE: case UBIFS_LPT_PNODE:
{ {
...@@ -1934,7 +1940,7 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum) ...@@ -1934,7 +1940,7 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum)
else else
printk(KERN_DEBUG "LEB %d:%d, nnode, ", printk(KERN_DEBUG "LEB %d:%d, nnode, ",
lnum, offs); lnum, offs);
err = ubifs_unpack_nnode(c, buf, &nnode); err = ubifs_unpack_nnode(c, p, &nnode);
for (i = 0; i < UBIFS_LPT_FANOUT; i++) { for (i = 0; i < UBIFS_LPT_FANOUT; i++) {
printk(KERN_CONT "%d:%d", nnode.nbranch[i].lnum, printk(KERN_CONT "%d:%d", nnode.nbranch[i].lnum,
nnode.nbranch[i].offs); nnode.nbranch[i].offs);
...@@ -1955,15 +1961,18 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum) ...@@ -1955,15 +1961,18 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum)
break; break;
default: default:
ubifs_err("LPT node type %d not recognized", node_type); ubifs_err("LPT node type %d not recognized", node_type);
return; goto out;
} }
buf += node_len; p += node_len;
len -= node_len; len -= node_len;
} }
printk(KERN_DEBUG "(pid %d) finish dumping LEB %d\n", printk(KERN_DEBUG "(pid %d) finish dumping LEB %d\n",
current->pid, lnum); current->pid, lnum);
out:
vfree(buf);
return;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment