questions about jffs2 jffs2_erase_pending_blocks in erase.c

Aaron Nabil krellboy at gmail.com
Tue Oct 5 17:03:49 EDT 2010


Again apologies if I'm doing this wrong, I rarely poke at the kernel
and only have a few days experience looking at jffs2 and don't
understand the "big picture" yet, but I'm seeing some things I don't
understand and would be grateful for any help.  Please contact me
off-list if you want to send me a "you are so stupid, it's supposed to
be doing that", in fact I'd welcome that over silence.  I'd even thank
you.

My question:

jffs2_erase_pending_blocks is only called with 1 or 0 as count arguments.

 nodemgmt.c jffs2_reserve_space  121 jffs2_erase_pending_blocks(c, 1);
 nodemgmt.c jffs2_find_nextblock 248 jffs2_erase_pending_blocks(c, 1);
 super.c    jffs2_write_super     67 jffs2_erase_pending_blocks(c, 0);

The test  if (!--count) seems to be testing for (count == 1) as the
decrement happens first.  If count is 0 it will be decremented
negative, underflow and wrap around to positive, and then eventually
hit 0 4 billion loop interations later.

Thanks in advance to anyone looking at this,

Aaron

void jffs2_erase_pending_blocks(struct jffs2_sb_info *c, int count)
{
        struct jffs2_eraseblock *jeb;

        mutex_lock(&c->erase_free_sem);

        spin_lock(&c->erase_completion_lock);

        while (!list_empty(&c->erase_complete_list) ||
               !list_empty(&c->erase_pending_list)) {

                if (!list_empty(&c->erase_complete_list)) {
                        jeb = list_entry(c->erase_complete_list.next,
struct jffs2_eraseblock, list);
                        list_move(&jeb->list, &c->erase_checking_list);
                        spin_unlock(&c->erase_completion_lock);
                        mutex_unlock(&c->erase_free_sem);
                        jffs2_mark_erased_block(c, jeb);

                        if (!--count) {            //  decrement then
test is equiv to (count == 1)
                                D1(printk(KERN_DEBUG "Count reached.
jffs2_erase_pending_blocks leaving\n"));
                                goto done;
                        }



More information about the linux-mtd mailing list