Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 107283
b: refs/heads/master
c: b7600db
h: refs/heads/master
i:
  107281: 5ecf367
  107279: 8dee7cb
v: v3
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Aug 1, 2008
1 parent d158697 commit 4210f84
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: f6ed6f78d46b43b6d908b39ed3322f7cda23f4a8
refs/heads/master: b7600dba6d4fbf3897e517b322d006986cce831a
40 changes: 26 additions & 14 deletions trunk/fs/jffs2/summary.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@

int jffs2_sum_init(struct jffs2_sb_info *c)
{
uint32_t sum_size = max_t(uint32_t, c->sector_size, MAX_SUMMARY_SIZE);

c->summary = kzalloc(sizeof(struct jffs2_summary), GFP_KERNEL);

if (!c->summary) {
JFFS2_WARNING("Can't allocate memory for summary information!\n");
return -ENOMEM;
}

c->summary->sum_buf = vmalloc(c->sector_size);
c->summary->sum_buf = kmalloc(sum_size, GFP_KERNEL);

if (!c->summary->sum_buf) {
JFFS2_WARNING("Can't allocate buffer for writing out summary information!\n");
Expand All @@ -49,7 +51,7 @@ void jffs2_sum_exit(struct jffs2_sb_info *c)

jffs2_sum_disable_collecting(c->summary);

vfree(c->summary->sum_buf);
kfree(c->summary->sum_buf);
c->summary->sum_buf = NULL;

kfree(c->summary);
Expand Down Expand Up @@ -665,7 +667,7 @@ int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb
/* Write summary data to flash - helper function for jffs2_sum_write_sumnode() */

static int jffs2_sum_write_data(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
uint32_t infosize, uint32_t datasize, int padsize)
uint32_t infosize, uint32_t datasize, int padsize)
{
struct jffs2_raw_summary isum;
union jffs2_sum_mem *temp;
Expand All @@ -676,6 +678,26 @@ static int jffs2_sum_write_data(struct jffs2_sb_info *c, struct jffs2_eraseblock
int ret;
size_t retlen;

if (padsize + datasize > MAX_SUMMARY_SIZE) {
/* It won't fit in the buffer. Abort summary for this jeb */
jffs2_sum_disable_collecting(c->summary);

JFFS2_WARNING("Summary too big (%d data, %d pad) in eraseblock at %08x\n",
datasize, padsize, jeb->offset);
/* Non-fatal */
return 0;
}
/* Is there enough space for summary? */
if (padsize < 0) {
/* don't try to write out summary for this jeb */
jffs2_sum_disable_collecting(c->summary);

JFFS2_WARNING("Not enough space for summary, padsize = %d\n",
padsize);
/* Non-fatal */
return 0;
}

memset(c->summary->sum_buf, 0xff, datasize);
memset(&isum, 0, sizeof(isum));

Expand Down Expand Up @@ -821,7 +843,7 @@ int jffs2_sum_write_sumnode(struct jffs2_sb_info *c)
{
int datasize, infosize, padsize;
struct jffs2_eraseblock *jeb;
int ret;
int ret = 0;

dbg_summary("called\n");

Expand All @@ -841,16 +863,6 @@ int jffs2_sum_write_sumnode(struct jffs2_sb_info *c)
infosize += padsize;
datasize += padsize;

/* Is there enough space for summary? */
if (padsize < 0) {
/* don't try to write out summary for this jeb */
jffs2_sum_disable_collecting(c->summary);

JFFS2_WARNING("Not enough space for summary, padsize = %d\n", padsize);
spin_lock(&c->erase_completion_lock);
return 0;
}

ret = jffs2_sum_write_data(c, jeb, infosize, datasize, padsize);
spin_lock(&c->erase_completion_lock);
return ret;
Expand Down
6 changes: 6 additions & 0 deletions trunk/fs/jffs2/summary.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
#ifndef JFFS2_SUMMARY_H
#define JFFS2_SUMMARY_H

/* Limit summary size to 64KiB so that we can kmalloc it. If the summary
is larger than that, we have to just ditch it and avoid using summary
for the eraseblock in question... and it probably doesn't hurt us much
anyway. */
#define MAX_SUMMARY_SIZE 65536

#include <linux/uio.h>
#include <linux/jffs2.h>

Expand Down

0 comments on commit 4210f84

Please sign in to comment.