blob: e9e3c2c330cc586d3913e9bbcad06088da933525 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
David Woodhousec00c3102007-04-25 14:16:47 +01004 * Copyright © 2001-2007 Red Hat, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Created by David Woodhouse <dwmw2@infradead.org>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.
9 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11
12#include <linux/kernel.h>
13#include <linux/slab.h>
14#include <linux/mtd/mtd.h>
15#include <linux/compiler.h>
16#include <linux/crc32.h>
17#include <linux/sched.h>
18#include <linux/pagemap.h>
19#include "nodelist.h"
20
21struct erase_priv_struct {
22 struct jffs2_eraseblock *jeb;
23 struct jffs2_sb_info *c;
24};
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#ifndef __ECOS
27static void jffs2_erase_callback(struct erase_info *);
28#endif
29static void jffs2_erase_failed(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t bad_offset);
30static void jffs2_erase_succeeded(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
32
33static void jffs2_erase_block(struct jffs2_sb_info *c,
34 struct jffs2_eraseblock *jeb)
35{
36 int ret;
37 uint32_t bad_offset;
38#ifdef __ECOS
39 ret = jffs2_flash_erase(c, jeb);
40 if (!ret) {
41 jffs2_erase_succeeded(c, jeb);
42 return;
43 }
44 bad_offset = jeb->offset;
45#else /* Linux */
46 struct erase_info *instr;
47
Artem B. Bityutskiye0c8e422005-07-24 16:14:17 +010048 D1(printk(KERN_DEBUG "jffs2_erase_block(): erase block %#08x (range %#08x-%#08x)\n",
49 jeb->offset, jeb->offset, jeb->offset + c->sector_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 instr = kmalloc(sizeof(struct erase_info) + sizeof(struct erase_priv_struct), GFP_KERNEL);
51 if (!instr) {
52 printk(KERN_WARNING "kmalloc for struct erase_info in jffs2_erase_block failed. Refiling block for later\n");
53 spin_lock(&c->erase_completion_lock);
Akinobu Mitaf1166292006-06-26 00:24:46 -070054 list_move(&jeb->list, &c->erase_pending_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 c->erasing_size -= c->sector_size;
56 c->dirty_size += c->sector_size;
57 jeb->dirty_size = c->sector_size;
58 spin_unlock(&c->erase_completion_lock);
59 return;
60 }
61
62 memset(instr, 0, sizeof(*instr));
63
64 instr->mtd = c->mtd;
65 instr->addr = jeb->offset;
66 instr->len = c->sector_size;
67 instr->callback = jffs2_erase_callback;
68 instr->priv = (unsigned long)(&instr[1]);
69 instr->fail_addr = 0xffffffff;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 ((struct erase_priv_struct *)instr->priv)->jeb = jeb;
72 ((struct erase_priv_struct *)instr->priv)->c = c;
73
74 ret = c->mtd->erase(c->mtd, instr);
75 if (!ret)
76 return;
77
78 bad_offset = instr->fail_addr;
79 kfree(instr);
80#endif /* __ECOS */
81
82 if (ret == -ENOMEM || ret == -EAGAIN) {
83 /* Erase failed immediately. Refile it on the list */
84 D1(printk(KERN_DEBUG "Erase at 0x%08x failed: %d. Refiling on erase_pending_list\n", jeb->offset, ret));
85 spin_lock(&c->erase_completion_lock);
Akinobu Mitaf1166292006-06-26 00:24:46 -070086 list_move(&jeb->list, &c->erase_pending_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 c->erasing_size -= c->sector_size;
88 c->dirty_size += c->sector_size;
89 jeb->dirty_size = c->sector_size;
90 spin_unlock(&c->erase_completion_lock);
91 return;
92 }
93
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000094 if (ret == -EROFS)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 printk(KERN_WARNING "Erase at 0x%08x failed immediately: -EROFS. Is the sector locked?\n", jeb->offset);
96 else
97 printk(KERN_WARNING "Erase at 0x%08x failed immediately: errno %d\n", jeb->offset, ret);
98
99 jffs2_erase_failed(c, jeb, bad_offset);
100}
101
102void jffs2_erase_pending_blocks(struct jffs2_sb_info *c, int count)
103{
104 struct jffs2_eraseblock *jeb;
105
106 down(&c->erase_free_sem);
107
108 spin_lock(&c->erase_completion_lock);
109
110 while (!list_empty(&c->erase_complete_list) ||
111 !list_empty(&c->erase_pending_list)) {
112
113 if (!list_empty(&c->erase_complete_list)) {
114 jeb = list_entry(c->erase_complete_list.next, struct jffs2_eraseblock, list);
115 list_del(&jeb->list);
116 spin_unlock(&c->erase_completion_lock);
117 jffs2_mark_erased_block(c, jeb);
118
119 if (!--count) {
120 D1(printk(KERN_DEBUG "Count reached. jffs2_erase_pending_blocks leaving\n"));
121 goto done;
122 }
123
124 } else if (!list_empty(&c->erase_pending_list)) {
125 jeb = list_entry(c->erase_pending_list.next, struct jffs2_eraseblock, list);
126 D1(printk(KERN_DEBUG "Starting erase of pending block 0x%08x\n", jeb->offset));
127 list_del(&jeb->list);
128 c->erasing_size += c->sector_size;
129 c->wasted_size -= jeb->wasted_size;
130 c->free_size -= jeb->free_size;
131 c->used_size -= jeb->used_size;
132 c->dirty_size -= jeb->dirty_size;
133 jeb->wasted_size = jeb->used_size = jeb->dirty_size = jeb->free_size = 0;
David Woodhousec38c1b62006-05-25 01:38:27 +0100134 jffs2_free_jeb_node_refs(c, jeb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 list_add(&jeb->list, &c->erasing_list);
136 spin_unlock(&c->erase_completion_lock);
137
138 jffs2_erase_block(c, jeb);
139
140 } else {
141 BUG();
142 }
143
144 /* Be nice */
Joakim Tjernlundfd532492007-06-26 23:32:10 +0200145 yield();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 spin_lock(&c->erase_completion_lock);
147 }
148
149 spin_unlock(&c->erase_completion_lock);
150 done:
151 D1(printk(KERN_DEBUG "jffs2_erase_pending_blocks completed\n"));
152
153 up(&c->erase_free_sem);
154}
155
156static void jffs2_erase_succeeded(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
157{
158 D1(printk(KERN_DEBUG "Erase completed successfully at 0x%08x\n", jeb->offset));
159 spin_lock(&c->erase_completion_lock);
Akinobu Mitaf1166292006-06-26 00:24:46 -0700160 list_move_tail(&jeb->list, &c->erase_complete_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 spin_unlock(&c->erase_completion_lock);
162 /* Ensure that kupdated calls us again to mark them clean */
163 jffs2_erase_pending_trigger(c);
164}
165
166static void jffs2_erase_failed(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t bad_offset)
167{
168 /* For NAND, if the failure did not occur at the device level for a
169 specific physical page, don't bother updating the bad block table. */
170 if (jffs2_cleanmarker_oob(c) && (bad_offset != 0xffffffff)) {
171 /* We had a device-level failure to erase. Let's see if we've
172 failed too many times. */
173 if (!jffs2_write_nand_badblock(c, jeb, bad_offset)) {
174 /* We'd like to give this block another try. */
175 spin_lock(&c->erase_completion_lock);
Akinobu Mitaf1166292006-06-26 00:24:46 -0700176 list_move(&jeb->list, &c->erase_pending_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 c->erasing_size -= c->sector_size;
178 c->dirty_size += c->sector_size;
179 jeb->dirty_size = c->sector_size;
180 spin_unlock(&c->erase_completion_lock);
181 return;
182 }
183 }
184
185 spin_lock(&c->erase_completion_lock);
186 c->erasing_size -= c->sector_size;
187 c->bad_size += c->sector_size;
Akinobu Mitaf1166292006-06-26 00:24:46 -0700188 list_move(&jeb->list, &c->bad_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 c->nr_erasing_blocks--;
190 spin_unlock(&c->erase_completion_lock);
191 wake_up(&c->erase_wait);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000192}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194#ifndef __ECOS
195static void jffs2_erase_callback(struct erase_info *instr)
196{
197 struct erase_priv_struct *priv = (void *)instr->priv;
198
199 if(instr->state != MTD_ERASE_DONE) {
200 printk(KERN_WARNING "Erase at 0x%08x finished, but state != MTD_ERASE_DONE. State is 0x%x instead.\n", instr->addr, instr->state);
201 jffs2_erase_failed(priv->c, priv->jeb, instr->fail_addr);
202 } else {
203 jffs2_erase_succeeded(priv->c, priv->jeb);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 kfree(instr);
206}
207#endif /* !__ECOS */
208
209/* Hmmm. Maybe we should accept the extra space it takes and make
210 this a standard doubly-linked list? */
211static inline void jffs2_remove_node_refs_from_ino_list(struct jffs2_sb_info *c,
212 struct jffs2_raw_node_ref *ref, struct jffs2_eraseblock *jeb)
213{
214 struct jffs2_inode_cache *ic = NULL;
215 struct jffs2_raw_node_ref **prev;
216
217 prev = &ref->next_in_ino;
218
219 /* Walk the inode's list once, removing any nodes from this eraseblock */
220 while (1) {
221 if (!(*prev)->next_in_ino) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000222 /* We're looking at the jffs2_inode_cache, which is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 at the end of the linked list. Stash it and continue
224 from the beginning of the list */
225 ic = (struct jffs2_inode_cache *)(*prev);
226 prev = &ic->nodes;
227 continue;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000228 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Andrew Victor3be36672005-02-09 09:09:05 +0000230 if (SECTOR_ADDR((*prev)->flash_offset) == jeb->offset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 /* It's in the block we're erasing */
232 struct jffs2_raw_node_ref *this;
233
234 this = *prev;
235 *prev = this->next_in_ino;
236 this->next_in_ino = NULL;
237
238 if (this == ref)
239 break;
240
241 continue;
242 }
243 /* Not to be deleted. Skip */
244 prev = &((*prev)->next_in_ino);
245 }
246
247 /* PARANOIA */
248 if (!ic) {
KaiGai Koheic9f700f2006-06-11 10:35:15 +0900249 JFFS2_WARNING("inode_cache/xattr_datum/xattr_ref"
250 " not found in remove_node_refs()!!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return;
252 }
253
254 D1(printk(KERN_DEBUG "Removed nodes in range 0x%08x-0x%08x from ino #%u\n",
255 jeb->offset, jeb->offset + c->sector_size, ic->ino));
256
257 D2({
258 int i=0;
259 struct jffs2_raw_node_ref *this;
260 printk(KERN_DEBUG "After remove_node_refs_from_ino_list: \n" KERN_DEBUG);
261
262 this = ic->nodes;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 while(this) {
265 printk( "0x%08x(%d)->", ref_offset(this), ref_flags(this));
266 if (++i == 5) {
267 printk("\n" KERN_DEBUG);
268 i=0;
269 }
270 this = this->next_in_ino;
271 }
272 printk("\n");
273 });
274
KaiGai Koheic9f700f2006-06-11 10:35:15 +0900275 switch (ic->class) {
276#ifdef CONFIG_JFFS2_FS_XATTR
277 case RAWNODE_CLASS_XATTR_DATUM:
278 jffs2_release_xattr_datum(c, (struct jffs2_xattr_datum *)ic);
279 break;
280 case RAWNODE_CLASS_XATTR_REF:
281 jffs2_release_xattr_ref(c, (struct jffs2_xattr_ref *)ic);
282 break;
283#endif
284 default:
285 if (ic->nodes == (void *)ic && ic->nlink == 0)
286 jffs2_del_ino_cache(c, ic);
287 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
289
David Woodhousec38c1b62006-05-25 01:38:27 +0100290void jffs2_free_jeb_node_refs(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
David Woodhouse9bfeb692006-05-26 21:19:05 +0100292 struct jffs2_raw_node_ref *block, *ref;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 D1(printk(KERN_DEBUG "Freeing all node refs for eraseblock offset 0x%08x\n", jeb->offset));
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000294
David Woodhouse9bfeb692006-05-26 21:19:05 +0100295 block = ref = jeb->first_node;
296
297 while (ref) {
298 if (ref->flash_offset == REF_LINK_NODE) {
299 ref = ref->next_in_ino;
300 jffs2_free_refblock(block);
301 block = ref;
302 continue;
303 }
304 if (ref->flash_offset != REF_EMPTY_NODE && ref->next_in_ino)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 jffs2_remove_node_refs_from_ino_list(c, ref, jeb);
306 /* else it was a non-inode node or already removed, so don't bother */
307
David Woodhouse9bfeb692006-05-26 21:19:05 +0100308 ref++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
David Woodhouse9bfeb692006-05-26 21:19:05 +0100310 jeb->first_node = jeb->last_node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}
312
Thomas Gleixner5d157882005-07-15 08:14:44 +0200313static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t *bad_offset)
314{
315 void *ebuf;
316 uint32_t ofs;
317 size_t retlen;
318 int ret = -EIO;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000319
Joakim Tjernlundfab2c392007-06-01 15:14:09 +0200320 if (c->mtd->point) {
321 unsigned long *wordebuf;
322
323 ret = c->mtd->point(c->mtd, jeb->offset, c->sector_size, &retlen, (unsigned char **)&ebuf);
324 if (ret) {
325 D1(printk(KERN_DEBUG "MTD point failed %d\n", ret));
326 goto do_flash_read;
327 }
328 if (retlen < c->sector_size) {
329 /* Don't muck about if it won't let us point to the whole erase sector */
330 D1(printk(KERN_DEBUG "MTD point returned len too short: 0x%zx\n", retlen));
331 c->mtd->unpoint(c->mtd, ebuf, jeb->offset, c->sector_size);
332 goto do_flash_read;
333 }
334 wordebuf = ebuf-sizeof(*wordebuf);
335 retlen /= sizeof(*wordebuf);
336 do {
337 if (*++wordebuf != ~0)
338 break;
339 } while(--retlen);
340 c->mtd->unpoint(c->mtd, ebuf, jeb->offset, c->sector_size);
341 if (retlen)
342 printk(KERN_WARNING "Newly-erased block contained word 0x%lx at offset 0x%08x\n",
343 *wordebuf, jeb->offset + c->sector_size-retlen*sizeof(*wordebuf));
344 return 0;
345 }
346 do_flash_read:
Thomas Gleixner5d157882005-07-15 08:14:44 +0200347 ebuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
348 if (!ebuf) {
349 printk(KERN_WARNING "Failed to allocate page buffer for verifying erase at 0x%08x. Refiling\n", jeb->offset);
350 return -EAGAIN;
351 }
352
353 D1(printk(KERN_DEBUG "Verifying erase at 0x%08x\n", jeb->offset));
354
355 for (ofs = jeb->offset; ofs < jeb->offset + c->sector_size; ) {
356 uint32_t readlen = min((uint32_t)PAGE_SIZE, jeb->offset + c->sector_size - ofs);
357 int i;
358
359 *bad_offset = ofs;
360
Artem Bityutskiyb0afbbe2007-03-21 11:07:05 +0200361 ret = c->mtd->read(c->mtd, ofs, readlen, &retlen, ebuf);
Thomas Gleixner5d157882005-07-15 08:14:44 +0200362 if (ret) {
363 printk(KERN_WARNING "Read of newly-erased block at 0x%08x failed: %d. Putting on bad_list\n", ofs, ret);
364 goto fail;
365 }
366 if (retlen != readlen) {
367 printk(KERN_WARNING "Short read from newly-erased block at 0x%08x. Wanted %d, got %zd\n", ofs, readlen, retlen);
368 goto fail;
369 }
370 for (i=0; i<readlen; i += sizeof(unsigned long)) {
371 /* It's OK. We know it's properly aligned */
372 unsigned long *datum = ebuf + i;
373 if (*datum + 1) {
374 *bad_offset += i;
375 printk(KERN_WARNING "Newly-erased block contained word 0x%lx at offset 0x%08x\n", *datum, *bad_offset);
376 goto fail;
377 }
378 }
379 ofs += readlen;
380 cond_resched();
381 }
382 ret = 0;
383fail:
384 kfree(ebuf);
385 return ret;
386}
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
389{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 size_t retlen;
391 int ret;
392 uint32_t bad_offset;
393
Thomas Gleixner5d157882005-07-15 08:14:44 +0200394 switch (jffs2_block_check_erase(c, jeb, &bad_offset)) {
395 case -EAGAIN: goto refile;
396 case -EIO: goto filebad;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000399 /* Write the erase complete marker */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 D1(printk(KERN_DEBUG "Writing erased marker to block at 0x%08x\n", jeb->offset));
Thomas Gleixner5d157882005-07-15 08:14:44 +0200401 bad_offset = jeb->offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Thomas Gleixner5d157882005-07-15 08:14:44 +0200403 /* Cleanmarker in oob area or no cleanmarker at all ? */
404 if (jffs2_cleanmarker_oob(c) || c->cleanmarker_size == 0) {
405
406 if (jffs2_cleanmarker_oob(c)) {
407 if (jffs2_write_nand_cleanmarker(c, jeb))
408 goto filebad;
409 }
410
David Woodhousef1f96712006-05-20 19:45:26 +0100411 /* Everything else got zeroed before the erase */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 jeb->free_size = c->sector_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 } else {
Thomas Gleixner5d157882005-07-15 08:14:44 +0200414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 struct kvec vecs[1];
416 struct jffs2_unknown_node marker = {
417 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
418 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
419 .totlen = cpu_to_je32(c->cleanmarker_size)
420 };
421
David Woodhouse046b8b92006-05-25 01:50:35 +0100422 jffs2_prealloc_raw_node_refs(c, jeb, 1);
Thomas Gleixner5d157882005-07-15 08:14:44 +0200423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 marker.hdr_crc = cpu_to_je32(crc32(0, &marker, sizeof(struct jffs2_unknown_node)-4));
425
426 vecs[0].iov_base = (unsigned char *) &marker;
427 vecs[0].iov_len = sizeof(marker);
428 ret = jffs2_flash_direct_writev(c, vecs, 1, jeb->offset, &retlen);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000429
Thomas Gleixner5d157882005-07-15 08:14:44 +0200430 if (ret || retlen != sizeof(marker)) {
431 if (ret)
432 printk(KERN_WARNING "Write clean marker to block at 0x%08x failed: %d\n",
433 jeb->offset, ret);
434 else
435 printk(KERN_WARNING "Short write to newly-erased block at 0x%08x: Wanted %zd, got %zd\n",
436 jeb->offset, sizeof(marker), retlen);
437
Thomas Gleixner5d157882005-07-15 08:14:44 +0200438 goto filebad;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 }
440
David Woodhousef1f96712006-05-20 19:45:26 +0100441 /* Everything else got zeroed before the erase */
442 jeb->free_size = c->sector_size;
David Woodhouse2f785402006-05-24 02:04:45 +0100443 /* FIXME Special case for cleanmarker in empty block */
444 jffs2_link_node_ref(c, jeb, jeb->offset | REF_NORMAL, c->cleanmarker_size, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 }
446
447 spin_lock(&c->erase_completion_lock);
448 c->erasing_size -= c->sector_size;
449 c->free_size += jeb->free_size;
450 c->used_size += jeb->used_size;
451
Artem B. Bityutskiye0c8e422005-07-24 16:14:17 +0100452 jffs2_dbg_acct_sanity_check_nolock(c,jeb);
453 jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
455 list_add_tail(&jeb->list, &c->free_list);
456 c->nr_erasing_blocks--;
457 c->nr_free_blocks++;
458 spin_unlock(&c->erase_completion_lock);
459 wake_up(&c->erase_wait);
Thomas Gleixner5d157882005-07-15 08:14:44 +0200460 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Thomas Gleixner5d157882005-07-15 08:14:44 +0200462filebad:
463 spin_lock(&c->erase_completion_lock);
464 /* Stick it on a list (any list) so erase_failed can take it
465 right off again. Silly, but shouldn't happen often. */
466 list_add(&jeb->list, &c->erasing_list);
467 spin_unlock(&c->erase_completion_lock);
468 jffs2_erase_failed(c, jeb, bad_offset);
469 return;
470
471refile:
472 /* Stick it back on the list from whence it came and come back later */
473 jffs2_erase_pending_trigger(c);
474 spin_lock(&c->erase_completion_lock);
475 list_add(&jeb->list, &c->erase_complete_list);
476 spin_unlock(&c->erase_completion_lock);
477 return;
478}