- chunk = yaffs_AllocateChunk(dev, useReserve,&bi);
-
- if (chunk >= 0) {
- /* First check this chunk is erased, if it needs checking.
- * The checking policy (unless forced always on) is as follows:
- * Check the first page we try to write in a block.
- * - If the check passes then we don't need to check any more.
- * - If the check fails, we check again...
- * If the block has been erased, we don't need to check.
- *
- * However, if the block has been prioritised for gc, then
- * we think there might be something odd about this block
- * and stop using it.
- *
- * Rationale:
- * We should only ever see chunks that have not been erased
- * if there was a partially written chunk due to power loss
- * This checking policy should catch that case with very
- * few checks and thus save a lot of checks that are most likely not
- * needed.
- */
-
- if(bi->gcPrioritise){
- yaffs_DeleteChunk(dev, chunk, 1, __LINE__);
- } else {
-#ifdef CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED
+ yaffs_BlockInfo *bi = 0;
+ int erasedOk = 0;
+
+ chunk = yaffs_AllocateChunk(dev, useReserve, &bi);
+ if (chunk < 0) {
+ /* no space */
+ break;
+ }
+
+ /* First check this chunk is erased, if it needs
+ * checking. The checking policy (unless forced
+ * always on) is as follows:
+ *
+ * Check the first page we try to write in a block.
+ * If the check passes then we don't need to check any
+ * more. If the check fails, we check again...
+ * If the block has been erased, we don't need to check.
+ *
+ * However, if the block has been prioritised for gc,
+ * then we think there might be something odd about
+ * this block and stop using it.
+ *
+ * Rationale: We should only ever see chunks that have
+ * not been erased if there was a partially written
+ * chunk due to power loss. This checking policy should
+ * catch that case with very few checks and thus save a
+ * lot of checks that are most likely not needed.
+ */
+ if (bi->gcPrioritise) {
+ yaffs_DeleteChunk(dev, chunk, 1, __LINE__);
+ /* try another chunk */
+ continue;
+ }