ebuf = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!ebuf) { printk(KERN_WARNING "Failed to allocate page buffer for verifying erase at 0x%08x. Assuming it worked\n", jeb->offset); } else { uint32_t ofs = jeb->offset;  D1(printk(KERN_DEBUG "Verifying erase at 0x%08x\n", jeb->offset)); while(ofs < jeb->offset + c->sector_size) { uint32_t readlen = min((uint32_t)PAGE_SIZE, jeb->offset + c->sector_size - ofs); int i;  bad_offset = ofs;  ret = c->mtd->read(c->mtd, ofs, readlen, &retlen, ebuf);  if (ret) { printk(KERN_WARNING "Read of newly-erased block at 0x%08x failed: %d. Putting on bad_list\n", ofs, ret); goto bad; } if (retlen != readlen) { printk(KERN_WARNING "Short read from newly-erased block at 0x%08x. Wanted %d, got %zd\n", ofs, readlen, retlen); goto bad; } for (i=0; i<readlen; i += sizeof(unsigned long)) { /* It's OK. We know it's properly aligned */ unsigned long datum = *(unsigned long *)(&ebuf[i]); if (datum + 1) { bad_offset += i; printk(KERN_WARNING "Newly-erased block contained word 0x%lx at offset 0x%08x\n", datum, bad_offset); bad: if ((!jffs2_cleanmarker_oob(c)) && (c->cleanmarker_size > 0)) jffs2_free_raw_node_ref(marker_ref); kfree(ebuf); bad2: spin_lock(&c->erase_completion_lock); /* Stick it on a list (any list) so erase_failed can take it right off again.  Silly, but shouldn't happen often. */ list_add(&jeb->list, &c->erasing_list); spin_unlock(&c->erase_completion_lock); jffs2_erase_failed(c, jeb, bad_offset); return; } } ofs += readlen; cond_resched(); } kfree(ebuf); }  bad_offset = jeb->offset; 
static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb){	struct jffs2_raw_node_ref *marker_ref = NULL;	unsigned char *ebuf;	size_t retlen;	int ret;	uint32_t bad_offset;	if ((!jffs2_cleanmarker_oob(c)) && (c->cleanmarker_size > 0)) {		marker_ref = jffs2_alloc_raw_node_ref();		if (!marker_ref) {			printk(KERN_WARNING "Failed to allocate raw node ref for clean marker\n");			/* Stick it back on the list from whence it came and come back later */			jffs2_erase_pending_trigger(c);			spin_lock(&c->erase_completion_lock);			list_add(&jeb->list, &c->erase_complete_list);			spin_unlock(&c->erase_completion_lock);			return;		}	}	ebuf = kmalloc(PAGE_SIZE, GFP_KERNEL);	if (!ebuf) {		printk(KERN_WARNING "Failed to allocate page buffer for verifying erase at 0x%08x. Assuming it worked\n", jeb->offset);	} else {		uint32_t ofs = jeb->offset;		D1(printk(KERN_DEBUG "Verifying erase at 0x%08x\n", jeb->offset));		while(ofs < jeb->offset + c->sector_size) {			uint32_t readlen = min((uint32_t)PAGE_SIZE, jeb->offset + c->sector_size - ofs);			int i;			bad_offset = ofs;			ret = c->mtd->read(c->mtd, ofs, readlen, &retlen, ebuf);			if (ret) {				printk(KERN_WARNING "Read of newly-erased block at 0x%08x failed: %d. Putting on bad_list\n", ofs, ret);				goto bad;			}			if (retlen != readlen) {				printk(KERN_WARNING "Short read from newly-erased block at 0x%08x. Wanted %d, got %zd\n", ofs, readlen, retlen);				goto bad;			}			for (i=0; i<readlen; i += sizeof(unsigned long)) {				/* It's OK. We know it's properly aligned */				unsigned long datum = *(unsigned long *)(&ebuf[i]);				if (datum + 1) {					bad_offset += i;					printk(KERN_WARNING "Newly-erased block contained word 0x%lx at offset 0x%08x\n", datum, bad_offset);				bad: 					if ((!jffs2_cleanmarker_oob(c)) && (c->cleanmarker_size > 0))						jffs2_free_raw_node_ref(marker_ref);					kfree(ebuf);				bad2:					spin_lock(&c->erase_completion_lock);					/* Stick it on a list (any list) so					   erase_failed can take it right off					   again.  Silly, but shouldn't happen					   often. */					list_add(&jeb->list, &c->erasing_list);					spin_unlock(&c->erase_completion_lock);					jffs2_erase_failed(c, jeb, bad_offset);					return;				}			}			ofs += readlen;			cond_resched();		}		kfree(ebuf);	}	bad_offset = jeb->offset;	/* Write the erase complete marker */		D1(printk(KERN_DEBUG "Writing erased marker to block at 0x%08x\n", jeb->offset));	if (jffs2_cleanmarker_oob(c)) {		if (jffs2_write_nand_cleanmarker(c, jeb))			goto bad2;					jeb->first_node = jeb->last_node = NULL;		jeb->free_size = c->sector_size;		jeb->used_size = 0;		jeb->dirty_size = 0;		jeb->wasted_size = 0;	} else if (c->cleanmarker_size == 0) {		jeb->first_node = jeb->last_node = NULL;		jeb->free_size = c->sector_size;		jeb->used_size = 0;		jeb->dirty_size = 0;		jeb->wasted_size = 0;	} else {		struct kvec vecs[1];		struct jffs2_unknown_node marker = {			.magic =	cpu_to_je16(JFFS2_MAGIC_BITMASK),			.nodetype =	cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),			.totlen =	cpu_to_je32(c->cleanmarker_size)		};		marker.hdr_crc = cpu_to_je32(crc32(0, &marker, sizeof(struct jffs2_unknown_node)-4));		vecs[0].iov_base = (unsigned char *) &marker;		vecs[0].iov_len = sizeof(marker);		ret = jffs2_flash_direct_writev(c, vecs, 1, jeb->offset, &retlen);				if (ret) {			printk(KERN_WARNING "Write clean marker to block at 0x%08x failed: %d\n",			       jeb->offset, ret);			goto bad2;		}		if (retlen != sizeof(marker)) {			printk(KERN_WARNING "Short write to newly-erased block at 0x%08x: Wanted %zd, got %zd\n",			       jeb->offset, sizeof(marker), retlen);			goto bad2;		}		marker_ref->next_in_ino = NULL;		marker_ref->next_phys = NULL;		marker_ref->flash_offset = jeb->offset | REF_NORMAL;		marker_ref->__totlen = c->cleanmarker_size;					jeb->first_node = jeb->last_node = marker_ref;					jeb->free_size = c->sector_size - c->cleanmarker_size;		jeb->used_size = c->cleanmarker_size;		jeb->dirty_size = 0;		jeb->wasted_size = 0;	}	spin_lock(&c->erase_completion_lock);	c->erasing_size -= c->sector_size;	c->free_size += jeb->free_size;	c->used_size += jeb->used_size;	ACCT_SANITY_CHECK(c,jeb);	D1(ACCT_PARANOIA_CHECK(jeb));	list_add_tail(&jeb->list, &c->free_list);	c->nr_erasing_blocks--;	c->nr_free_blocks++;	spin_unlock(&c->erase_completion_lock);	wake_up(&c->erase_wait);}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/5d157885f383ccc0660c011fa488ae4edb77ab16/erase.c/buggy/fs/jffs2/erase.c