Skip to content

Commit

Permalink
[JFFS2] Calculate CRC check starting point correctly
Browse files Browse the repository at this point in the history
When data starts from the beginning of NAND page, 'len' must be zero, not
c->wbuf_page.

Thanks to Zoltan Sogor for reporting this problem.

Signed-off-by: Artem B. Bityutskiy <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
  • Loading branch information
dedekind authored and Thomas Gleixner committed Nov 6, 2005
1 parent 8d5df40 commit 280562b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions fs/jffs2/nodelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* For licensing information, see the file 'LICENCE' in this directory.
*
* $Id: nodelist.c,v 1.110 2005/08/17 14:13:45 dedekind Exp $
* $Id: nodelist.c,v 1.111 2005/08/17 14:57:39 dedekind Exp $
*
*/

Expand Down Expand Up @@ -413,7 +413,8 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
/* Calculate how many bytes were already checked */
ofs = ref_offset(ref) + sizeof(struct jffs2_raw_inode);
len = ofs & (c->wbuf_pagesize - 1);
len = c->wbuf_pagesize - len;
if (likely(len))
len = c->wbuf_pagesize - len;

if (len >= tn->csize) {
JFFS2_DBG_READINODE("no need to check node at %#08x, data length %u, data starts at %#08x - it has already been checked.\n",
Expand Down
12 changes: 6 additions & 6 deletions fs/jffs2/readinode.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* For licensing information, see the file 'LICENCE' in this directory.
*
* $Id: readinode.c,v 1.140 2005/08/17 13:46:23 dedekind Exp $
* $Id: readinode.c,v 1.141 2005/08/17 14:57:39 dedekind Exp $
*
*/

Expand Down Expand Up @@ -272,9 +272,9 @@ static inline int read_dnode(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
buf = (unsigned char *)rd + sizeof(*rd);
/* len will be the read data length */
len = min_t(uint32_t, rdlen - sizeof(*rd), csize);

if (len)
tn->partial_crc = crc = crc32(0, buf, len);
tn->partial_crc = crc32(0, buf, len);

JFFS2_DBG_READINODE("Calculates CRC (%#08x) for %d bytes, csize %d\n", tn->partial_crc, len, csize);

/* If we actually calculated the whole data CRC
* and it is wrong, drop the node. */
Expand Down Expand Up @@ -327,8 +327,8 @@ static inline int read_dnode(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
else // normal case...
tn->fn->size = je32_to_cpu(rd->dsize);

JFFS2_DBG_READINODE("dnode @%08x: ver %u, offset %#04x, dsize %#04x\n",
ref_offset(ref), je32_to_cpu(rd->version), je32_to_cpu(rd->offset), je32_to_cpu(rd->dsize));
JFFS2_DBG_READINODE("dnode @%08x: ver %u, offset %#04x, dsize %#04x, csize %#04x\n",
ref_offset(ref), je32_to_cpu(rd->version), je32_to_cpu(rd->offset), je32_to_cpu(rd->dsize), csize);

jffs2_add_tn_to_tree(tn, tnp);

Expand Down

0 comments on commit 280562b

Please sign in to comment.