yaffs: Clean up as per Ryan's comments
authorCharles Manning <cdhmanning@gmail.com>
Mon, 31 Jan 2011 21:57:18 +0000 (10:57 +1300)
committerCharles Manning <cdhmanning@gmail.com>
Mon, 31 Jan 2011 21:57:18 +0000 (10:57 +1300)
Clean up a whole lot of code issues raised by Ryan.

Some further reformatting etc to be mor kernel friendly.

Signed-off-by: Charles Manning <cdhmanning@gmail.com>
20 files changed:
yaffs_allocator.c
yaffs_checkptrw.c
yaffs_ecc.c
yaffs_guts.c
yaffs_guts.h
yaffs_mtdif.c
yaffs_mtdif1_multi.c
yaffs_mtdif1_single.c
yaffs_mtdif2_multi.c
yaffs_mtdif2_single.c
yaffs_nameval.c
yaffs_nand.c
yaffs_packedtags1.c
yaffs_packedtags2.c
yaffs_tagscompat.c
yaffs_tagsvalidity.c
yaffs_verify.c
yaffs_vfs_single.c
yaffs_yaffs1.c
yaffs_yaffs2.c

index 1dd0c27b91682b8cd274d8d4a67d9ddf019566d2..695c2541153e937580bbf2c87b72bc704425c7ba 100644 (file)
 #include "yaffs_trace.h"
 #include "yportenv.h"
 
+/*
+ * Each entry in yaffs_tnode_list and yaffs_obj_list hold blocks
+ * of approx 100 objects that are themn allocated singly.
+ * This is basically a simplified slab allocator.
+ *
+ * We don't use the Linux slab allocator because slab does not allow
+ * us to dump all the objects in one hit when we do a umount and tear
+ * down  all the tnodes and objects. slab requires that we first free
+ * the individual objects.
+ *
+ * Once yaffs has been mainlined I shall try to motivate for a change
+ * to slab to provide the extra features we need here.
+ */
 
 struct yaffs_tnode_list {
        struct yaffs_tnode_list *next;
@@ -34,7 +47,7 @@ struct yaffs_allocator {
        struct yaffs_tnode_list *alloc_tnode_list;
 
        int n_obj_created;
-       struct yaffs_obj *free_objs;
+       struct list_head free_objs;
        int n_free_objects;
 
        struct yaffs_obj_list *allocated_obj_list;
@@ -68,14 +81,15 @@ static void yaffs_init_raw_tnodes(struct yaffs_dev *dev)
 {
        struct yaffs_allocator *allocator = dev->allocator;
 
-       if (allocator) {
-               allocator->alloc_tnode_list = NULL;
-               allocator->free_tnodes = NULL;
-               allocator->n_free_tnodes = 0;
-               allocator->n_tnodes_created = 0;
-       } else {
+       if (!allocator) {
                BUG();
+               return;
        }
+
+       allocator->alloc_tnode_list = NULL;
+       allocator->free_tnodes = NULL;
+       allocator->n_free_tnodes = 0;
+       allocator->n_tnodes_created = 0;
 }
 
 static int yaffs_create_tnodes(struct yaffs_dev *dev, int n_tnodes)
@@ -183,17 +197,24 @@ void yaffs_free_raw_tnode(struct yaffs_dev *dev, struct yaffs_tnode *tn)
        dev->checkpoint_blocks_required = 0;    /* force recalculation */
 }
 
+/*--------------- yaffs_obj alloaction ------------------------
+ *
+ * Free yaffs_objs are stored in a list using obj->siblings.
+ * The blocks of allocated objects are stored in a linked list.
+ */
+
 static void yaffs_init_raw_objs(struct yaffs_dev *dev)
 {
        struct yaffs_allocator *allocator = dev->allocator;
 
-       if (allocator) {
-               allocator->allocated_obj_list = NULL;
-               allocator->free_objs = NULL;
-               allocator->n_free_objects = 0;
-       } else {
+       if (!allocator) {
                BUG();
+               return;
        }
+
+       allocator->allocated_obj_list = NULL;
+       INIT_LIST_HEAD(&allocator->free_objs);
+       allocator->n_free_objects = 0;
 }
 
 static void yaffs_deinit_raw_objs(struct yaffs_dev *dev)
@@ -210,11 +231,10 @@ static void yaffs_deinit_raw_objs(struct yaffs_dev *dev)
                tmp = allocator->allocated_obj_list->next;
                kfree(allocator->allocated_obj_list->objects);
                kfree(allocator->allocated_obj_list);
-
                allocator->allocated_obj_list = tmp;
        }
 
-       allocator->free_objs = NULL;
+       INIT_LIST_HEAD(&allocator->free_objs);
        allocator->n_free_objects = 0;
        allocator->n_obj_created = 0;
 }
@@ -249,13 +269,9 @@ static int yaffs_create_free_objs(struct yaffs_dev *dev, int n_obj)
        }
 
        /* Hook them into the free list */
-       for (i = 0; i < n_obj - 1; i++) {
-               new_objs[i].siblings.next =
-                   (struct list_head *)(&new_objs[i + 1]);
-       }
+       for (i = 0; i < n_obj; i++)
+               list_add(&new_objs[i].siblings, &allocator->free_objs);
 
-       new_objs[n_obj - 1].siblings.next = (void *)allocator->free_objs;
-       allocator->free_objs = new_objs;
        allocator->n_free_objects += n_obj;
        allocator->n_obj_created += n_obj;
 
@@ -271,6 +287,7 @@ static int yaffs_create_free_objs(struct yaffs_dev *dev, int n_obj)
 struct yaffs_obj *yaffs_alloc_raw_obj(struct yaffs_dev *dev)
 {
        struct yaffs_obj *obj = NULL;
+       struct list_head *lh;
        struct yaffs_allocator *allocator = dev->allocator;
 
        if (!allocator) {
@@ -279,13 +296,13 @@ struct yaffs_obj *yaffs_alloc_raw_obj(struct yaffs_dev *dev)
        }
 
        /* If there are none left make more */
-       if (!allocator->free_objs)
+       if (list_empty(&allocator->free_objs))
                yaffs_create_free_objs(dev, YAFFS_ALLOCATION_NOBJECTS);
 
-       if (allocator->free_objs) {
-               obj = allocator->free_objs;
-               allocator->free_objs =
-                   (struct yaffs_obj *)(allocator->free_objs->siblings.next);
+       if (!list_empty(&allocator->free_objs)) {
+               lh = allocator->free_objs.next;
+               obj = list_entry(lh, struct yaffs_obj, siblings);
+               list_del_init(lh);
                allocator->n_free_objects--;
        }
 
@@ -297,42 +314,44 @@ void yaffs_free_raw_obj(struct yaffs_dev *dev, struct yaffs_obj *obj)
 
        struct yaffs_allocator *allocator = dev->allocator;
 
-       if (!allocator)
+       if (!allocator) {
                BUG();
-       else {
-               /* Link into the free list. */
-               obj->siblings.next = (struct list_head *)(allocator->free_objs);
-               allocator->free_objs = obj;
-               allocator->n_free_objects++;
+               return;
        }
+
+       /* Link into the free list. */
+       list_add(&obj->siblings, &allocator->free_objs);
+       allocator->n_free_objects++;
 }
 
 void yaffs_deinit_raw_tnodes_and_objs(struct yaffs_dev *dev)
 {
-       if (dev->allocator) {
-               yaffs_deinit_raw_tnodes(dev);
-               yaffs_deinit_raw_objs(dev);
 
-               kfree(dev->allocator);
-               dev->allocator = NULL;
-       } else {
+       if (!dev->allocator) {
                BUG();
+               return;
        }
+
+       yaffs_deinit_raw_tnodes(dev);
+       yaffs_deinit_raw_objs(dev);
+       kfree(dev->allocator);
+       dev->allocator = NULL;
 }
 
 void yaffs_init_raw_tnodes_and_objs(struct yaffs_dev *dev)
 {
        struct yaffs_allocator *allocator;
 
-       if (!dev->allocator) {
-               allocator = kmalloc(sizeof(struct yaffs_allocator), GFP_NOFS);
-               if (allocator) {
-                       dev->allocator = allocator;
-                       yaffs_init_raw_tnodes(dev);
-                       yaffs_init_raw_objs(dev);
-               }
-       } else {
+       if (dev->allocator) {
                BUG();
+               return;
+       }
+
+       allocator = kmalloc(sizeof(struct yaffs_allocator), GFP_NOFS);
+       if (allocator) {
+               dev->allocator = allocator;
+               yaffs_init_raw_tnodes(dev);
+               yaffs_init_raw_objs(dev);
        }
 }
 
index 711df13e5cd36ef18523f8eacec75b3d23ee1cb8..7faf2860f923775952300824a34562d152641ad7 100644 (file)
@@ -137,6 +137,8 @@ static void yaffs2_checkpt_find_block(struct yaffs_dev *dev)
 
 int yaffs2_checkpt_open(struct yaffs_dev *dev, int writing)
 {
+       int i;
+
        dev->checkpt_open_write = writing;
 
        /* Got the functions we need? */
@@ -167,25 +169,24 @@ int yaffs2_checkpt_open(struct yaffs_dev *dev, int writing)
                memset(dev->checkpt_buffer, 0, dev->data_bytes_per_chunk);
                dev->checkpt_byte_offs = 0;
                return yaffs_checkpt_erase(dev);
-       } else {
-               int i;
-               /* Set to a value that will kick off a read */
-               dev->checkpt_byte_offs = dev->data_bytes_per_chunk;
-               /* A checkpoint block list of 1 checkpoint block per 16 block is
-                * (hopefully) going to be way more than we need */
-               dev->blocks_in_checkpt = 0;
-               dev->checkpt_max_blocks =
-                   (dev->internal_end_block - dev->internal_start_block) / 16 +
-                   2;
-               dev->checkpt_block_list =
-                   kmalloc(sizeof(int) * dev->checkpt_max_blocks, GFP_NOFS);
-               if (!dev->checkpt_block_list)
-                       return 0;
-
-               for (i = 0; i < dev->checkpt_max_blocks; i++)
-                       dev->checkpt_block_list[i] = -1;
        }
 
+       /* Set to a value that will kick off a read */
+       dev->checkpt_byte_offs = dev->data_bytes_per_chunk;
+       /* A checkpoint block list of 1 checkpoint block per 16 block is
+        * (hopefully) going to be way more than we need */
+       dev->blocks_in_checkpt = 0;
+       dev->checkpt_max_blocks =
+           (dev->internal_end_block - dev->internal_start_block) / 16 + 2;
+       dev->checkpt_block_list =
+           kmalloc(sizeof(int) * dev->checkpt_max_blocks, GFP_NOFS);
+
+       if (!dev->checkpt_block_list)
+               return 0;
+
+       for (i = 0; i < dev->checkpt_max_blocks; i++)
+               dev->checkpt_block_list[i] = -1;
+
        return 1;
 }
 
@@ -308,49 +309,47 @@ int yaffs2_checkpt_rd(struct yaffs_dev *dev, void *data, int n_bytes)
                                dev->checkpt_cur_chunk = 0;
                        }
 
-                       if (dev->checkpt_cur_block < 0)
+                       if (dev->checkpt_cur_block < 0) {
                                ok = 0;
-                       else {
-                               chunk = dev->checkpt_cur_block *
-                                   dev->param.chunks_per_block +
-                                   dev->checkpt_cur_chunk;
-
-                               realigned_chunk = chunk - dev->chunk_offset;
-
-                               dev->n_page_reads++;
-
-                               /* read in the next chunk */
-                               dev->param.read_chunk_tags_fn(dev,
-                                                       realigned_chunk,
-                                                       dev->checkpt_buffer,
-                                                       &tags);
-
-                               if (tags.chunk_id != (dev->checkpt_page_seq + 1)
-                                   || tags.ecc_result > YAFFS_ECC_RESULT_FIXED
-                                   || tags.seq_number !=
-                                   YAFFS_SEQUENCE_CHECKPOINT_DATA)
-                                       ok = 0;
-
-                               dev->checkpt_byte_offs = 0;
-                               dev->checkpt_page_seq++;
-                               dev->checkpt_cur_chunk++;
-
-                               if (dev->checkpt_cur_chunk >=
-                                   dev->param.chunks_per_block)
-                                       dev->checkpt_cur_block = -1;
+                               break;
                        }
-               }
 
-               if (ok) {
-                       *data_bytes =
-                           dev->checkpt_buffer[dev->checkpt_byte_offs];
-                       dev->checkpt_sum += *data_bytes;
-                       dev->checkpt_xor ^= *data_bytes;
-                       dev->checkpt_byte_offs++;
-                       i++;
-                       data_bytes++;
-                       dev->checkpt_byte_count++;
+                       chunk = dev->checkpt_cur_block *
+                           dev->param.chunks_per_block +
+                           dev->checkpt_cur_chunk;
+
+                       realigned_chunk = chunk - dev->chunk_offset;
+                       dev->n_page_reads++;
+
+                       /* read in the next chunk */
+                       dev->param.read_chunk_tags_fn(dev,
+                                               realigned_chunk,
+                                               dev->checkpt_buffer,
+                                               &tags);
+
+                       if (tags.chunk_id != (dev->checkpt_page_seq + 1) ||
+                           tags.ecc_result > YAFFS_ECC_RESULT_FIXED ||
+                           tags.seq_number != YAFFS_SEQUENCE_CHECKPOINT_DATA) {
+                               ok = 0;
+                               break;
+                       }
+
+                       dev->checkpt_byte_offs = 0;
+                       dev->checkpt_page_seq++;
+                       dev->checkpt_cur_chunk++;
+
+                       if (dev->checkpt_cur_chunk >=
+                                       dev->param.chunks_per_block)
+                               dev->checkpt_cur_block = -1;
                }
+
+               *data_bytes = dev->checkpt_buffer[dev->checkpt_byte_offs];
+               dev->checkpt_sum += *data_bytes;
+               dev->checkpt_xor ^= *data_bytes;
+               dev->checkpt_byte_offs++;
+               i++;
+               data_bytes++;
+               dev->checkpt_byte_count++;
        }
 
        return i;
@@ -358,18 +357,20 @@ int yaffs2_checkpt_rd(struct yaffs_dev *dev, void *data, int n_bytes)
 
 int yaffs_checkpt_close(struct yaffs_dev *dev)
 {
+       int i;
+
        if (dev->checkpt_open_write) {
                if (dev->checkpt_byte_offs != 0)
                        yaffs2_checkpt_flush_buffer(dev);
        } else if (dev->checkpt_block_list) {
-               int i;
                for (i = 0;
-                    i < dev->blocks_in_checkpt
-                    && dev->checkpt_block_list[i] >= 0; i++) {
+                    i < dev->blocks_in_checkpt &&
+                    dev->checkpt_block_list[i] >= 0; i++) {
                        int blk = dev->checkpt_block_list[i];
                        struct yaffs_block_info *bi = NULL;
-                       if (dev->internal_start_block <= blk
-                           && blk <= dev->internal_end_block)
+
+                       if (dev->internal_start_block <= blk &&
+                           blk <= dev->internal_end_block)
                                bi = yaffs_get_block_info(dev, blk);
                        if (bi && bi->block_state == YAFFS_BLOCK_STATE_EMPTY)
                                bi->block_state = YAFFS_BLOCK_STATE_CHECKPOINT;
@@ -379,7 +380,7 @@ int yaffs_checkpt_close(struct yaffs_dev *dev)
        }
 
        dev->n_free_chunks -=
-           dev->blocks_in_checkpt * dev->param.chunks_per_block;
+               dev->blocks_in_checkpt * dev->param.chunks_per_block;
        dev->n_erased_blocks -= dev->blocks_in_checkpt;
 
        yaffs_trace(YAFFS_TRACE_CHECKPOINT, "checkpoint byte count %d",
index 4f29b80da1ff06df93c537a661303b2e0b153de1..bc2a14919c78c4b021fda741876dcbf2856a3608 100644 (file)
  *
  */
 
+#include "yportenv.h"
+
+#include "yaffs_ecc.h"
+
 /* Table generated by gen-ecc.c
  * Using a table means we do not have to calculate p1..p4 and p1'..p4'
  * for each byte of data. These are instead provided in a table in bits7..2.
  * and therefore this bytes influence on the line parity.
  */
 
-#include "yportenv.h"
-
-#include "yaffs_ecc.h"
-
 static const unsigned char column_parity_table[] = {
        0x00, 0x55, 0x59, 0x0c, 0x65, 0x30, 0x3c, 0x69,
        0x69, 0x3c, 0x30, 0x65, 0x0c, 0x59, 0x55, 0x00,
index c31ca30235758657a2ef746c7766aacb68aaf7ca..4ed4abd3780441a71a1ad8b13f7ae38df3a453b7 100644 (file)
@@ -44,8 +44,8 @@ static int yaffs_wr_data_obj(struct yaffs_obj *in, int inode_chunk,
 
 /* Function to calculate chunk and offset */
 
-static void yaffs_addr_to_chunk(struct yaffs_dev *dev, loff_t addr,
-                               int *chunk_out, u32 *offset_out)
+static inline void yaffs_addr_to_chunk(struct yaffs_dev *dev, loff_t addr,
+                                       int *chunk_out, u32 *offset_out)
 {
        int chunk;
        u32 offset;
@@ -76,7 +76,7 @@ static void yaffs_addr_to_chunk(struct yaffs_dev *dev, loff_t addr,
  * be hellishly efficient.
  */
 
-static u32 calc_shifts_ceiling(u32 x)
+static inline u32 calc_shifts_ceiling(u32 x)
 {
        int extra_bits;
        int shifts;
@@ -99,7 +99,7 @@ static u32 calc_shifts_ceiling(u32 x)
 /* Function to return the number of shifts to get a 1 in bit 0
  */
 
-static u32 calc_shifts(u32 x)
+static inline u32 calc_shifts(u32 x)
 {
        u32 shifts;
 
@@ -387,7 +387,7 @@ int yaffs_check_alloc_available(struct yaffs_dev *dev, int n_chunks)
        checkpt_blocks = yaffs_calc_checkpt_blocks_required(dev);
 
        reserved_chunks =
-           ((reserved_blocks + checkpt_blocks) * dev->param.chunks_per_block);
+           (reserved_blocks + checkpt_blocks) * dev->param.chunks_per_block;
 
        return (dev->n_free_chunks > (reserved_chunks + n_chunks));
 }
@@ -509,9 +509,10 @@ static int yaffs_get_erased_chunks(struct yaffs_dev *dev)
  */
 void yaffs_skip_rest_of_block(struct yaffs_dev *dev)
 {
+       struct yaffs_block_info *bi;
+
        if (dev->alloc_block > 0) {
-               struct yaffs_block_info *bi =
-                   yaffs_get_block_info(dev, dev->alloc_block);
+               bi = yaffs_get_block_info(dev, dev->alloc_block);
                if (bi->block_state == YAFFS_BLOCK_STATE_ALLOCATING) {
                        bi->block_state = YAFFS_BLOCK_STATE_FULL;
                        dev->alloc_block = -1;
@@ -671,16 +672,16 @@ static u16 yaffs_calc_name_sum(const YCHAR *name)
 {
        u16 sum = 0;
        u16 i = 1;
-       const YUCHAR *bname = (const YUCHAR *)name;
 
-       if (bname) {
-               while ((*bname) && (i < (YAFFS_MAX_NAME_LENGTH / 2))) {
+       if (!name)
+               return 0;
 
-                       /* 0x1f mask is case insensitive */
-                       sum += ((*bname) & 0x1f) * i;
-                       i++;
-                       bname++;
-               }
+       while ((*name) && i < (YAFFS_MAX_NAME_LENGTH / 2)) {
+
+               /* 0x1f mask is case insensitive */
+               sum += ((*name) & 0x1f) * i;
+               i++;
+               name++;
        }
        return sum;
 }
@@ -772,7 +773,7 @@ void yaffs_load_tnode_0(struct yaffs_dev *dev, struct yaffs_tnode *tn,
 
        if (dev->tnode_width > (32 - bit_in_word)) {
                bit_in_word = (32 - bit_in_word);
-               word_in_map++;;
+               word_in_map++;
                mask =
                    dev->tnode_mask >> bit_in_word;
                map[word_in_map] &= ~mask;
@@ -799,7 +800,7 @@ u32 yaffs_get_group_base(struct yaffs_dev *dev, struct yaffs_tnode *tn,
 
        if (dev->tnode_width > (32 - bit_in_word)) {
                bit_in_word = (32 - bit_in_word);
-               word_in_map++;;
+               word_in_map++;
                val |= (map[word_in_map] << bit_in_word);
        }
 
@@ -884,8 +885,8 @@ struct yaffs_tnode *yaffs_add_find_tnode_0(struct yaffs_dev *dev,
        u32 x;
 
        /* Check sane level and page Id */
-       if (file_struct->top_level < 0
-           || file_struct->top_level > YAFFS_TNODES_MAX_LEVEL)
+       if (file_struct->top_level < 0 ||
+           file_struct->top_level > YAFFS_TNODES_MAX_LEVEL)
                return NULL;
 
        if (chunk_id > YAFFS_MAX_CHUNK_ID)
@@ -971,7 +972,8 @@ static int yaffs_tags_match(const struct yaffs_ext_tags *tags, int obj_id,
                            int chunk_obj)
 {
        return (tags->chunk_id == chunk_obj &&
-               tags->obj_id == obj_id && !tags->is_deleted) ? 1 : 0;
+               tags->obj_id == obj_id &&
+               !tags->is_deleted) ? 1 : 0;
 
 }
 
@@ -1020,13 +1022,13 @@ static int yaffs_find_chunk_in_file(struct yaffs_obj *in, int inode_chunk,
 
        tn = yaffs_find_tnode_0(dev, &in->variant.file_variant, inode_chunk);
 
-       if (tn) {
-               the_chunk = yaffs_get_group_base(dev, tn, inode_chunk);
+       if (!tn)
+               return ret_val;
 
-               ret_val =
-                   yaffs_find_chunk_in_group(dev, the_chunk, tags, in->obj_id,
+       the_chunk = yaffs_get_group_base(dev, tn, inode_chunk);
+
+       ret_val = yaffs_find_chunk_in_group(dev, the_chunk, tags, in->obj_id,
                                              inode_chunk);
-       }
        return ret_val;
 }
 
@@ -1047,18 +1049,17 @@ static int yaffs_find_del_file_chunk(struct yaffs_obj *in, int inode_chunk,
 
        tn = yaffs_find_tnode_0(dev, &in->variant.file_variant, inode_chunk);
 
-       if (tn) {
+       if (!tn)
+               return ret_val;
 
-               the_chunk = yaffs_get_group_base(dev, tn, inode_chunk);
+       the_chunk = yaffs_get_group_base(dev, tn, inode_chunk);
 
-               ret_val =
-                   yaffs_find_chunk_in_group(dev, the_chunk, tags, in->obj_id,
+       ret_val = yaffs_find_chunk_in_group(dev, the_chunk, tags, in->obj_id,
                                              inode_chunk);
 
-               /* Delete the entry in the filestructure (if found) */
-               if (ret_val != -1)
-                       yaffs_load_tnode_0(dev, tn, inode_chunk, 0);
-       }
+       /* Delete the entry in the filestructure (if found) */
+       if (ret_val != -1)
+               yaffs_load_tnode_0(dev, tn, inode_chunk, 0);
 
        return ret_val;
 }
@@ -1228,38 +1229,39 @@ static int yaffs_soft_del_worker(struct yaffs_obj *in, struct yaffs_tnode *tn,
        int all_done = 1;
        struct yaffs_dev *dev = in->my_dev;
 
-       if (tn) {
-               if (level > 0) {
-                       for (i = YAFFS_NTNODES_INTERNAL - 1;
-                               all_done && i >= 0;
-                               i--) {
-                               if (tn->internal[i]) {
-                                       all_done =
-                                           yaffs_soft_del_worker(in,
-                                               tn->internal[i],
-                                               level - 1,
-                                               (chunk_offset <<
-                                               YAFFS_TNODES_INTERNAL_BITS)
-                                               + i);
-                                       if (all_done) {
-                                               yaffs_free_tnode(dev,
-                                                       tn->internal[i]);
-                                               tn->internal[i] = NULL;
-                                       } else {
-                                               /* Can this happen? */
-                                       }
-                               }
-                       }
-                       return (all_done) ? 1 : 0;
-               } else if (level == 0) {
-                       for (i = YAFFS_NTNODES_LEVEL0 - 1; i >= 0; i--) {
-                               the_chunk = yaffs_get_group_base(dev, tn, i);
-                               if (the_chunk) {
-                                       yaffs_soft_del_chunk(dev, the_chunk);
-                                       yaffs_load_tnode_0(dev, tn, i, 0);
+       if (!tn)
+               return 1;
+
+       if (level > 0) {
+               for (i = YAFFS_NTNODES_INTERNAL - 1;
+                       all_done && i >= 0;
+                       i--) {
+                       if (tn->internal[i]) {
+                               all_done =
+                                   yaffs_soft_del_worker(in,
+                                       tn->internal[i],
+                                       level - 1,
+                                       (chunk_offset <<
+                                       YAFFS_TNODES_INTERNAL_BITS)
+                                       + i);
+                               if (all_done) {
+                                       yaffs_free_tnode(dev,
+                                               tn->internal[i]);
+                                       tn->internal[i] = NULL;
+                               } else {
+                                       /* Can this happen? */
                                }
                        }
-                       return 1;
+               }
+               return (all_done) ? 1 : 0;
+       }
+
+       /* level 0 */
+        for (i = YAFFS_NTNODES_LEVEL0 - 1; i >= 0; i--) {
+               the_chunk = yaffs_get_group_base(dev, tn, i);
+               if (the_chunk) {
+                       yaffs_soft_del_chunk(dev, the_chunk);
+                       yaffs_load_tnode_0(dev, tn, i, 0);
                }
        }
        return 1;
@@ -1358,25 +1360,22 @@ static int yaffs_change_obj_name(struct yaffs_obj *obj,
         *   else only proceed if the new name does not exist and we're putting
         *   it into a directory.
         */
-       if ((unlink_op ||
-            del_op ||
-            force ||
-            (shadows > 0) ||
-            !existing_target) &&
-           new_dir->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) {
-               yaffs_set_obj_name(obj, new_name);
-               obj->dirty = 1;
+       if (!(unlink_op || del_op || force ||
+             shadows > 0 || !existing_target) ||
+             new_dir->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
+               return YAFFS_FAIL;
 
-               yaffs_add_obj_to_dir(new_dir, obj);
+       yaffs_set_obj_name(obj, new_name);
+       obj->dirty = 1;
+       yaffs_add_obj_to_dir(new_dir, obj);
 
-               if (unlink_op)
-                       obj->unlinked = 1;
+       if (unlink_op)
+               obj->unlinked = 1;
+
+       /* If it is a deletion then we mark it as a shrink for gc  */
+       if (yaffs_update_oh(obj, new_name, 0, del_op, shadows, NULL) >= 0)
+               return YAFFS_OK;
 
-               /* If it is a deletion then we mark it as a shrink for gc  */
-               if (yaffs_update_oh(obj, new_name, 0, del_op, shadows, NULL) >=
-                   0)
-                       return YAFFS_OK;
-       }
        return YAFFS_FAIL;
 }
 
@@ -1418,40 +1417,39 @@ static void yaffs_flush_file_cache(struct yaffs_obj *obj)
        int chunk_written = 0;
        int n_caches = obj->my_dev->param.n_caches;
 
-       if (n_caches > 0) {
-               do {
-                       cache = NULL;
-
-                       /* Find the lowest dirty chunk for this object */
-                       for (i = 0; i < n_caches; i++) {
-                               if (dev->cache[i].object == obj &&
-                                   dev->cache[i].dirty) {
-                                       if (!cache
-                                           || dev->cache[i].chunk_id <
-                                           lowest) {
-                                               cache = &dev->cache[i];
-                                               lowest = cache->chunk_id;
-                                       }
+       if (n_caches < 1)
+               return;
+       do {
+               cache = NULL;
+
+               /* Find the lowest dirty chunk for this object */
+               for (i = 0; i < n_caches; i++) {
+                       if (dev->cache[i].object == obj &&
+                           dev->cache[i].dirty) {
+                               if (!cache ||
+                                   dev->cache[i].chunk_id < lowest) {
+                                       cache = &dev->cache[i];
+                                       lowest = cache->chunk_id;
                                }
                        }
+               }
 
-                       if (cache && !cache->locked) {
-                               /* Write it out and free it up */
-                               chunk_written =
-                                   yaffs_wr_data_obj(cache->object,
-                                                     cache->chunk_id,
-                                                     cache->data,
-                                                     cache->n_bytes, 1);
-                               cache->dirty = 0;
-                               cache->object = NULL;
-                       }
-               } while (cache && chunk_written > 0);
+               if (cache && !cache->locked) {
+                       /* Write it out and free it up */
+                       chunk_written =
+                           yaffs_wr_data_obj(cache->object,
+                                             cache->chunk_id,
+                                             cache->data,
+                                             cache->n_bytes, 1);
+                       cache->dirty = 0;
+                       cache->object = NULL;
+               }
+       } while (cache && chunk_written > 0);
 
-               if (cache)
-                       /* Hoosterman, disk full while writing cache out. */
-                       yaffs_trace(YAFFS_TRACE_ERROR,
-                               "yaffs tragedy: no space during cache write");
-       }
+       if (cache)
+               /* Hoosterman, disk full while writing cache out. */
+               yaffs_trace(YAFFS_TRACE_ERROR,
+                       "yaffs tragedy: no space during cache write");
 }
 
 /*yaffs_flush_whole_cache(dev)
@@ -1506,48 +1504,46 @@ static struct yaffs_cache *yaffs_grab_chunk_cache(struct yaffs_dev *dev)
        int i;
        int pushout;
 
-       if (dev->param.n_caches > 0) {
-               /* Try find a non-dirty one... */
+       if (dev->param.n_caches < 1)
+               return NULL;
 
-               cache = yaffs_grab_chunk_worker(dev);
+       /* Try find a non-dirty one... */
 
-               if (!cache) {
-                       /* They were all dirty, find the LRU object and flush
-                        * its cache, then  find again.
-                        * NB what's here is not very accurate,
-                        * we actually flush the object with the LRU chunk.
-                        */
+       cache = yaffs_grab_chunk_worker(dev);
 
-                       /* With locking we can't assume we can use entry zero,
-                        * Set the_obj to a valid pointer for Coverity. */
+       if (!cache) {
+               /* They were all dirty, find the LRU object and flush
+                * its cache, then  find again.
+                * NB what's here is not very accurate,
+                * we actually flush the object with the LRU chunk.
+                */
 
-                       the_obj = dev->cache[0].object;
-                       usage = -1;
-                       cache = NULL;
-                       pushout = -1;
+               /* With locking we can't assume we can use entry zero,
+                * Set the_obj to a valid pointer for Coverity. */
+               the_obj = dev->cache[0].object;
+               usage = -1;
+               cache = NULL;
+               pushout = -1;
 
-                       for (i = 0; i < dev->param.n_caches; i++) {
-                               if (dev->cache[i].object &&
-                                   !dev->cache[i].locked &&
-                                   (dev->cache[i].last_use < usage
-                                    || !cache)) {
-                                       usage = dev->cache[i].last_use;
-                                       the_obj = dev->cache[i].object;
-                                       cache = &dev->cache[i];
-                                       pushout = i;
-                               }
+               for (i = 0; i < dev->param.n_caches; i++) {
+                       if (dev->cache[i].object &&
+                           !dev->cache[i].locked &&
+                           (dev->cache[i].last_use < usage ||
+                           !cache)) {
+                               usage = dev->cache[i].last_use;
+                               the_obj = dev->cache[i].object;
+                               cache = &dev->cache[i];
+                               pushout = i;
                        }
+               }
 
-                       if (!cache || cache->dirty) {
-                               /* Flush and try again */
-                               yaffs_flush_file_cache(the_obj);
-                               cache = yaffs_grab_chunk_worker(dev);
-                       }
+               if (!cache || cache->dirty) {
+                       /* Flush and try again */
+                       yaffs_flush_file_cache(the_obj);
+                       cache = yaffs_grab_chunk_worker(dev);
                }
-               return cache;
-       } else {
-               return NULL;
        }
+       return cache;
 }
 
 /* Find a cached chunk */
@@ -1557,14 +1553,15 @@ static struct yaffs_cache *yaffs_find_chunk_cache(const struct yaffs_obj *obj,
        struct yaffs_dev *dev = obj->my_dev;
        int i;
 
-       if (dev->param.n_caches > 0) {
-               for (i = 0; i < dev->param.n_caches; i++) {
-                       if (dev->cache[i].object == obj &&
-                           dev->cache[i].chunk_id == chunk_id) {
-                               dev->cache_hits++;
+       if (dev->param.n_caches < 1)
+               return NULL;
 
-                               return &dev->cache[i];
-                       }
+       for (i = 0; i < dev->param.n_caches; i++) {
+               if (dev->cache[i].object == obj &&
+                   dev->cache[i].chunk_id == chunk_id) {
+                       dev->cache_hits++;
+
+                       return &dev->cache[i];
                }
        }
        return NULL;
@@ -1574,22 +1571,24 @@ static struct yaffs_cache *yaffs_find_chunk_cache(const struct yaffs_obj *obj,
 static void yaffs_use_cache(struct yaffs_dev *dev, struct yaffs_cache *cache,
                            int is_write)
 {
-       if (dev->param.n_caches > 0) {
-               if (dev->cache_last_use < 0 ||
-                       dev->cache_last_use > 100000000) {
-                       /* Reset the cache usages */
-                       int i;
-                       for (i = 1; i < dev->param.n_caches; i++)
-                               dev->cache[i].last_use = 0;
-
-                       dev->cache_last_use = 0;
-               }
-               dev->cache_last_use++;
-               cache->last_use = dev->cache_last_use;
+       int i;
 
-               if (is_write)
-                       cache->dirty = 1;
+       if (dev->param.n_caches < 1)
+               return;
+
+       if (dev->cache_last_use < 0 ||
+               dev->cache_last_use > 100000000) {
+               /* Reset the cache usages */
+               for (i = 1; i < dev->param.n_caches; i++)
+                       dev->cache[i].last_use = 0;
+
+               dev->cache_last_use = 0;
        }
+       dev->cache_last_use++;
+       cache->last_use = dev->cache_last_use;
+
+       if (is_write)
+               cache->dirty = 1;
 }
 
 /* Invalidate a single cache page.
@@ -1598,9 +1597,10 @@ static void yaffs_use_cache(struct yaffs_dev *dev, struct yaffs_cache *cache,
  */
 static void yaffs_invalidate_chunk_cache(struct yaffs_obj *object, int chunk_id)
 {
+       struct yaffs_cache *cache;
+
        if (object->my_dev->param.n_caches > 0) {
-               struct yaffs_cache *cache =
-                   yaffs_find_chunk_cache(object, chunk_id);
+               cache = yaffs_find_chunk_cache(object, chunk_id);
 
                if (cache)
                        cache->object = NULL;
@@ -1697,25 +1697,26 @@ static int yaffs_generic_obj_del(struct yaffs_obj *in)
 
 static void yaffs_soft_del_file(struct yaffs_obj *obj)
 {
-       if (obj->deleted &&
-           obj->variant_type == YAFFS_OBJECT_TYPE_FILE && !obj->soft_del) {
-               if (obj->n_data_chunks <= 0) {
-                       /* Empty file with no duplicate object headers,
-                        * just delete it immediately */
-                       yaffs_free_tnode(obj->my_dev,
-                                        obj->variant.file_variant.top);
-                       obj->variant.file_variant.top = NULL;
-                       yaffs_trace(YAFFS_TRACE_TRACING,
-                               "yaffs: Deleting empty file %d",
-                               obj->obj_id);
-                       yaffs_generic_obj_del(obj);
-               } else {
-                       yaffs_soft_del_worker(obj,
-                                             obj->variant.file_variant.top,
-                                             obj->variant.
-                                             file_variant.top_level, 0);
-                       obj->soft_del = 1;
-               }
+       if (!obj->deleted ||
+           obj->variant_type != YAFFS_OBJECT_TYPE_FILE ||
+           obj->soft_del)
+               return;
+
+       if (obj->n_data_chunks <= 0) {
+               /* Empty file with no duplicate object headers,
+                * just delete it immediately */
+               yaffs_free_tnode(obj->my_dev, obj->variant.file_variant.top);
+               obj->variant.file_variant.top = NULL;
+               yaffs_trace(YAFFS_TRACE_TRACING,
+                       "yaffs: Deleting empty file %d",
+                       obj->obj_id);
+               yaffs_generic_obj_del(obj);
+       } else {
+               yaffs_soft_del_worker(obj,
+                                     obj->variant.file_variant.top,
+                                     obj->variant.
+                                     file_variant.top_level, 0);
+               obj->soft_del = 1;
        }
 }
 
@@ -1741,39 +1742,39 @@ static struct yaffs_tnode *yaffs_prune_worker(struct yaffs_dev *dev,
        int i;
        int has_data;
 
-       if (tn) {
-               has_data = 0;
+       if (!tn)
+               return tn;
 
-               if (level > 0) {
-                       for (i = 0; i < YAFFS_NTNODES_INTERNAL; i++) {
-                               if (tn->internal[i]) {
-                                       tn->internal[i] =
-                                           yaffs_prune_worker(dev,
-                                                       tn->internal[i],
-                                                       level - 1,
-                                                       (i == 0) ? del0 : 1);
-                               }
+       has_data = 0;
 
-                               if (tn->internal[i])
-                                       has_data++;
+       if (level > 0) {
+               for (i = 0; i < YAFFS_NTNODES_INTERNAL; i++) {
+                       if (tn->internal[i]) {
+                               tn->internal[i] =
+                                   yaffs_prune_worker(dev,
+                                               tn->internal[i],
+                                               level - 1,
+                                               (i == 0) ? del0 : 1);
                        }
-               } else {
-                       int tnode_size_u32 = dev->tnode_size / sizeof(u32);
-                       u32 *map = (u32 *) tn;
 
-                       for (i = 0; !has_data && i < tnode_size_u32; i++) {
-                               if (map[i])
-                                       has_data++;
-                       }
+                       if (tn->internal[i])
+                               has_data++;
                }
+       } else {
+               int tnode_size_u32 = dev->tnode_size / sizeof(u32);
+               u32 *map = (u32 *) tn;
 
-               if (has_data == 0 && del0) {
-                       /* Free and return NULL */
-
-                       yaffs_free_tnode(dev, tn);
-                       tn = NULL;
+               for (i = 0; !has_data && i < tnode_size_u32; i++) {
+                       if (map[i])
+                               has_data++;
                }
        }
+
+       if (has_data == 0 && del0) {
+               /* Free and return NULL */
+               yaffs_free_tnode(dev, tn);
+               tn = NULL;
+       }
        return tn;
 }
 
@@ -1785,36 +1786,37 @@ static int yaffs_prune_tree(struct yaffs_dev *dev,
        int done = 0;
        struct yaffs_tnode *tn;
 
-       if (file_struct->top_level > 0) {
-               file_struct->top =
-                   yaffs_prune_worker(dev, file_struct->top,
-                                      file_struct->top_level, 0);
+       if (file_struct->top_level < 1)
+               return YAFFS_OK;
 
-               /* Now we have a tree with all the non-zero branches NULL but
-                * the height is the same as it was.
-                * Let's see if we can trim internal tnodes to shorten the tree.
-                * We can do this if only the 0th element in the tnode is in use
-                * (ie all the non-zero are NULL)
-                */
+       file_struct->top =
+          yaffs_prune_worker(dev, file_struct->top, file_struct->top_level, 0);
 
-               while (file_struct->top_level && !done) {
-                       tn = file_struct->top;
+       /* Now we have a tree with all the non-zero branches NULL but
+        * the height is the same as it was.
+        * Let's see if we can trim internal tnodes to shorten the tree.
+        * We can do this if only the 0th element in the tnode is in use
+        * (ie all the non-zero are NULL)
+        */
 
-                       has_data = 0;
-                       for (i = 1; i < YAFFS_NTNODES_INTERNAL; i++) {
-                               if (tn->internal[i])
-                                       has_data++;
-                       }
+       while (file_struct->top_level && !done) {
+               tn = file_struct->top;
 
-                       if (!has_data) {
-                               file_struct->top = tn->internal[0];
-                               file_struct->top_level--;
-                               yaffs_free_tnode(dev, tn);
-                       } else {
-                               done = 1;
-                       }
+               has_data = 0;
+               for (i = 1; i < YAFFS_NTNODES_INTERNAL; i++) {
+                       if (tn->internal[i])
+                               has_data++;
+               }
+
+               if (!has_data) {
+                       file_struct->top = tn->internal[0];
+                       file_struct->top_level--;
+                       yaffs_free_tnode(dev, tn);
+               } else {
+                       done = 1;
                }
        }
+
        return YAFFS_OK;
 }
 
@@ -1825,38 +1827,39 @@ static struct yaffs_obj *yaffs_alloc_empty_obj(struct yaffs_dev *dev)
 {
        struct yaffs_obj *obj = yaffs_alloc_raw_obj(dev);
 
-       if (obj) {
-               dev->n_obj++;
+       if (!obj)
+               return obj;
 
-               /* Now sweeten it up... */
+       dev->n_obj++;
 
-               memset(obj, 0, sizeof(struct yaffs_obj));
-               obj->being_created = 1;
+       /* Now sweeten it up... */
 
-               obj->my_dev = dev;
-               obj->hdr_chunk = 0;
-               obj->variant_type = YAFFS_OBJECT_TYPE_UNKNOWN;
-               INIT_LIST_HEAD(&(obj->hard_links));
-               INIT_LIST_HEAD(&(obj->hash_link));
-               INIT_LIST_HEAD(&obj->siblings);
+       memset(obj, 0, sizeof(struct yaffs_obj));
+       obj->being_created = 1;
 
-               /* Now make the directory sane */
-               if (dev->root_dir) {
-                       obj->parent = dev->root_dir;
-                       list_add(&(obj->siblings),
-                                &dev->root_dir->variant.dir_variant.children);
-               }
+       obj->my_dev = dev;
+       obj->hdr_chunk = 0;
+       obj->variant_type = YAFFS_OBJECT_TYPE_UNKNOWN;
+       INIT_LIST_HEAD(&(obj->hard_links));
+       INIT_LIST_HEAD(&(obj->hash_link));
+       INIT_LIST_HEAD(&obj->siblings);
 
-               /* Add it to the lost and found directory.
-                * NB Can't put root or lost-n-found in lost-n-found so
-                * check if lost-n-found exists first
-                */
-               if (dev->lost_n_found)
-                       yaffs_add_obj_to_dir(dev->lost_n_found, obj);
-
-               obj->being_created = 0;
+       /* Now make the directory sane */
+       if (dev->root_dir) {
+               obj->parent = dev->root_dir;
+               list_add(&(obj->siblings),
+                        &dev->root_dir->variant.dir_variant.children);
        }
 
+       /* Add it to the lost and found directory.
+        * NB Can't put root or lost-n-found in lost-n-found so
+        * check if lost-n-found exists first
+        */
+       if (dev->lost_n_found)
+               yaffs_add_obj_to_dir(dev->lost_n_found, obj);
+
+       obj->being_created = 0;
+
        dev->checkpoint_blocks_required = 0;    /* force recalculation */
 
        return obj;
@@ -1962,39 +1965,35 @@ struct yaffs_obj *yaffs_new_obj(struct yaffs_dev *dev, int number,
                return NULL;
        }
 
-       if (the_obj) {
-               the_obj->fake = 0;
-               the_obj->rename_allowed = 1;
-               the_obj->unlink_allowed = 1;
-               the_obj->obj_id = number;
-               yaffs_hash_obj(the_obj);
-               the_obj->variant_type = type;
-               yaffs_load_current_time(the_obj, 1, 1);
+       the_obj->fake = 0;
+       the_obj->rename_allowed = 1;
+       the_obj->unlink_allowed = 1;
+       the_obj->obj_id = number;
+       yaffs_hash_obj(the_obj);
+       the_obj->variant_type = type;
+       yaffs_load_current_time(the_obj, 1, 1);
 
-               switch (type) {
-               case YAFFS_OBJECT_TYPE_FILE:
-                       the_obj->variant.file_variant.file_size = 0;
-                       the_obj->variant.file_variant.scanned_size = 0;
-                       the_obj->variant.file_variant.shrink_size = ~0;
-                                                               /* max */
-                       the_obj->variant.file_variant.top_level = 0;
-                       the_obj->variant.file_variant.top = tn;
-                       break;
-               case YAFFS_OBJECT_TYPE_DIRECTORY:
-                       INIT_LIST_HEAD(&the_obj->variant.dir_variant.children);
-                       INIT_LIST_HEAD(&the_obj->variant.dir_variant.dirty);
-                       break;
-               case YAFFS_OBJECT_TYPE_SYMLINK:
-               case YAFFS_OBJECT_TYPE_HARDLINK:
-               case YAFFS_OBJECT_TYPE_SPECIAL:
-                       /* No action required */
-                       break;
-               case YAFFS_OBJECT_TYPE_UNKNOWN:
-                       /* todo this should not happen */
-                       break;
-               }
+       switch (type) {
+       case YAFFS_OBJECT_TYPE_FILE:
+               the_obj->variant.file_variant.file_size = 0;
+               the_obj->variant.file_variant.scanned_size = 0;
+               the_obj->variant.file_variant.shrink_size = ~0; /* max */
+               the_obj->variant.file_variant.top_level = 0;
+               the_obj->variant.file_variant.top = tn;
+               break;
+       case YAFFS_OBJECT_TYPE_DIRECTORY:
+               INIT_LIST_HEAD(&the_obj->variant.dir_variant.children);
+               INIT_LIST_HEAD(&the_obj->variant.dir_variant.dirty);
+               break;
+       case YAFFS_OBJECT_TYPE_SYMLINK:
+       case YAFFS_OBJECT_TYPE_HARDLINK:
+       case YAFFS_OBJECT_TYPE_SPECIAL:
+               /* No action required */
+               break;
+       case YAFFS_OBJECT_TYPE_UNKNOWN:
+               /* todo this should not happen */
+               break;
        }
-
        return the_obj;
 }
 
@@ -2005,16 +2004,17 @@ static struct yaffs_obj *yaffs_create_fake_dir(struct yaffs_dev *dev,
        struct yaffs_obj *obj =
            yaffs_new_obj(dev, number, YAFFS_OBJECT_TYPE_DIRECTORY);
 
-       if (obj) {
-               obj->fake = 1;  /* it is fake so it might not use NAND */
-               obj->rename_allowed = 0;
-               obj->unlink_allowed = 0;
-               obj->deleted = 0;
-               obj->unlinked = 0;
-               obj->yst_mode = mode;
-               obj->my_dev = dev;
-               obj->hdr_chunk = 0;     /* Not a valid chunk. */
-       }
+       if (!obj)
+               return NULL;
+
+       obj->fake = 1;  /* it is fake so it might not use NAND */
+       obj->rename_allowed = 0;
+       obj->unlink_allowed = 0;
+       obj->deleted = 0;
+       obj->unlinked = 0;
+       obj->yst_mode = mode;
+       obj->my_dev = dev;
+       obj->hdr_chunk = 0;     /* Not a valid chunk. */
        return obj;
 
 }
@@ -2170,50 +2170,48 @@ static struct yaffs_obj *yaffs_create_obj(enum yaffs_obj_type type,
                return NULL;
        }
 
-       if (in) {
-               in->hdr_chunk = 0;
-               in->valid = 1;
-               in->variant_type = type;
+       in->hdr_chunk = 0;
+       in->valid = 1;
+       in->variant_type = type;
 
-               in->yst_mode = mode;
+       in->yst_mode = mode;
 
-               yaffs_attribs_init(in, gid, uid, rdev);
+       yaffs_attribs_init(in, gid, uid, rdev);
 
-               in->n_data_chunks = 0;
+       in->n_data_chunks = 0;
 
-               yaffs_set_obj_name(in, name);
-               in->dirty = 1;
+       yaffs_set_obj_name(in, name);
+       in->dirty = 1;
 
-               yaffs_add_obj_to_dir(parent, in);
+       yaffs_add_obj_to_dir(parent, in);
 
-               in->my_dev = parent->my_dev;
+       in->my_dev = parent->my_dev;
 
-               switch (type) {
-               case YAFFS_OBJECT_TYPE_SYMLINK:
-                       in->variant.symlink_variant.alias = str;
-                       break;
-               case YAFFS_OBJECT_TYPE_HARDLINK:
-                       in->variant.hardlink_variant.equiv_obj = equiv_obj;
-                       in->variant.hardlink_variant.equiv_id =
-                           equiv_obj->obj_id;
-                       list_add(&in->hard_links, &equiv_obj->hard_links);
-                       break;
-               case YAFFS_OBJECT_TYPE_FILE:
-               case YAFFS_OBJECT_TYPE_DIRECTORY:
-               case YAFFS_OBJECT_TYPE_SPECIAL:
-               case YAFFS_OBJECT_TYPE_UNKNOWN:
-                       /* do nothing */
-                       break;
-               }
+       switch (type) {
+       case YAFFS_OBJECT_TYPE_SYMLINK:
+               in->variant.symlink_variant.alias = str;
+               break;
+       case YAFFS_OBJECT_TYPE_HARDLINK:
+               in->variant.hardlink_variant.equiv_obj = equiv_obj;
+               in->variant.hardlink_variant.equiv_id = equiv_obj->obj_id;
+               list_add(&in->hard_links, &equiv_obj->hard_links);
+               break;
+       case YAFFS_OBJECT_TYPE_FILE:
+       case YAFFS_OBJECT_TYPE_DIRECTORY:
+       case YAFFS_OBJECT_TYPE_SPECIAL:
+       case YAFFS_OBJECT_TYPE_UNKNOWN:
+               /* do nothing */
+               break;
+       }
 
-               if (yaffs_update_oh(in, name, 0, 0, 0, NULL) < 0) {
-                       /* Could not create the object header, fail */
-                       yaffs_del_obj(in);
-                       in = NULL;
-               }
+       if (yaffs_update_oh(in, name, 0, 0, 0, NULL) < 0) {
+               /* Could not create the object header, fail */
+               yaffs_del_obj(in);
+               in = NULL;
+       }
 
+       if (in)
                yaffs_update_parent(parent);
-       }
 
        return in;
 }
@@ -2256,12 +2254,12 @@ struct yaffs_obj *yaffs_link_obj(struct yaffs_obj *parent, const YCHAR * name,
        /* Get the real object in case we were fed a hard link obj */
        equiv_obj = yaffs_get_equivalent_obj(equiv_obj);
 
-       if (yaffs_create_obj
-           (YAFFS_OBJECT_TYPE_HARDLINK, parent, name, 0, 0, 0,
-            equiv_obj, NULL, 0))
+       if (yaffs_create_obj(YAFFS_OBJECT_TYPE_HARDLINK,
+                       parent, name, 0, 0, 0,
+                       equiv_obj, NULL, 0))
                return equiv_obj;
-       else
-               return NULL;
+
+       return NULL;
 
 }
 
@@ -2269,6 +2267,25 @@ struct yaffs_obj *yaffs_link_obj(struct yaffs_obj *parent, const YCHAR * name,
 
 /*---------------------- Block Management and Page Allocation -------------*/
 
+static void yaffs_deinit_blocks(struct yaffs_dev *dev)
+{
+       if (dev->block_info_alt && dev->block_info)
+               vfree(dev->block_info);
+       else
+               kfree(dev->block_info);
+
+       dev->block_info_alt = 0;
+
+       dev->block_info = NULL;
+
+       if (dev->chunk_bits_alt && dev->chunk_bits)
+               vfree(dev->chunk_bits);
+       else
+               kfree(dev->chunk_bits);
+       dev->chunk_bits_alt = 0;
+       dev->chunk_bits = NULL;
+}
+
 static int yaffs_init_blocks(struct yaffs_dev *dev)
 {
        int n_blocks = dev->internal_end_block - dev->internal_start_block + 1;
@@ -2288,53 +2305,39 @@ static int yaffs_init_blocks(struct yaffs_dev *dev)
                dev->block_info_alt = 0;
        }
 
-       if (dev->block_info) {
-               /* Set up dynamic blockinfo stuff. Round up bytes. */
-               dev->chunk_bit_stride = (dev->param.chunks_per_block + 7) / 8;
+       if (!dev->block_info)
+               goto alloc_error;
+
+       /* Set up dynamic blockinfo stuff. Round up bytes. */
+       dev->chunk_bit_stride = (dev->param.chunks_per_block + 7) / 8;
+       dev->chunk_bits =
+               kmalloc(dev->chunk_bit_stride * n_blocks, GFP_NOFS);
+       if (!dev->chunk_bits) {
                dev->chunk_bits =
-                       kmalloc(dev->chunk_bit_stride * n_blocks, GFP_NOFS);
-               if (!dev->chunk_bits) {
-                       dev->chunk_bits =
-                           vmalloc(dev->chunk_bit_stride * n_blocks);
-                       dev->chunk_bits_alt = 1;
-               } else {
-                       dev->chunk_bits_alt = 0;
-               }
+                   vmalloc(dev->chunk_bit_stride * n_blocks);
+               dev->chunk_bits_alt = 1;
+       } else {
+               dev->chunk_bits_alt = 0;
        }
+       if (!dev->chunk_bits)
+               goto alloc_error;
 
-       if (dev->block_info && dev->chunk_bits) {
-               memset(dev->block_info, 0,
-                      n_blocks * sizeof(struct yaffs_block_info));
-               memset(dev->chunk_bits, 0, dev->chunk_bit_stride * n_blocks);
-               return YAFFS_OK;
-       }
 
+       memset(dev->block_info, 0, n_blocks * sizeof(struct yaffs_block_info));
+       memset(dev->chunk_bits, 0, dev->chunk_bit_stride * n_blocks);
+       return YAFFS_OK;
+
+alloc_error:
+       yaffs_deinit_blocks(dev);
        return YAFFS_FAIL;
 }
 
-static void yaffs_deinit_blocks(struct yaffs_dev *dev)
-{
-       if (dev->block_info_alt && dev->block_info)
-               vfree(dev->block_info);
-       else
-               kfree(dev->block_info);
-
-       dev->block_info_alt = 0;
-
-       dev->block_info = NULL;
-
-       if (dev->chunk_bits_alt && dev->chunk_bits)
-               vfree(dev->chunk_bits);
-       else
-               kfree(dev->chunk_bits);
-       dev->chunk_bits_alt = 0;
-       dev->chunk_bits = NULL;
-}
 
 void yaffs_block_became_dirty(struct yaffs_dev *dev, int block_no)
 {
        struct yaffs_block_info *bi = yaffs_get_block_info(dev, block_no);
        int erased_ok = 0;
+       int i;
 
        /* If the block is still healthy erase it and mark as clean.
         * If the block has had a data failure, then retire it.
@@ -2370,13 +2373,13 @@ void yaffs_block_became_dirty(struct yaffs_dev *dev, int block_no)
                }
        }
 
+       /* Verify erasure if needed */
        if (erased_ok &&
-           ((yaffs_trace_mask & YAFFS_TRACE_ERASE)
-            || !yaffs_skip_verification(dev))) {
-               int i;
+           ((yaffs_trace_mask & YAFFS_TRACE_ERASE) ||
+            !yaffs_skip_verification(dev))) {
                for (i = 0; i < dev->param.chunks_per_block; i++) {
-                       if (!yaffs_check_chunk_erased
-                           (dev, block_no * dev->param.chunks_per_block + i)) {
+                       if (!yaffs_check_chunk_erased(dev,
+                               block_no * dev->param.chunks_per_block + i)) {
                                yaffs_trace(YAFFS_TRACE_ERROR,
                                        ">>Block %d erasure supposedly OK, but chunk %d not erased",
                                        block_no, i);
@@ -2384,32 +2387,32 @@ void yaffs_block_became_dirty(struct yaffs_dev *dev, int block_no)
                }
        }
 
-       if (erased_ok) {
-               /* Clean it up... */
-               bi->block_state = YAFFS_BLOCK_STATE_EMPTY;
-               bi->seq_number = 0;
-               dev->n_erased_blocks++;
-               bi->pages_in_use = 0;
-               bi->soft_del_pages = 0;
-               bi->has_shrink_hdr = 0;
-               bi->skip_erased_check = 1;      /* Clean, so no need to check */
-               bi->gc_prioritise = 0;
-               yaffs_clear_chunk_bits(dev, block_no);
-
-               yaffs_trace(YAFFS_TRACE_ERASE,
-                       "Erased block %d", block_no);
-       } else {
+       if (!erased_ok) {
                /* We lost a block of free space */
                dev->n_free_chunks -= dev->param.chunks_per_block;
                yaffs_retire_block(dev, block_no);
                yaffs_trace(YAFFS_TRACE_ERROR | YAFFS_TRACE_BAD_BLOCKS,
                        "**>> Block %d retired", block_no);
+               return;
        }
+
+       /* Clean it up... */
+       bi->block_state = YAFFS_BLOCK_STATE_EMPTY;
+       bi->seq_number = 0;
+       dev->n_erased_blocks++;
+       bi->pages_in_use = 0;
+       bi->soft_del_pages = 0;
+       bi->has_shrink_hdr = 0;
+       bi->skip_erased_check = 1;      /* Clean, so no need to check */
+       bi->gc_prioritise = 0;
+       yaffs_clear_chunk_bits(dev, block_no);
+
+       yaffs_trace(YAFFS_TRACE_ERASE, "Erased block %d", block_no);
 }
 
-static int yaffs_gc_process_chunk(struct yaffs_dev *dev,
-                               struct yaffs_block_info *bi,
-                               int old_chunk, u8 *buffer)
+static inline int yaffs_gc_process_chunk(struct yaffs_dev *dev,
+                                       struct yaffs_block_info *bi,
+                                       int old_chunk, u8 *buffer)
 {
        int new_chunk;
        int mark_flash = 1;
@@ -2830,10 +2833,9 @@ static int yaffs_check_gc(struct yaffs_dev *dev, int background)
        if (dev->param.gc_control && (dev->param.gc_control(dev) & 1) == 0)
                return YAFFS_OK;
 
-       if (dev->gc_disable) {
+       if (dev->gc_disable)
                /* Bail out so we don't get recursive gc */
                return YAFFS_OK;
-       }
 
        /* This loop should pass the first time.
         * Only loops here if the collection does not increase space.
@@ -2897,8 +2899,8 @@ static int yaffs_check_gc(struct yaffs_dev *dev, int background)
                        gc_ok = yaffs_gc_block(dev, dev->gc_block, aggressive);
                }
 
-               if (dev->n_erased_blocks < (dev->param.n_reserved_blocks)
-                   && dev->gc_block > 0) {
+               if (dev->n_erased_blocks < (dev->param.n_reserved_blocks) &&
+                   dev->gc_block > 0) {
                        yaffs_trace(YAFFS_TRACE_GC,
                                "yaffs: GC !!!no reclaim!!! n_erased_blocks %d after try %d block %d",
                                dev->n_erased_blocks, max_tries,
@@ -2988,7 +2990,7 @@ void yaffs_chunk_del(struct yaffs_dev *dev, int chunk_id, int mark_flash,
         */
        if (bi->block_state == YAFFS_BLOCK_STATE_ALLOCATING ||
            bi->block_state == YAFFS_BLOCK_STATE_FULL ||
-           bi->block_state == YAFFS_BLOCK_STATE_NEEDS_SCANNING ||
+           bi->block_state == YAFFS_BLOCK_STATE_NEEDS_SCAN ||
            bi->block_state == YAFFS_BLOCK_STATE_COLLECTING) {
                dev->n_free_chunks++;
                yaffs_clear_chunk_bit(dev, block, page);
@@ -2997,7 +2999,7 @@ void yaffs_chunk_del(struct yaffs_dev *dev, int chunk_id, int mark_flash,
                if (bi->pages_in_use == 0 &&
                    !bi->has_shrink_hdr &&
                    bi->block_state != YAFFS_BLOCK_STATE_ALLOCATING &&
-                   bi->block_state != YAFFS_BLOCK_STATE_NEEDS_SCANNING) {
+                   bi->block_state != YAFFS_BLOCK_STATE_NEEDS_SCAN) {
                        yaffs_block_became_dirty(dev, block);
                }
        }
@@ -3181,40 +3183,34 @@ int yaffs_list_xattrib(struct yaffs_obj *obj, char *buffer, int size)
 
 static void yaffs_check_obj_details_loaded(struct yaffs_obj *in)
 {
-       u8 *chunk_data;
+       u8 *buf;
        struct yaffs_obj_hdr *oh;
        struct yaffs_dev *dev;
        struct yaffs_ext_tags tags;
        int result;
        int alloc_failed = 0;
 
-       if (!in)
+       if (!in || !in->lazy_loaded || in->hdr_chunk < 1)
                return;
 
        dev = in->my_dev;
+       in->lazy_loaded = 0;
+       buf = yaffs_get_temp_buffer(dev, __LINE__);
 
-       if (in->lazy_loaded && in->hdr_chunk > 0) {
-               in->lazy_loaded = 0;
-               chunk_data = yaffs_get_temp_buffer(dev, __LINE__);
-
-               result =
-                   yaffs_rd_chunk_tags_nand(dev, in->hdr_chunk, chunk_data,
-                                            &tags);
-               oh = (struct yaffs_obj_hdr *)chunk_data;
-
-               in->yst_mode = oh->yst_mode;
-               yaffs_load_attribs(in, oh);
-               yaffs_set_obj_name_from_oh(in, oh);
+       result = yaffs_rd_chunk_tags_nand(dev, in->hdr_chunk, buf, &tags);
+       oh = (struct yaffs_obj_hdr *)buf;
 
-               if (in->variant_type == YAFFS_OBJECT_TYPE_SYMLINK) {
-                       in->variant.symlink_variant.alias =
-                           yaffs_clone_str(oh->alias);
-                       if (!in->variant.symlink_variant.alias)
-                               alloc_failed = 1;       /* Not returned */
-               }
+       in->yst_mode = oh->yst_mode;
+       yaffs_load_attribs(in, oh);
+       yaffs_set_obj_name_from_oh(in, oh);
 
-               yaffs_release_temp_buffer(dev, chunk_data, __LINE__);
+       if (in->variant_type == YAFFS_OBJECT_TYPE_SYMLINK) {
+               in->variant.symlink_variant.alias =
+                   yaffs_clone_str(oh->alias);
+               if (!in->variant.symlink_variant.alias)
+                       alloc_failed = 1;       /* Not returned */
        }
+       yaffs_release_temp_buffer(dev, buf, __LINE__);
 }
 
 static void yaffs_load_name_from_oh(struct yaffs_dev *dev, YCHAR *name,
@@ -3277,8 +3273,7 @@ static void yaffs_load_oh_from_name(struct yaffs_dev *dev, YCHAR *oh_name,
                } else {
                        /* Unicode name, so save starting at the second YCHAR */
                        *oh_name = 0;
-                       strncpy(oh_name + 1, name,
-                                       YAFFS_MAX_NAME_LENGTH - 2);
+                       strncpy(oh_name + 1, name, YAFFS_MAX_NAME_LENGTH - 2);
                }
        } else {
 #else
@@ -3310,135 +3305,129 @@ int yaffs_update_oh(struct yaffs_obj *in, const YCHAR *name, int force,
 
        strcpy(old_name, _Y("silly old name"));
 
-       if (!in->fake || in == dev->root_dir ||
-           force || xmod) {
-
-               yaffs_check_gc(dev, 0);
-               yaffs_check_obj_details_loaded(in);
+       if (in->fake && in != dev->root_dir && !force && !xmod)
+               return ret_val;
 
-               buffer = yaffs_get_temp_buffer(in->my_dev, __LINE__);
-               oh = (struct yaffs_obj_hdr *)buffer;
+       yaffs_check_gc(dev, 0);
+       yaffs_check_obj_details_loaded(in);
 
-               prev_chunk_id = in->hdr_chunk;
+       buffer = yaffs_get_temp_buffer(in->my_dev, __LINE__);
+       oh = (struct yaffs_obj_hdr *)buffer;
 
-               if (prev_chunk_id > 0) {
-                       result = yaffs_rd_chunk_tags_nand(dev, prev_chunk_id,
-                                                         buffer, &old_tags);
+       prev_chunk_id = in->hdr_chunk;
 
-                       yaffs_verify_oh(in, oh, &old_tags, 0);
+       if (prev_chunk_id > 0) {
+               result = yaffs_rd_chunk_tags_nand(dev, prev_chunk_id,
+                                                 buffer, &old_tags);
 
-                       memcpy(old_name, oh->name, sizeof(oh->name));
-                       memset(buffer, 0xFF, sizeof(struct yaffs_obj_hdr));
-               } else {
-                       memset(buffer, 0xFF, dev->data_bytes_per_chunk);
-               }
+               yaffs_verify_oh(in, oh, &old_tags, 0);
+               memcpy(old_name, oh->name, sizeof(oh->name));
+               memset(buffer, 0xFF, sizeof(struct yaffs_obj_hdr));
+       } else {
+               memset(buffer, 0xFF, dev->data_bytes_per_chunk);
+       }
 
-               oh->type = in->variant_type;
-               oh->yst_mode = in->yst_mode;
-               oh->shadows_obj = oh->inband_shadowed_obj_id = shadows;
+       oh->type = in->variant_type;
+       oh->yst_mode = in->yst_mode;
+       oh->shadows_obj = oh->inband_shadowed_obj_id = shadows;
 
-               yaffs_load_attribs_oh(oh, in);
+       yaffs_load_attribs_oh(oh, in);
 
-               if (in->parent)
-                       oh->parent_obj_id = in->parent->obj_id;
-               else
-                       oh->parent_obj_id = 0;
+       if (in->parent)
+               oh->parent_obj_id = in->parent->obj_id;
+       else
+               oh->parent_obj_id = 0;
 
-               if (name && *name) {
-                       memset(oh->name, 0, sizeof(oh->name));
-                       yaffs_load_oh_from_name(dev, oh->name, name);
-               } else if (prev_chunk_id > 0) {
-                       memcpy(oh->name, old_name, sizeof(oh->name));
-               } else {
-                       memset(oh->name, 0, sizeof(oh->name));
-               }
+       if (name && *name) {
+               memset(oh->name, 0, sizeof(oh->name));
+               yaffs_load_oh_from_name(dev, oh->name, name);
+       } else if (prev_chunk_id > 0) {
+               memcpy(oh->name, old_name, sizeof(oh->name));
+       } else {
+               memset(oh->name, 0, sizeof(oh->name));
+       }
 
-               oh->is_shrink = is_shrink;
+       oh->is_shrink = is_shrink;
 
-               switch (in->variant_type) {
-               case YAFFS_OBJECT_TYPE_UNKNOWN:
-                       /* Should not happen */
-                       break;
-               case YAFFS_OBJECT_TYPE_FILE:
-                       oh->file_size =
-                           (oh->parent_obj_id == YAFFS_OBJECTID_DELETED
-                            || oh->parent_obj_id ==
-                            YAFFS_OBJECTID_UNLINKED) ? 0 : in->
-                           variant.file_variant.file_size;
-                       break;
-               case YAFFS_OBJECT_TYPE_HARDLINK:
-                       oh->equiv_id = in->variant.hardlink_variant.equiv_id;
-                       break;
-               case YAFFS_OBJECT_TYPE_SPECIAL:
-                       /* Do nothing */
-                       break;
-               case YAFFS_OBJECT_TYPE_DIRECTORY:
-                       /* Do nothing */
-                       break;
-               case YAFFS_OBJECT_TYPE_SYMLINK:
-                       alias = in->variant.symlink_variant.alias;
-                       if (!alias)
-                               alias = _Y("no alias");
-                       strncpy(oh->alias, alias, YAFFS_MAX_ALIAS_LENGTH);
-                       oh->alias[YAFFS_MAX_ALIAS_LENGTH] = 0;
-                       break;
-               }
+       switch (in->variant_type) {
+       case YAFFS_OBJECT_TYPE_UNKNOWN:
+               /* Should not happen */
+               break;
+       case YAFFS_OBJECT_TYPE_FILE:
+               oh->file_size =
+                   (oh->parent_obj_id == YAFFS_OBJECTID_DELETED ||
+                    oh->parent_obj_id == YAFFS_OBJECTID_UNLINKED) ?
+                    0 : in->variant.file_variant.file_size;
+               break;
+       case YAFFS_OBJECT_TYPE_HARDLINK:
+               oh->equiv_id = in->variant.hardlink_variant.equiv_id;
+               break;
+       case YAFFS_OBJECT_TYPE_SPECIAL:
+               /* Do nothing */
+               break;
+       case YAFFS_OBJECT_TYPE_DIRECTORY:
+               /* Do nothing */
+               break;
+       case YAFFS_OBJECT_TYPE_SYMLINK:
+               alias = in->variant.symlink_variant.alias;
+               if (!alias)
+                       alias = _Y("no alias");
+               strncpy(oh->alias, alias, YAFFS_MAX_ALIAS_LENGTH);
+               oh->alias[YAFFS_MAX_ALIAS_LENGTH] = 0;
+               break;
+       }
 
-               /* process any xattrib modifications */
-               if (xmod)
-                       yaffs_apply_xattrib_mod(in, (char *)buffer, xmod);
-
-               /* Tags */
-               yaffs_init_tags(&new_tags);
-               in->serial++;
-               new_tags.chunk_id = 0;
-               new_tags.obj_id = in->obj_id;
-               new_tags.serial_number = in->serial;
-
-               /* Add extra info for file header */
-               new_tags.extra_available = 1;
-               new_tags.extra_parent_id = oh->parent_obj_id;
-               new_tags.extra_length = oh->file_size;
-               new_tags.extra_is_shrink = oh->is_shrink;
-               new_tags.extra_equiv_id = oh->equiv_id;
-               new_tags.extra_shadows = (oh->shadows_obj > 0) ? 1 : 0;
-               new_tags.extra_obj_type = in->variant_type;
-               yaffs_verify_oh(in, oh, &new_tags, 1);
-
-               /* Create new chunk in NAND */
-               new_chunk_id =
-                   yaffs_write_new_chunk(dev, buffer, &new_tags,
-                                         (prev_chunk_id > 0) ? 1 : 0);
-
-               if (new_chunk_id >= 0) {
-
-                       in->hdr_chunk = new_chunk_id;
-
-                       if (prev_chunk_id > 0) {
-                               yaffs_chunk_del(dev, prev_chunk_id, 1,
-                                               __LINE__);
-                       }
+       /* process any xattrib modifications */
+       if (xmod)
+               yaffs_apply_xattrib_mod(in, (char *)buffer, xmod);
 
-                       if (!yaffs_obj_cache_dirty(in))
-                               in->dirty = 0;
-
-                       /* If this was a shrink, then mark the block
-                        * that the chunk lives on */
-                       if (is_shrink) {
-                               bi = yaffs_get_block_info(in->my_dev,
-                                                         new_chunk_id /
-                                                         in->my_dev->param.
-                                                         chunks_per_block);
-                               bi->has_shrink_hdr = 1;
-                       }
-               }
-               ret_val = new_chunk_id;
-       }
+       /* Tags */
+       yaffs_init_tags(&new_tags);
+       in->serial++;
+       new_tags.chunk_id = 0;
+       new_tags.obj_id = in->obj_id;
+       new_tags.serial_number = in->serial;
+
+       /* Add extra info for file header */
+       new_tags.extra_available = 1;
+       new_tags.extra_parent_id = oh->parent_obj_id;
+       new_tags.extra_length = oh->file_size;
+       new_tags.extra_is_shrink = oh->is_shrink;
+       new_tags.extra_equiv_id = oh->equiv_id;
+       new_tags.extra_shadows = (oh->shadows_obj > 0) ? 1 : 0;
+       new_tags.extra_obj_type = in->variant_type;
+       yaffs_verify_oh(in, oh, &new_tags, 1);
+
+       /* Create new chunk in NAND */
+       new_chunk_id =
+           yaffs_write_new_chunk(dev, buffer, &new_tags,
+                                 (prev_chunk_id > 0) ? 1 : 0);
 
        if (buffer)
                yaffs_release_temp_buffer(dev, buffer, __LINE__);
 
-       return ret_val;
+       if (new_chunk_id < 0)
+               return new_chunk_id;
+
+       in->hdr_chunk = new_chunk_id;
+
+       if (prev_chunk_id > 0)
+               yaffs_chunk_del(dev, prev_chunk_id, 1, __LINE__);
+
+       if (!yaffs_obj_cache_dirty(in))
+               in->dirty = 0;
+
+       /* If this was a shrink, then mark the block
+        * that the chunk lives on */
+       if (is_shrink) {
+               bi = yaffs_get_block_info(in->my_dev,
+                                         new_chunk_id /
+                                         in->my_dev->param.chunks_per_block);
+               bi->has_shrink_hdr = 1;
+       }
+
+
+       return new_chunk_id;
 }
 
 /*--------------------- File read/write ------------------------
@@ -3481,8 +3470,8 @@ int yaffs_file_rd(struct yaffs_obj *in, u8 * buffer, loff_t offset, int n_bytes)
                 * a whole chunk or we're using inband tags then use the cache
                 * (if there is caching) else bypass the cache.
                 */
-               if (cache || n_copy != dev->data_bytes_per_chunk
-                   || dev->param.inband_tags) {
+               if (cache || n_copy != dev->data_bytes_per_chunk ||
+                   dev->param.inband_tags) {
                        if (dev->param.n_caches > 0) {
 
                                /* If we can't find the data in the cache,
@@ -3611,8 +3600,8 @@ int yaffs_do_file_wr(struct yaffs_obj *in, const u8 *buffer, loff_t offset,
                                 * load the cache */
                                cache = yaffs_find_chunk_cache(in, chunk);
 
-                               if (!cache
-                                   && yaffs_check_alloc_available(dev, 1)) {
+                               if (!cache &&
+                                   yaffs_check_alloc_available(dev, 1)) {
                                        cache = yaffs_grab_chunk_cache(dev);
                                        cache->object = in;
                                        cache->chunk_id = chunk;
@@ -3733,20 +3722,21 @@ static void yaffs_prune_chunks(struct yaffs_obj *in, int new_size)
                 */
 
                chunk_id = yaffs_find_del_file_chunk(in, i, NULL);
-               if (chunk_id > 0) {
-                       if (chunk_id <
-                           (dev->internal_start_block *
-                            dev->param.chunks_per_block) ||
-                           chunk_id >=
-                           ((dev->internal_end_block + 1) *
-                             dev->param.chunks_per_block)) {
-                               yaffs_trace(YAFFS_TRACE_ALWAYS,
-                                       "Found daft chunk_id %d for %d",
-                                       chunk_id, i);
-                       } else {
-                               in->n_data_chunks--;
-                               yaffs_chunk_del(dev, chunk_id, 1, __LINE__);
-                       }
+
+               if (chunk_id < 1)
+                       continue;
+
+               if (chunk_id <
+                   (dev->internal_start_block * dev->param.chunks_per_block) ||
+                   chunk_id >=
+                   ((dev->internal_end_block + 1) *
+                     dev->param.chunks_per_block)) {
+                       yaffs_trace(YAFFS_TRACE_ALWAYS,
+                               "Found daft chunk_id %d for %d",
+                               chunk_id, i);
+               } else {
+                       in->n_data_chunks--;
+                       yaffs_chunk_del(dev, chunk_id, 1, __LINE__);
                }
        }
 }
@@ -3821,23 +3811,19 @@ int yaffs_resize_file(struct yaffs_obj *in, loff_t new_size)
 
 int yaffs_flush_file(struct yaffs_obj *in, int update_time, int data_sync)
 {
-       int ret_val;
+       if (!in->dirty)
+               return YAFFS_OK;
 
-       if (in->dirty) {
-               yaffs_flush_file_cache(in);
-               if (data_sync)  /* Only sync data */
-                       ret_val = YAFFS_OK;
-               else {
-                       if (update_time)
-                               yaffs_load_current_time(in, 0, 0);
+       yaffs_flush_file_cache(in);
 
-                       ret_val = (yaffs_update_oh(in, NULL, 0, 0, 0, NULL) >=
-                                  0) ? YAFFS_OK : YAFFS_FAIL;
-               }
-       } else {
-               ret_val = YAFFS_OK;
-       }
-       return ret_val;
+       if (data_sync)
+               return YAFFS_OK;
+
+       if (update_time)
+               yaffs_load_current_time(in, 0, 0);
+
+       return (yaffs_update_oh(in, NULL, 0, 0, 0, NULL) >= 0) ?
+                               YAFFS_OK : YAFFS_FAIL;
 }
 
 
@@ -4155,12 +4141,7 @@ void yaffs_handle_shadowed_obj(struct yaffs_dev *dev, int obj_id,
 {
        struct yaffs_obj *obj;
 
-       if (!backward_scanning) {
-               /* Handle YAFFS1 forward scanning case
-                * For YAFFS1 we always do the deletion
-                */
-
-       } else {
+       if (backward_scanning) {
                /* Handle YAFFS2 case (backward scanning)
                 * If the shadowed object exists then ignore.
                 */
@@ -4183,18 +4164,17 @@ void yaffs_handle_shadowed_obj(struct yaffs_dev *dev, int obj_id,
        obj->valid = 1;         /* So that we don't read any other info. */
 }
 
-void yaffs_link_fixup(struct yaffs_dev *dev, struct yaffs_obj *hard_list)
+void yaffs_link_fixup(struct yaffs_dev *dev, struct list_head *hard_list)
 {
+       struct list_head *lh;
+       struct list_head *save;
        struct yaffs_obj *hl;
        struct yaffs_obj *in;
 
-       while (hard_list) {
-               hl = hard_list;
-               hard_list = (struct yaffs_obj *)(hard_list->hard_links.next);
-
+       list_for_each_safe(lh, save, hard_list) {
+               hl = list_entry(lh, struct yaffs_obj, hard_links);
                in = yaffs_find_by_number(dev,
-                                         hl->variant.
-                                         hardlink_variant.equiv_id);
+                                       hl->variant.hardlink_variant.equiv_id);
 
                if (in) {
                        /* Add the hardlink pointers */
@@ -4388,8 +4368,7 @@ struct yaffs_obj *yaffs_find_by_name(struct yaffs_obj *directory,
                if (l->obj_id == YAFFS_OBJECTID_LOSTNFOUND) {
                        if (!strcmp(name, YAFFS_LOSTNFOUND_NAME))
                                return l;
-               } else if (l->sum == sum
-                          || l->hdr_chunk <= 0) {
+               } else if (l->sum == sum || l->hdr_chunk <= 0) {
                        /* LostnFound chunk called Objxxx
                         * Do a real check
                         */
@@ -4644,6 +4623,11 @@ int yaffs_guts_initialise(struct yaffs_dev *dev)
                return YAFFS_FAIL;
        }
 
+       if (dev->is_mounted) {
+               yaffs_trace(YAFFS_TRACE_ALWAYS, "device already mounted");
+               return YAFFS_FAIL;
+       }
+
        dev->internal_start_block = dev->param.start_block;
        dev->internal_end_block = dev->param.end_block;
        dev->block_offset = 0;
@@ -4704,11 +4688,6 @@ int yaffs_guts_initialise(struct yaffs_dev *dev)
                return YAFFS_FAIL;
        }
 
-       if (dev->is_mounted) {
-               yaffs_trace(YAFFS_TRACE_ALWAYS, "device already mounted");
-               return YAFFS_FAIL;
-       }
-
        /* Finished with most checks. Further checks happen later on too. */
 
        dev->is_mounted = 1;
index e4680e819e4610e54a8759855d8600b9cae14450..1c578a54c442b667241f0e74b3bd05ef4078e3d2 100644 (file)
@@ -225,7 +225,7 @@ enum yaffs_block_state {
        YAFFS_BLOCK_STATE_SCANNING,
        /* Being scanned */
 
-       YAFFS_BLOCK_STATE_NEEDS_SCANNING,
+       YAFFS_BLOCK_STATE_NEEDS_SCAN,
        /* The block might have something on it (ie it is allocating or full,
         * perhaps empty) but it needs to be scanned to determine its true
         * state.
@@ -906,7 +906,7 @@ void yaffs_set_obj_name_from_oh(struct yaffs_obj *obj,
                                const struct yaffs_obj_hdr *oh);
 void yaffs_add_obj_to_dir(struct yaffs_obj *directory, struct yaffs_obj *obj);
 YCHAR *yaffs_clone_str(const YCHAR *str);
-void yaffs_link_fixup(struct yaffs_dev *dev, struct yaffs_obj *hard_list);
+void yaffs_link_fixup(struct yaffs_dev *dev, struct list_head *hard_list);
 void yaffs_block_became_dirty(struct yaffs_dev *dev, int block_no);
 int yaffs_update_oh(struct yaffs_obj *in, const YCHAR *name,
                    int force, int is_shrink, int shadows,
index b36a8bec42160c7da5a1d8f73ff57c4aaca9e864..b5fccec35f590bc2c903af63ef0662def6247e73 100644 (file)
@@ -26,8 +26,8 @@ int nandmtd_erase_block(struct yaffs_dev *dev, int block_no)
 {
        struct mtd_info *mtd = yaffs_dev_to_mtd(dev);
        u32 addr =
-           ((loff_t) block_no) * dev->param.total_bytes_per_chunk
-           dev->param.chunks_per_block;
+           ((loff_t) block_no) * dev->param.total_bytes_per_chunk *
+           dev->param.chunks_per_block;
        struct erase_info ei;
        int retval = 0;
 
@@ -43,8 +43,8 @@ int nandmtd_erase_block(struct yaffs_dev *dev, int block_no)
 
        if (retval == 0)
                return YAFFS_OK;
-       else
-               return YAFFS_FAIL;
+
+       return YAFFS_FAIL;
 }
 
 int nandmtd_initialise(struct yaffs_dev *dev)
index 291000716a8578a9d436708917d6d27eee01c243..9ec0d7fbdc23c917762c830814fb77b562443b3c 100644 (file)
@@ -314,7 +314,7 @@ static int nandmtd1_test_prerequists(struct mtd_info *mtd)
  *
  * Examine the tags of the first chunk of the block and return the state:
  *  - YAFFS_BLOCK_STATE_DEAD, the block is marked bad
- *  - YAFFS_BLOCK_STATE_NEEDS_SCANNING, the block is in use
+ *  - YAFFS_BLOCK_STATE_NEEDS_SCAN, the block is in use
  *  - YAFFS_BLOCK_STATE_EMPTY, the block is clean
  *
  * Always returns YAFFS_OK.
@@ -345,9 +345,9 @@ int nandmtd1_query_block(struct yaffs_dev *dev, int block_no,
                state = YAFFS_BLOCK_STATE_DEAD;
        } else if (etags.ecc_result != YAFFS_ECC_RESULT_NO_ERROR) {
                /* bad tags, need to look more closely */
-               state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
+               state = YAFFS_BLOCK_STATE_NEEDS_SCAN;
        } else if (etags.chunk_used) {
-               state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
+               state = YAFFS_BLOCK_STATE_NEEDS_SCAN;
                seqnum = etags.seq_number;
        } else {
                state = YAFFS_BLOCK_STATE_EMPTY;
index 182870cb5ab63ca8526bf26184db2a58e8fd02a0..d82f4d783806dc27610cabb271e9dc6dda997527 100644 (file)
@@ -283,7 +283,7 @@ static int nandmtd1_test_prerequists(struct mtd_info *mtd)
  *
  * Examine the tags of the first chunk of the block and return the state:
  *  - YAFFS_BLOCK_STATE_DEAD, the block is marked bad
- *  - YAFFS_BLOCK_STATE_NEEDS_SCANNING, the block is in use
+ *  - YAFFS_BLOCK_STATE_NEEDS_SCAN, the block is in use
  *  - YAFFS_BLOCK_STATE_EMPTY, the block is clean
  *
  * Always returns YAFFS_OK.
@@ -313,9 +313,9 @@ int nandmtd1_query_block(struct yaffs_dev *dev, int block_no,
                state = YAFFS_BLOCK_STATE_DEAD;
        } else if (etags.ecc_result != YAFFS_ECC_RESULT_NO_ERROR) {
                /* bad tags, need to look more closely */
-               state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
+               state = YAFFS_BLOCK_STATE_NEEDS_SCAN;
        } else if (etags.chunk_used) {
-               state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
+               state = YAFFS_BLOCK_STATE_NEEDS_SCAN;
                seqnum = etags.seq_number;
        } else {
                state = YAFFS_BLOCK_STATE_EMPTY;
index 6eac0251047246db196947997e21e5e36541219b..10b7a4fec27631d2113c6b9d125ad2a121af64fc 100644 (file)
@@ -244,7 +244,7 @@ int nandmtd2_query_block(struct yaffs_dev *dev, int block_no,
 
                if (t.chunk_used) {
                        *seq_number = t.seq_number;
-                       *state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
+                       *state = YAFFS_BLOCK_STATE_NEEDS_SCAN;
                } else {
                        *seq_number = 0;
                        *state = YAFFS_BLOCK_STATE_EMPTY;
index 18340bde8ecd38de8e2a1b8613305a2bd5913395..cafb1c311f5db64df5a1367efe825d582beb896f 100644 (file)
@@ -57,9 +57,8 @@ int nandmtd2_write_chunk_tags(struct yaffs_dev *dev, int nand_chunk,
                struct yaffs_packed_tags2_tags_only *pt2tp;
 
                pt2tp =
-                   (struct yaffs_packed_tags2_tags_only *)(data +
-                                                       dev->
-                                                       data_bytes_per_chunk);
+                   (struct yaffs_packed_tags2_tags_only *)
+                       (data + dev->data_bytes_per_chunk);
                yaffs_pack_tags2_tags_only(pt2tp, tags);
        } else {
                yaffs_pack_tags2(&pt, tags, !dev->param.no_tags_ecc);
@@ -75,8 +74,8 @@ int nandmtd2_write_chunk_tags(struct yaffs_dev *dev, int nand_chunk,
 
        if (retval == 0)
                return YAFFS_OK;
-       else
-               return YAFFS_FAIL;
+
+       return YAFFS_FAIL;
 }
 
 int nandmtd2_read_chunk_tags(struct yaffs_dev *dev, int nand_chunk,
@@ -98,18 +97,15 @@ int nandmtd2_read_chunk_tags(struct yaffs_dev *dev, int nand_chunk,
                "nandmtd2_read_chunk_tags chunk %d data %p tags %p",
                nand_chunk, data, tags);
 
-       if (dev->param.inband_tags) {
-
-               if (!data) {
-                       local_data = 1;
-                       data = yaffs_get_temp_buffer(dev, __LINE__);
-               }
+       if (dev->param.inband_tags && !data) {
+               local_data = 1;
+               data = yaffs_get_temp_buffer(dev, __LINE__);
        }
 
-       if (dev->param.inband_tags || (data && !tags))
+       if (dev->param.inband_tags || (data && !tags)) {
                retval = mtd->read(mtd, addr, dev->param.total_bytes_per_chunk,
                                   &dummy, data);
-       else if (tags) {
+       else if (tags) {
                ops.mode = MTD_OOB_AUTO;
                ops.ooblen = packed_tags_size;
                ops.len = data ? dev->data_bytes_per_chunk : packed_tags_size;
@@ -119,40 +115,38 @@ int nandmtd2_read_chunk_tags(struct yaffs_dev *dev, int nand_chunk,
                retval = mtd->read_oob(mtd, addr, &ops);
        }
 
-       if (dev->param.inband_tags) {
-               if (tags) {
-                       struct yaffs_packed_tags2_tags_only *pt2tp;
-                       pt2tp =
-                               (struct yaffs_packed_tags2_tags_only *)
-                                       &data[dev->data_bytes_per_chunk];
-                       yaffs_unpack_tags2_tags_only(tags, pt2tp);
-               }
-       } else {
-               if (tags) {
-                       memcpy(packed_tags_ptr,
-                              yaffs_dev_to_lc(dev)->spare_buffer,
-                              packed_tags_size);
-                       yaffs_unpack_tags2(tags, &pt, !dev->param.no_tags_ecc);
-               }
+       if (dev->param.inband_tags && tags) {
+               struct yaffs_packed_tags2_tags_only *pt2tp;
+
+               pt2tp =
+                       (struct yaffs_packed_tags2_tags_only *)
+                               &data[dev->data_bytes_per_chunk];
+               yaffs_unpack_tags2_tags_only(tags, pt2tp);
+       } else if (tags) {
+               memcpy(packed_tags_ptr,
+                      yaffs_dev_to_lc(dev)->spare_buffer,
+                      packed_tags_size);
+               yaffs_unpack_tags2(tags, &pt, !dev->param.no_tags_ecc);
        }
 
        if (local_data)
                yaffs_release_temp_buffer(dev, data, __LINE__);
 
-       if (tags && retval == -EBADMSG
-           && tags->ecc_result == YAFFS_ECC_RESULT_NO_ERROR) {
+       if (tags && retval == -EBADMSG &&
+           tags->ecc_result == YAFFS_ECC_RESULT_NO_ERROR) {
                tags->ecc_result = YAFFS_ECC_RESULT_UNFIXED;
                dev->n_ecc_unfixed++;
        }
-       if (tags && retval == -EUCLEAN
-           && tags->ecc_result == YAFFS_ECC_RESULT_NO_ERROR) {
+       if (tags && retval == -EUCLEAN &&
+           tags->ecc_result == YAFFS_ECC_RESULT_NO_ERROR) {
                tags->ecc_result = YAFFS_ECC_RESULT_FIXED;
                dev->n_ecc_fixed++;
        }
+
        if (retval == 0)
                return YAFFS_OK;
-       else
-               return YAFFS_FAIL;
+
+       return YAFFS_FAIL;
 }
 
 int nandmtd2_mark_block_bad(struct yaffs_dev *dev, int block_no)
@@ -170,8 +164,8 @@ int nandmtd2_mark_block_bad(struct yaffs_dev *dev, int block_no)
 
        if (retval == 0)
                return YAFFS_OK;
-       else
-               return YAFFS_FAIL;
+
+       return YAFFS_FAIL;
 }
 
 int nandmtd2_query_block(struct yaffs_dev *dev, int block_no,
@@ -193,12 +187,13 @@ int nandmtd2_query_block(struct yaffs_dev *dev, int block_no,
                *seq_number = 0;
        } else {
                struct yaffs_ext_tags t;
+
                nandmtd2_read_chunk_tags(dev, block_no *
                                         dev->param.chunks_per_block, NULL, &t);
 
                if (t.chunk_used) {
                        *seq_number = t.seq_number;
-                       *state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
+                       *state = YAFFS_BLOCK_STATE_NEEDS_SCAN;
                } else {
                        *seq_number = 0;
                        *state = YAFFS_BLOCK_STATE_EMPTY;
@@ -209,7 +204,6 @@ int nandmtd2_query_block(struct yaffs_dev *dev, int block_no,
 
        if (retval == 0)
                return YAFFS_OK;
-       else
-               return YAFFS_FAIL;
-}
 
+       return YAFFS_FAIL;
+}
index 18c30b3372c48f9cdf2a7c3c5a81f74b5df7d56f..8d0fa4e565ed11f6157ac91f165ba3da30a710be 100644 (file)
@@ -37,8 +37,7 @@ static int nval_find(const char *xb, int xb_size, const YCHAR *name,
 
        memcpy(&size, xb, sizeof(int));
        while (size > 0 && (size < xb_size) && (pos + size < xb_size)) {
-               if (strncmp
-                   ((YCHAR *) (xb + pos + sizeof(int)), name, size) == 0) {
+               if (!strncmp((YCHAR *) (xb + pos + sizeof(int)), name, size)) {
                        if (exist_size)
                                *exist_size = size;
                        return pos;
@@ -152,12 +151,11 @@ int nval_get(const char *xb, int xb_size, const YCHAR * name, char *buf,
                        memcpy(buf, xb + pos, size);
                        return size;
                }
-
        }
        if (pos >= 0)
                return -ERANGE;
-       else
-               return -ENODATA;
+
+       return -ENODATA;
 }
 
 int nval_list(const char *xb, int xb_size, char *buf, int bsize)
index ff9daad6eab9eb7513eb5584840c47bec36db565..a1fe5c4bb1f657420aeddda609d96ff0e1e9be20 100644 (file)
@@ -75,8 +75,8 @@ int yaffs_wr_chunk_tags_nand(struct yaffs_dev *dev,
        if (dev->param.write_chunk_tags_fn)
                return dev->param.write_chunk_tags_fn(dev, nand_chunk, buffer,
                                                        tags);
-       else
-               return yaffs_tags_compat_wr(dev, nand_chunk, buffer, tags);
+
+       return yaffs_tags_compat_wr(dev, nand_chunk, buffer, tags);
 }
 
 int yaffs_mark_bad(struct yaffs_dev *dev, int block_no)
@@ -84,8 +84,8 @@ int yaffs_mark_bad(struct yaffs_dev *dev, int block_no)
        block_no -= dev->block_offset;
        if (dev->param.bad_block_fn)
                return dev->param.bad_block_fn(dev, block_no);
-       else
-               return yaffs_tags_compat_mark_bad(dev, block_no);
+
+       return yaffs_tags_compat_mark_bad(dev, block_no);
 }
 
 int yaffs_query_init_block_state(struct yaffs_dev *dev,
@@ -97,9 +97,8 @@ int yaffs_query_init_block_state(struct yaffs_dev *dev,
        if (dev->param.query_block_fn)
                return dev->param.query_block_fn(dev, block_no, state,
                                                 seq_number);
-       else
-               return yaffs_tags_compat_query_block(dev, block_no,
-                                                    state, seq_number);
+
+       return yaffs_tags_compat_query_block(dev, block_no, state, seq_number);
 }
 
 int yaffs_erase_block(struct yaffs_dev *dev, int flash_block)
index 873f06520b0322782aaad2a4678bf4d039681894..b35efe0a9f735e754316f066e0c32ce5aef3f62b 100644 (file)
 #include "yaffs_packedtags1.h"
 #include "yportenv.h"
 
+static const u8 all_ff[20] = {
+       0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff
+};
+
 void yaffs_pack_tags1(struct yaffs_packed_tags1 *pt,
                      const struct yaffs_ext_tags *t)
 {
@@ -30,11 +38,6 @@ void yaffs_pack_tags1(struct yaffs_packed_tags1 *pt,
 void yaffs_unpack_tags1(struct yaffs_ext_tags *t,
                        const struct yaffs_packed_tags1 *pt)
 {
-       static const u8 all_ff[12] = {
-               0xff, 0xff, 0xff, 0xff,
-               0xff, 0xff, 0xff, 0xff,
-               0xff, 0xff, 0xff, 0xff
-       };
 
        if (memcmp(all_ff, pt, sizeof(struct yaffs_packed_tags1))) {
                t->block_bad = 0;
index 2bb31b0707e49e39538aab5577c6dabf47075281..4ec5e59eb61d5d27136beab944493e7e024dec61 100644 (file)
@@ -100,9 +100,8 @@ void yaffs_pack_tags2(struct yaffs_packed_tags2 *pt,
 
        if (tags_ecc)
                yaffs_ecc_calc_other((unsigned char *)&pt->t,
-                                    sizeof(struct
-                                           yaffs_packed_tags2_tags_only),
-                                    &pt->ecc);
+                                   sizeof(struct yaffs_packed_tags2_tags_only),
+                                   &pt->ecc);
 }
 
 void yaffs_unpack_tags2_tags_only(struct yaffs_ext_tags *t,
@@ -111,37 +110,34 @@ void yaffs_unpack_tags2_tags_only(struct yaffs_ext_tags *t,
        memset(t, 0, sizeof(struct yaffs_ext_tags));
        yaffs_init_tags(t);
 
-       if (ptt->seq_number != 0xFFFFFFFF) {
-               t->block_bad = 0;
-               t->chunk_used = 1;
-               t->obj_id = ptt->obj_id;
-               t->chunk_id = ptt->chunk_id;
-               t->n_bytes = ptt->n_bytes;
-               t->is_deleted = 0;
-               t->serial_number = 0;
-               t->seq_number = ptt->seq_number;
-
-               /* Do extra header info stuff */
-               if (ptt->chunk_id & EXTRA_HEADER_INFO_FLAG) {
-                       t->chunk_id = 0;
-                       t->n_bytes = 0;
-
-                       t->extra_available = 1;
-                       t->extra_parent_id =
-                           ptt->chunk_id & (~(ALL_EXTRA_FLAGS));
-                       t->extra_is_shrink =
-                           (ptt->chunk_id & EXTRA_SHRINK_FLAG) ? 1 : 0;
-                       t->extra_shadows =
-                           (ptt->chunk_id & EXTRA_SHADOWS_FLAG) ? 1 : 0;
-                       t->extra_obj_type =
-                           ptt->obj_id >> EXTRA_OBJECT_TYPE_SHIFT;
-                       t->obj_id &= ~EXTRA_OBJECT_TYPE_MASK;
-
-                       if (t->extra_obj_type == YAFFS_OBJECT_TYPE_HARDLINK)
-                               t->extra_equiv_id = ptt->n_bytes;
-                       else
-                               t->extra_length = ptt->n_bytes;
-               }
+       if (ptt->seq_number == 0xFFFFFFFF)
+               return;
+
+       t->block_bad = 0;
+       t->chunk_used = 1;
+       t->obj_id = ptt->obj_id;
+       t->chunk_id = ptt->chunk_id;
+       t->n_bytes = ptt->n_bytes;
+       t->is_deleted = 0;
+       t->serial_number = 0;
+       t->seq_number = ptt->seq_number;
+
+       /* Do extra header info stuff */
+       if (ptt->chunk_id & EXTRA_HEADER_INFO_FLAG) {
+               t->chunk_id = 0;
+               t->n_bytes = 0;
+
+               t->extra_available = 1;
+               t->extra_parent_id = ptt->chunk_id & (~(ALL_EXTRA_FLAGS));
+               t->extra_is_shrink = ptt->chunk_id & EXTRA_SHRINK_FLAG ? 1 : 0;
+               t->extra_shadows = ptt->chunk_id & EXTRA_SHADOWS_FLAG ? 1 : 0;
+               t->extra_obj_type = ptt->obj_id >> EXTRA_OBJECT_TYPE_SHIFT;
+               t->obj_id &= ~EXTRA_OBJECT_TYPE_MASK;
+
+               if (t->extra_obj_type == YAFFS_OBJECT_TYPE_HARDLINK)
+                       t->extra_equiv_id = ptt->n_bytes;
+               else
+                       t->extra_length = ptt->n_bytes;
        }
        yaffs_dump_packed_tags2_tags_only(ptt);
        yaffs_dump_tags2(t);
index 35d33c91fcee285ec557bac232e909a5faee31e4..fcd3d1780038744dab245232b8b26fcc6432bd84 100644 (file)
@@ -305,9 +305,7 @@ int yaffs_tags_compat_wr(struct yaffs_dev *dev,
                        yaffs_calc_ecc(data, &spare);
 
                yaffs_load_tags_to_spare(&spare, &tags);
-
        }
-
        return yaffs_wr_nand(dev, nand_chunk, data, &spare);
 }
 
@@ -320,48 +318,44 @@ int yaffs_tags_compat_rd(struct yaffs_dev *dev,
        enum yaffs_ecc_result ecc_result = YAFFS_ECC_RESULT_UNKNOWN;
        static struct yaffs_spare spare_ff;
        static int init;
+       int deleted;
 
        if (!init) {
                memset(&spare_ff, 0xFF, sizeof(spare_ff));
                init = 1;
        }
 
-       if (yaffs_rd_chunk_nand(dev, nand_chunk,
-                                       data, &spare, &ecc_result, 1)) {
-               /* ext_tags may be NULL */
-               if (ext_tags) {
-
-                       int deleted =
-                           (hweight8(spare.page_status) < 7) ? 1 : 0;
+       if (!yaffs_rd_chunk_nand(dev, nand_chunk,
+                                       data, &spare, &ecc_result, 1))
+               return YAFFS_FAIL;
 
-                       ext_tags->is_deleted = deleted;
-                       ext_tags->ecc_result = ecc_result;
-                       ext_tags->block_bad = 0;        /* We're reading it */
-                       /* therefore it is not a bad block */
-                       ext_tags->chunk_used =
-                           (memcmp(&spare_ff, &spare, sizeof(spare_ff)) !=
-                            0) ? 1 : 0;
+       /* ext_tags may be NULL */
+       if (!ext_tags)
+               return YAFFS_OK;
 
-                       if (ext_tags->chunk_used) {
-                               yaffs_get_tags_from_spare(dev, &spare, &tags);
+       deleted = (hweight8(spare.page_status) < 7) ? 1 : 0;
 
-                               ext_tags->obj_id = tags.obj_id;
-                               ext_tags->chunk_id = tags.chunk_id;
-                               ext_tags->n_bytes = tags.n_bytes_lsb;
+       ext_tags->is_deleted = deleted;
+       ext_tags->ecc_result = ecc_result;
+       ext_tags->block_bad = 0;        /* We're reading it */
+       /* therefore it is not a bad block */
+       ext_tags->chunk_used =
+               memcmp(&spare_ff, &spare, sizeof(spare_ff)) ? 1 : 0;
 
-                               if (dev->data_bytes_per_chunk >= 1024)
-                                       ext_tags->n_bytes |=
-                                           (((unsigned)tags.
-                                             n_bytes_msb) << 10);
+       if (ext_tags->chunk_used) {
+               yaffs_get_tags_from_spare(dev, &spare, &tags);
+               ext_tags->obj_id = tags.obj_id;
+               ext_tags->chunk_id = tags.chunk_id;
+               ext_tags->n_bytes = tags.n_bytes_lsb;
 
-                               ext_tags->serial_number = tags.serial_number;
-                       }
-               }
+               if (dev->data_bytes_per_chunk >= 1024)
+                       ext_tags->n_bytes |=
+                               (((unsigned)tags.n_bytes_msb) << 10);
 
-               return YAFFS_OK;
-       } else {
-               return YAFFS_FAIL;
+               ext_tags->serial_number = tags.serial_number;
        }
+
+       return YAFFS_OK;
 }
 
 int yaffs_tags_compat_mark_bad(struct yaffs_dev *dev, int flash_block)
@@ -407,7 +401,7 @@ int yaffs_tags_compat_query_block(struct yaffs_dev *dev,
        else if (memcmp(&spare_ff, &spare0, sizeof(spare_ff)) == 0)
                *state = YAFFS_BLOCK_STATE_EMPTY;
        else
-               *state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
+               *state = YAFFS_BLOCK_STATE_NEEDS_SCAN;
 
        return YAFFS_OK;
 }
index 582f36acbfd06ff4cfa54341507d27f51e1bf031..1bbada03d0916c868ef9063975d76501531d5a5a 100644 (file)
 
 #include "yaffs_tagsvalidity.h"
 
+#define VALID0 0xAAAAAAAA
+#define VALID1 0x55555555
+
 void yaffs_init_tags(struct yaffs_ext_tags *tags)
 {
        memset(tags, 0, sizeof(struct yaffs_ext_tags));
-       tags->validity0 = 0xAAAAAAAA;
-       tags->validity1 = 0x55555555;
+       tags->validity0 = VALID0;
+       tags->validity1 = VALID1;
 }
 
 int yaffs_validate_tags(struct yaffs_ext_tags *tags)
 {
-       return (tags->validity0 == 0xAAAAAAAA && tags->validity1 == 0x55555555);
+       return (tags->validity0 == VALID0 && tags->validity1 == VALID1);
 }
index 87e39c886ea40f8a96eb38328776ef4222fb390a..bf254dadf43087bef3c489d7ef09988f27301308 100644 (file)
@@ -38,7 +38,7 @@ static int yaffs_skip_nand_verification(struct yaffs_dev *dev)
 
 static const char * const block_state_name[] = {
        "Unknown",
-       "Needs scanning",
+       "Needs scan",
        "Scanning",
        "Empty",
        "Allocating",
@@ -66,7 +66,7 @@ void yaffs_verify_blk(struct yaffs_dev *dev, struct yaffs_block_info *bi, int n)
        switch (bi->block_state) {
        case YAFFS_BLOCK_STATE_UNKNOWN:
        case YAFFS_BLOCK_STATE_SCANNING:
-       case YAFFS_BLOCK_STATE_NEEDS_SCANNING:
+       case YAFFS_BLOCK_STATE_NEEDS_SCAN:
                yaffs_trace(YAFFS_TRACE_VERIFY,
                        "Block %d has bad run-state %s",
                        n, block_state_name[bi->block_state]);
@@ -76,11 +76,11 @@ void yaffs_verify_blk(struct yaffs_dev *dev, struct yaffs_block_info *bi, int n)
 
        actually_used = bi->pages_in_use - bi->soft_del_pages;
 
-       if (bi->pages_in_use < 0
-           || bi->pages_in_use > dev->param.chunks_per_block
-           || bi->soft_del_pages < 0
-           || bi->soft_del_pages > dev->param.chunks_per_block
-           || actually_used < 0 || actually_used > dev->param.chunks_per_block)
+       if (bi->pages_in_use < 0 ||
+           bi->pages_in_use > dev->param.chunks_per_block ||
+           bi->soft_del_pages < 0 ||
+           bi->soft_del_pages > dev->param.chunks_per_block ||
+           actually_used < 0 || actually_used > dev->param.chunks_per_block)
                yaffs_trace(YAFFS_TRACE_VERIFY,
                        "Block %d has illegal values pages_in_used %d soft_del_pages %d",
                        n, bi->pages_in_use, bi->soft_del_pages);
@@ -225,6 +225,7 @@ void yaffs_verify_file(struct yaffs_obj *obj)
        int required_depth;
        int actual_depth;
        u32 last_chunk;
+       u32 the_chunk;
        u32 x;
        u32 i;
        struct yaffs_dev *dev;
@@ -264,17 +265,18 @@ void yaffs_verify_file(struct yaffs_obj *obj)
        for (i = 1; i <= last_chunk; i++) {
                tn = yaffs_find_tnode_0(dev, &obj->variant.file_variant, i);
 
-               if (tn) {
-                       u32 the_chunk = yaffs_get_group_base(dev, tn, i);
-                       if (the_chunk > 0) {
-                               yaffs_rd_chunk_tags_nand(dev, the_chunk, NULL,
-                                                        &tags);
-                               if (tags.obj_id != obj_id || tags.chunk_id != i)
-                                       yaffs_trace(YAFFS_TRACE_VERIFY,
-                                               "Object %d chunk_id %d NAND mismatch chunk %d tags (%d:%d)",
-                                               obj_id, i, the_chunk,
-                                               tags.obj_id, tags.chunk_id);
-                       }
+               if (!tn)
+                       continue;
+
+               the_chunk = yaffs_get_group_base(dev, tn, i);
+               if (the_chunk > 0) {
+                       yaffs_rd_chunk_tags_nand(dev, the_chunk, NULL,
+                                                &tags);
+                       if (tags.obj_id != obj_id || tags.chunk_id != i)
+                               yaffs_trace(YAFFS_TRACE_VERIFY,
+                                       "Object %d chunk_id %d NAND mismatch chunk %d tags (%d:%d)",
+                                       obj_id, i, the_chunk,
+                                       tags.obj_id, tags.chunk_id);
                }
        }
 }
@@ -366,8 +368,8 @@ void yaffs_verify_obj(struct yaffs_obj *obj)
        }
 
        /* Verify parent is a directory */
-       if (obj->parent
-           && obj->parent->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY) {
+       if (obj->parent &&
+           obj->parent->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY) {
                yaffs_trace(YAFFS_TRACE_VERIFY,
                        "Obj %d's parent is not a directory (type %d)",
                        obj->obj_id, obj->parent->variant_type);
@@ -521,4 +523,3 @@ int yaffs_verify_file_sane(struct yaffs_obj *in)
        in = in;
        return YAFFS_OK;
 }
-
index 4a0ec0a9312b40db05d9902148cd3c5aae8e051b..32734a68ee21dfeefda42cd86d5056d7fc8cc848 100644 (file)
@@ -201,16 +201,16 @@ static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
        if ((dir->i_mode & S_ISGID) && S_ISDIR(mode))
                mode |= S_ISGID;
 
-       if (parent) {
-               yaffs_trace(YAFFS_TRACE_OS,
-                       "yaffs_mknod: parent object %d type %d",
-                       parent->obj_id, parent->variant_type);
-       } else {
+       if (!parent) {
                yaffs_trace(YAFFS_TRACE_OS,
                        "yaffs_mknod: could not get parent object");
                return -EPERM;
        }
 
+       yaffs_trace(YAFFS_TRACE_OS,
+                       "yaffs_mknod: parent object %d type %d",
+                       parent->obj_id, parent->variant_type);
+
        yaffs_trace(YAFFS_TRACE_OS,
                "yaffs_mknod: making oject for %s, mode %x dev %x",
                dentry->d_name.name, mode, rdev);
@@ -246,21 +246,20 @@ static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
        /* Can not call yaffs_get_inode() with gross lock held */
        yaffs_gross_unlock(dev);
 
-       if (obj) {
-               inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
-               d_instantiate(dentry, inode);
-               update_dir_time(dir);
-               yaffs_trace(YAFFS_TRACE_OS,
-                       "yaffs_mknod created object %d count = %d",
-                       obj->obj_id, atomic_read(&inode->i_count));
-               error = 0;
-               yaffs_fill_inode_from_obj(dir, parent);
-       } else {
+       if (!obj) {
                yaffs_trace(YAFFS_TRACE_OS, "yaffs_mknod failed making object");
-               error = -ENOMEM;
+               return -ENOMEM;
        }
 
-       return error;
+       inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
+       d_instantiate(dentry, inode);
+       update_dir_time(dir);
+       yaffs_trace(YAFFS_TRACE_OS,
+               "yaffs_mknod created object %d count = %d",
+               obj->obj_id, atomic_read(&inode->i_count));
+       yaffs_fill_inode_from_obj(dir, parent);
+
+       return 0;
 }
 
 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
@@ -319,6 +318,7 @@ static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
 {
        struct yaffs_obj *obj;
        struct yaffs_dev *dev;
+       struct inode *inode;
        uid_t uid = current->cred->fsuid;
        gid_t gid =
            (dir->i_mode & S_ISGID) ? dir->i_gid : current->cred->fsgid;
@@ -331,19 +331,17 @@ static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
                                   S_IFLNK | S_IRWXUGO, uid, gid, symname);
        yaffs_gross_unlock(dev);
 
-       if (obj) {
-               struct inode *inode;
-
-               inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
-               d_instantiate(dentry, inode);
-               update_dir_time(dir);
-               yaffs_trace(YAFFS_TRACE_OS, "symlink created OK");
-               return 0;
-       } else {
+       if (!obj) {
                yaffs_trace(YAFFS_TRACE_OS, "symlink not created");
+               return -ENOMEM;
        }
 
-       return -ENOMEM;
+       inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
+       d_instantiate(dentry, inode);
+       update_dir_time(dir);
+       yaffs_trace(YAFFS_TRACE_OS, "symlink created OK");
+
+       return 0;
 }
 
 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
@@ -494,6 +492,7 @@ static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
        struct inode *inode = dentry->d_inode;
        int error = 0;
        struct yaffs_dev *dev;
+       int result;
 
        yaffs_trace(YAFFS_TRACE_OS,
                "yaffs_setattr of object %d",
@@ -503,17 +502,15 @@ static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
        if (attr->ia_valid & ATTR_SIZE && (attr->ia_size >> 31))
                error = -EINVAL;
 
-       if (error == 0)
+       if (!error)
                error = inode_change_ok(inode, attr);
-       if (error == 0) {
-               int result;
-               if (!error) {
-                       setattr_copy(inode, attr);
-                       yaffs_trace(YAFFS_TRACE_OS, "inode_setattr called");
-                       if (attr->ia_valid & ATTR_SIZE) {
-                               truncate_setsize(inode, attr->ia_size);
-                               inode->i_blocks = (inode->i_size + 511) >> 9;
-                       }
+
+       if (!error) {
+               setattr_copy(inode, attr);
+               yaffs_trace(YAFFS_TRACE_OS, "inode_setattr called");
+               if (attr->ia_valid & ATTR_SIZE) {
+                       truncate_setsize(inode, attr->ia_size);
+                       inode->i_blocks = (inode->i_size + 511) >> 9;
                }
                dev = yaffs_inode_to_obj(inode)->my_dev;
                if (attr->ia_valid & ATTR_SIZE) {
@@ -521,11 +518,10 @@ static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
                                           (int)(attr->ia_size),
                                           (int)(attr->ia_size));
                }
+
                yaffs_gross_lock(dev);
                result = yaffs_set_attribs(yaffs_inode_to_obj(inode), attr);
-               if (result == YAFFS_OK)
-                       error = 0;
-               else
+               if (result != YAFFS_OK)
                        error = -EPERM;
                yaffs_gross_unlock(dev);
        }
@@ -540,23 +536,17 @@ static int yaffs_setxattr(struct dentry *dentry, const char *name,
                   const void *value, size_t size, int flags)
 {
        struct inode *inode = dentry->d_inode;
-       int error = 0;
+       int error;
        struct yaffs_dev *dev;
        struct yaffs_obj *obj = yaffs_inode_to_obj(inode);
 
        yaffs_trace(YAFFS_TRACE_OS, "yaffs_setxattr of object %d", obj->obj_id);
 
-       if (error == 0) {
-               int result;
-               dev = obj->my_dev;
-               yaffs_gross_lock(dev);
-               result = yaffs_set_xattrib(obj, name, value, size, flags);
-               if (result == YAFFS_OK)
-                       error = 0;
-               else if (result < 0)
-                       error = result;
-               yaffs_gross_unlock(dev);
-       }
+       dev = obj->my_dev;
+       yaffs_gross_lock(dev);
+       error = yaffs_set_xattrib(obj, name, value, size, flags);
+       yaffs_gross_unlock(dev);
+
        yaffs_trace(YAFFS_TRACE_OS, "yaffs_setxattr done returning %d", error);
 
        return error;
@@ -566,7 +556,7 @@ static ssize_t yaffs_getxattr(struct dentry *dentry, const char *name,
                                void *buff, size_t size)
 {
        struct inode *inode = dentry->d_inode;
-       int error = 0;
+       int error;
        struct yaffs_dev *dev;
        struct yaffs_obj *obj = yaffs_inode_to_obj(inode);
 
@@ -574,12 +564,11 @@ static ssize_t yaffs_getxattr(struct dentry *dentry, const char *name,
                "yaffs_getxattr \"%s\" from object %d",
                name, obj->obj_id);
 
-       if (error == 0) {
-               dev = obj->my_dev;
-               yaffs_gross_lock(dev);
-               error = yaffs_get_xattrib(obj, name, buff, size);
-               yaffs_gross_unlock(dev);
-       }
+       dev = obj->my_dev;
+       yaffs_gross_lock(dev);
+       error = yaffs_get_xattrib(obj, name, buff, size);
+       yaffs_gross_unlock(dev);
+
        yaffs_trace(YAFFS_TRACE_OS, "yaffs_getxattr done returning %d", error);
 
        return error;
@@ -588,24 +577,18 @@ static ssize_t yaffs_getxattr(struct dentry *dentry, const char *name,
 static int yaffs_removexattr(struct dentry *dentry, const char *name)
 {
        struct inode *inode = dentry->d_inode;
-       int error = 0;
+       int error;
        struct yaffs_dev *dev;
        struct yaffs_obj *obj = yaffs_inode_to_obj(inode);
 
        yaffs_trace(YAFFS_TRACE_OS,
                "yaffs_removexattr of object %d", obj->obj_id);
 
-       if (error == 0) {
-               int result;
-               dev = obj->my_dev;
-               yaffs_gross_lock(dev);
-               result = yaffs_remove_xattrib(obj, name);
-               if (result == YAFFS_OK)
-                       error = 0;
-               else if (result < 0)
-                       error = result;
-               yaffs_gross_unlock(dev);
-       }
+       dev = obj->my_dev;
+       yaffs_gross_lock(dev);
+       error = yaffs_remove_xattrib(obj, name);
+       yaffs_gross_unlock(dev);
+
        yaffs_trace(YAFFS_TRACE_OS,
                "yaffs_removexattr done returning %d", error);
 
@@ -615,19 +598,18 @@ static int yaffs_removexattr(struct dentry *dentry, const char *name)
 static ssize_t yaffs_listxattr(struct dentry *dentry, char *buff, size_t size)
 {
        struct inode *inode = dentry->d_inode;
-       int error = 0;
+       int error;
        struct yaffs_dev *dev;
        struct yaffs_obj *obj = yaffs_inode_to_obj(inode);
 
        yaffs_trace(YAFFS_TRACE_OS,
                "yaffs_listxattr of object %d", obj->obj_id);
 
-       if (error == 0) {
-               dev = obj->my_dev;
-               yaffs_gross_lock(dev);
-               error = yaffs_list_xattrib(obj, buff, size);
-               yaffs_gross_unlock(dev);
-       }
+       dev = obj->my_dev;
+       yaffs_gross_lock(dev);
+       error = yaffs_list_xattrib(obj, buff, size);
+       yaffs_gross_unlock(dev);
+
        yaffs_trace(YAFFS_TRACE_OS,
                "yaffs_listxattr done returning %d", error);
 
@@ -692,18 +674,20 @@ static struct yaffs_search_context *yaffs_new_search(struct yaffs_obj *dir)
        struct yaffs_search_context *sc =
            kmalloc(sizeof(struct yaffs_search_context), GFP_NOFS);
 
-       if (sc) {
-               sc->dir_obj = dir;
-               sc->dev = dev;
-               if (list_empty(&sc->dir_obj->variant.dir_variant.children))
-                       sc->next_return = NULL;
-               else
-                       sc->next_return =
-                           list_entry(dir->variant.dir_variant.children.next,
-                                      struct yaffs_obj, siblings);
-               INIT_LIST_HEAD(&sc->others);
-               list_add(&sc->others, &(yaffs_dev_to_lc(dev)->search_contexts));
-       }
+       if (!sc)
+               return NULL;
+
+       sc->dir_obj = dir;
+       sc->dev = dev;
+       if (list_empty(&sc->dir_obj->variant.dir_variant.children))
+               sc->next_return = NULL;
+       else
+               sc->next_return =
+                   list_entry(dir->variant.dir_variant.children.next,
+                              struct yaffs_obj, siblings);
+       INIT_LIST_HEAD(&sc->others);
+       list_add(&sc->others, &(yaffs_dev_to_lc(dev)->search_contexts));
+
        return sc;
 }
 
@@ -1444,8 +1428,8 @@ static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf)
 
                bytes_in_dev =
                    ((uint64_t)
-                    ((dev->param.end_block - dev->param.start_block +
-                      1))) * ((uint64_t) (dev->param.chunks_per_block *
+                    ((dev->param.end_block - dev->param.start_block + 1))) *
+                    ((uint64_t) (dev->param.chunks_per_block *
                                           dev->data_bytes_per_chunk));
 
                do_div(bytes_in_dev, sb->s_blocksize);
@@ -1830,92 +1814,86 @@ static const struct inode_operations yaffs_symlink_inode_operations = {
 static void yaffs_fill_inode_from_obj(struct inode *inode,
                                      struct yaffs_obj *obj)
 {
-       if (inode && obj) {
-               /* Check mode against the variant type
-                * and attempt to repair if broken. */
-               u32 mode = obj->yst_mode;
-               switch (obj->variant_type) {
-               case YAFFS_OBJECT_TYPE_FILE:
-                       if (!S_ISREG(mode)) {
-                               obj->yst_mode &= ~S_IFMT;
-                               obj->yst_mode |= S_IFREG;
-                       }
-
-                       break;
-               case YAFFS_OBJECT_TYPE_SYMLINK:
-                       if (!S_ISLNK(mode)) {
-                               obj->yst_mode &= ~S_IFMT;
-                               obj->yst_mode |= S_IFLNK;
-                       }
+       if (!inode || !obj)  {
+               yaffs_trace(YAFFS_TRACE_OS,
+                       "yaffs_fill_inode invalid parameters");
+               return;
+       }
 
-                       break;
-               case YAFFS_OBJECT_TYPE_DIRECTORY:
-                       if (!S_ISDIR(mode)) {
-                               obj->yst_mode &= ~S_IFMT;
-                               obj->yst_mode |= S_IFDIR;
-                       }
+       /* Check mode against the variant type
+        * and attempt to repair if broken. */
+       u32 mode = obj->yst_mode;
 
-                       break;
-               case YAFFS_OBJECT_TYPE_UNKNOWN:
-               case YAFFS_OBJECT_TYPE_HARDLINK:
-               case YAFFS_OBJECT_TYPE_SPECIAL:
-               default:
-                       /* TODO? */
-                       break;
+       switch (obj->variant_type) {
+       case YAFFS_OBJECT_TYPE_FILE:
+               if (!S_ISREG(mode)) {
+                       obj->yst_mode &= ~S_IFMT;
+                       obj->yst_mode |= S_IFREG;
                }
-
-               inode->i_flags |= S_NOATIME;
-
-               inode->i_ino = obj->obj_id;
-               inode->i_mode = obj->yst_mode;
-               inode->i_uid = obj->yst_uid;
-               inode->i_gid = obj->yst_gid;
-
-               inode->i_rdev = old_decode_dev(obj->yst_rdev);
-
-               inode->i_atime.tv_sec = (time_t) (obj->yst_atime);
-               inode->i_atime.tv_nsec = 0;
-               inode->i_mtime.tv_sec = (time_t) obj->yst_mtime;
-               inode->i_mtime.tv_nsec = 0;
-               inode->i_ctime.tv_sec = (time_t) obj->yst_ctime;
-               inode->i_ctime.tv_nsec = 0;
-               inode->i_size = yaffs_get_obj_length(obj);
-               inode->i_blocks = (inode->i_size + 511) >> 9;
-
-               inode->i_nlink = yaffs_get_obj_link_count(obj);
-
-               yaffs_trace(YAFFS_TRACE_OS,
-                       "yaffs_fill_inode mode %x uid %d gid %d size %d count %d",
-                       inode->i_mode, inode->i_uid, inode->i_gid,
-                       (int)inode->i_size, atomic_read(&inode->i_count));
-
-               switch (obj->yst_mode & S_IFMT) {
-               default:        /* fifo, device or socket */
-                       init_special_inode(inode, obj->yst_mode,
-                                          old_decode_dev(obj->yst_rdev));
-                       break;
-               case S_IFREG:   /* file */
-                       inode->i_op = &yaffs_file_inode_operations;
-                       inode->i_fop = &yaffs_file_operations;
-                       inode->i_mapping->a_ops =
-                           &yaffs_file_address_operations;
-                       break;
-               case S_IFDIR:   /* directory */
-                       inode->i_op = &yaffs_dir_inode_operations;
-                       inode->i_fop = &yaffs_dir_operations;
-                       break;
-               case S_IFLNK:   /* symlink */
-                       inode->i_op = &yaffs_symlink_inode_operations;
-                       break;
+               break;
+       case YAFFS_OBJECT_TYPE_SYMLINK:
+               if (!S_ISLNK(mode)) {
+                       obj->yst_mode &= ~S_IFMT;
+                       obj->yst_mode |= S_IFLNK;
+               }
+               break;
+       case YAFFS_OBJECT_TYPE_DIRECTORY:
+               if (!S_ISDIR(mode)) {
+                       obj->yst_mode &= ~S_IFMT;
+                       obj->yst_mode |= S_IFDIR;
                }
+               break;
+       case YAFFS_OBJECT_TYPE_UNKNOWN:
+       case YAFFS_OBJECT_TYPE_HARDLINK:
+       case YAFFS_OBJECT_TYPE_SPECIAL:
+       default:
+               /* TODO? */
+               break;
+       }
 
-               yaffs_inode_to_obj_lv(inode) = obj;
-               obj->my_inode = inode;
+       inode->i_flags |= S_NOATIME;
+       inode->i_ino = obj->obj_id;
+       inode->i_mode = obj->yst_mode;
+       inode->i_uid = obj->yst_uid;
+       inode->i_gid = obj->yst_gid;
 
-       } else {
-               yaffs_trace(YAFFS_TRACE_OS,
-                       "yaffs_fill_inode invalid parameters");
+       inode->i_rdev = old_decode_dev(obj->yst_rdev);
+
+       inode->i_atime.tv_sec = (time_t) (obj->yst_atime);
+       inode->i_atime.tv_nsec = 0;
+       inode->i_mtime.tv_sec = (time_t) obj->yst_mtime;
+       inode->i_mtime.tv_nsec = 0;
+       inode->i_ctime.tv_sec = (time_t) obj->yst_ctime;
+       inode->i_ctime.tv_nsec = 0;
+       inode->i_size = yaffs_get_obj_length(obj);
+       inode->i_blocks = (inode->i_size + 511) >> 9;
+       inode->i_nlink = yaffs_get_obj_link_count(obj);
+       yaffs_trace(YAFFS_TRACE_OS,
+               "yaffs_fill_inode mode %x uid %d gid %d size %d count %d",
+               inode->i_mode, inode->i_uid, inode->i_gid,
+               (int)inode->i_size, atomic_read(&inode->i_count));
+
+       switch (obj->yst_mode & S_IFMT) {
+       default:        /* fifo, device or socket */
+               init_special_inode(inode, obj->yst_mode,
+                                  old_decode_dev(obj->yst_rdev));
+               break;
+       case S_IFREG:   /* file */
+               inode->i_op = &yaffs_file_inode_operations;
+               inode->i_fop = &yaffs_file_operations;
+               inode->i_mapping->a_ops = &yaffs_file_address_operations;
+               break;
+       case S_IFDIR:   /* directory */
+               inode->i_op = &yaffs_dir_inode_operations;
+               inode->i_fop = &yaffs_dir_operations;
+               break;
+       case S_IFLNK:   /* symlink */
+               inode->i_op = &yaffs_symlink_inode_operations;
+               break;
        }
+
+       yaffs_inode_to_obj_lv(inode) = obj;
+       obj->my_inode = inode;
 }
 
 static void yaffs_put_super(struct super_block *sb)
@@ -2020,10 +1998,9 @@ static struct super_block *yaffs_internal_read_super(int yaffs_version,
 
        memset(&options, 0, sizeof(options));
 
-       if (yaffs_parse_options(&options, data_str)) {
+       if (yaffs_parse_options(&options, data_str))
                /* Option parsing failed */
                return NULL;
-       }
 
        sb->s_blocksize = PAGE_CACHE_SIZE;
        sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
@@ -2261,8 +2238,7 @@ static struct super_block *yaffs_internal_read_super(int yaffs_version,
 
        mutex_lock(&yaffs_context_lock);
        /* Get a mount id */
-       found = 0;
-       for (mount_id = 0; !found; mount_id++) {
+       for (mount_id = 0, found = 0; !found; mount_id++) {
                found = 1;
                list_for_each(l, &yaffs_context_list) {
                        context_iterator =
index 6ee91a139e1ae508acec7fc26a091d740fdeefb0..a70c1422e1cbc844dbf8b9338060e4ed2f10412e 100644 (file)
@@ -28,7 +28,7 @@ int yaffs1_scan(struct yaffs_dev *dev)
        int c;
        int deleted;
        enum yaffs_block_state state;
-       struct yaffs_obj *hard_list = NULL;
+       LIST_HEAD(hard_list);
        struct yaffs_block_info *bi;
        u32 seq_number;
        struct yaffs_obj_hdr *oh;
@@ -89,8 +89,9 @@ int yaffs1_scan(struct yaffs_dev *dev)
                deleted = 0;
 
                /* For each chunk in each block that needs scanning.... */
-               for (c = 0; !alloc_failed && c < dev->param.chunks_per_block &&
-                    state == YAFFS_BLOCK_STATE_NEEDS_SCANNING; c++) {
+               for (c = 0;
+                       !alloc_failed && c < dev->param.chunks_per_block &&
+                       state == YAFFS_BLOCK_STATE_NEEDS_SCAN; c++) {
                        /* Read the tags and decide what to do */
                        chunk = blk * dev->param.chunks_per_block + c;
 
@@ -99,8 +100,8 @@ int yaffs1_scan(struct yaffs_dev *dev)
 
                        /* Let's have a good look at this chunk... */
 
-                       if (tags.ecc_result == YAFFS_ECC_RESULT_UNFIXED
-                           || tags.is_deleted) {
+                       if (tags.ecc_result == YAFFS_ECC_RESULT_UNFIXED ||
+                           tags.is_deleted) {
                                /* YAFFS1 only...
                                 * A deleted chunk
                                 */
@@ -160,9 +161,9 @@ int yaffs1_scan(struct yaffs_dev *dev)
                                    tags.n_bytes;
                                if (in &&
                                    in->variant_type ==
-                                   YAFFS_OBJECT_TYPE_FILE &&
+                                    YAFFS_OBJECT_TYPE_FILE &&
                                    in->variant.file_variant.scanned_size <
-                                   endpos) {
+                                     endpos) {
                                        in->variant.file_variant.scanned_size =
                                            endpos;
                                        if (!dev->param.use_header_file_size) {
@@ -332,10 +333,8 @@ int yaffs1_scan(struct yaffs_dev *dev)
                                                in->variant.
                                                    hardlink_variant.equiv_id =
                                                    oh->equiv_id;
-                                               in->hard_links.next =
-                                                   (struct list_head *)
-                                                   hard_list;
-                                               hard_list = in;
+                                               list_add(&in->hard_links,
+                                                               &hard_list);
                                                break;
                                        case YAFFS_OBJECT_TYPE_DIRECTORY:
                                                /* Do nothing */
@@ -356,7 +355,7 @@ int yaffs1_scan(struct yaffs_dev *dev)
                        }
                }
 
-               if (state == YAFFS_BLOCK_STATE_NEEDS_SCANNING) {
+               if (state == YAFFS_BLOCK_STATE_NEEDS_SCAN) {
                        /* If we got this far while scanning,
                         * then the block is fully allocated. */
                        state = YAFFS_BLOCK_STATE_FULL;
@@ -374,9 +373,8 @@ int yaffs1_scan(struct yaffs_dev *dev)
                /* Now let's see if it was dirty */
                if (bi->pages_in_use == 0 &&
                    !bi->has_shrink_hdr &&
-                   bi->block_state == YAFFS_BLOCK_STATE_FULL) {
+                   bi->block_state == YAFFS_BLOCK_STATE_FULL)
                        yaffs_block_became_dirty(dev, blk);
-               }
        }
 
        /* Ok, we've done all the scanning.
@@ -385,9 +383,12 @@ int yaffs1_scan(struct yaffs_dev *dev)
         * these hardlinks.
         */
 
-       yaffs_link_fixup(dev, hard_list);
+       yaffs_link_fixup(dev, &hard_list);
 
-       /* Fix up any shadowed objects */
+       /*
+        * Fix up any shadowed objects.
+        * There should not be more than one of these.
+        */
        {
                struct yaffs_shadow_fixer *fixer;
                struct yaffs_obj *obj;
index 77101e72e1bdda16913bc4ba3ac4e34f49251667..32840e76566803c2b50cd2d955252597d8624edd 100644 (file)
@@ -54,7 +54,8 @@ void yaffs_calc_oldest_dirty_seq(struct yaffs_dev *dev)
        for (i = dev->internal_start_block; i <= dev->internal_end_block; i++) {
                if (b->block_state == YAFFS_BLOCK_STATE_FULL &&
                    (b->pages_in_use - b->soft_del_pages) <
-                   dev->param.chunks_per_block && b->seq_number < seq) {
+                   dev->param.chunks_per_block &&
+                   b->seq_number < seq) {
                        seq = b->seq_number;
                        block_no = i;
                }
@@ -206,17 +207,16 @@ int yaffs2_checkpt_required(struct yaffs_dev *dev)
 int yaffs_calc_checkpt_blocks_required(struct yaffs_dev *dev)
 {
        int retval;
+       int n_bytes = 0;
+       int n_blocks;
+       int dev_blocks;
 
        if (!dev->param.is_yaffs2)
                return 0;
 
        if (!dev->checkpoint_blocks_required && yaffs2_checkpt_required(dev)) {
                /* Not a valid value so recalculate */
-               int n_bytes = 0;
-               int n_blocks;
-               int dev_blocks =
-                   (dev->param.end_block - dev->param.start_block + 1);
-
+               dev_blocks = dev->param.end_block - dev->param.start_block + 1;
                n_bytes += sizeof(struct yaffs_checkpt_validity);
                n_bytes += sizeof(struct yaffs_checkpt_dev);
                n_bytes += dev_blocks * sizeof(struct yaffs_block_info);
@@ -309,8 +309,7 @@ static int yaffs2_wr_checkpt_dev(struct yaffs_dev *dev)
 {
        struct yaffs_checkpt_dev cp;
        u32 n_bytes;
-       u32 n_blocks =
-           (dev->internal_end_block - dev->internal_start_block + 1);
+       u32 n_blocks = dev->internal_end_block - dev->internal_start_block + 1;
        int ok;
 
        /* Write device runtime values */
@@ -318,20 +317,19 @@ static int yaffs2_wr_checkpt_dev(struct yaffs_dev *dev)
        cp.struct_type = sizeof(cp);
 
        ok = (yaffs2_checkpt_wr(dev, &cp, sizeof(cp)) == sizeof(cp));
+       if (!ok)
+               return 0;
 
        /* Write block info */
-       if (ok) {
-               n_bytes = n_blocks * sizeof(struct yaffs_block_info);
-               ok = (yaffs2_checkpt_wr(dev, dev->block_info, n_bytes) ==
-                     n_bytes);
-       }
+       n_bytes = n_blocks * sizeof(struct yaffs_block_info);
+       ok = (yaffs2_checkpt_wr(dev, dev->block_info, n_bytes) == n_bytes);
+       if (!ok)
+               return 0;
 
        /* Write chunk bits */
-       if (ok) {
-               n_bytes = n_blocks * dev->chunk_bit_stride;
-               ok = (yaffs2_checkpt_wr(dev, dev->chunk_bits, n_bytes) ==
-                     n_bytes);
-       }
+       n_bytes = n_blocks * dev->chunk_bit_stride;
+       ok = (yaffs2_checkpt_wr(dev, dev->chunk_bits, n_bytes) == n_bytes);
+
        return ok ? 1 : 0;
 }
 
@@ -358,6 +356,7 @@ static int yaffs2_rd_checkpt_dev(struct yaffs_dev *dev)
 
        if (!ok)
                return 0;
+
        n_bytes = n_blocks * dev->chunk_bit_stride;
 
        ok = (yaffs2_checkpt_rd(dev, dev->chunk_bits, n_bytes) == n_bytes);
@@ -387,7 +386,7 @@ static void yaffs2_obj_checkpt_obj(struct yaffs_checkpt_obj *cp,
                cp->size_or_equiv_obj = obj->variant.hardlink_variant.equiv_id;
 }
 
-static int taffs2_checkpt_obj_to_obj(struct yaffs_obj *obj,
+static int yaffs2_checkpt_obj_to_obj(struct yaffs_obj *obj,
                                     struct yaffs_checkpt_obj *cp)
 {
        struct yaffs_obj *parent;
@@ -449,33 +448,32 @@ static int yaffs2_checkpt_tnode_worker(struct yaffs_obj *in,
        int i;
        struct yaffs_dev *dev = in->my_dev;
        int ok = 1;
-
-       if (tn) {
-               if (level > 0) {
-
-                       for (i = 0; i < YAFFS_NTNODES_INTERNAL && ok; i++) {
-                               if (tn->internal[i]) {
-                                       ok = yaffs2_checkpt_tnode_worker(in,
-                                                tn->internal[i],
-                                                level - 1,
-                                                (chunk_offset <<
-                                                 YAFFS_TNODES_INTERNAL_BITS)
-                                                + i);
-                               }
-                       }
-               } else if (level == 0) {
-                       u32 base_offset =
-                           chunk_offset << YAFFS_TNODES_LEVEL0_BITS;
-                       ok = (yaffs2_checkpt_wr
-                             (dev, &base_offset,
-                              sizeof(base_offset)) == sizeof(base_offset));
-                       if (ok)
-                               ok = (yaffs2_checkpt_wr
-                                     (dev, tn,
-                                      dev->tnode_size) == dev->tnode_size);
+       u32 base_offset;
+
+       if (!tn)
+               return 1;
+
+       if (level > 0) {
+               for (i = 0; i < YAFFS_NTNODES_INTERNAL && ok; i++) {
+                       if (!tn->internal[i])
+                               continue;
+                       ok = yaffs2_checkpt_tnode_worker(in,
+                                tn->internal[i],
+                                level - 1,
+                                (chunk_offset <<
+                                 YAFFS_TNODES_INTERNAL_BITS) + i);
                }
+               return ok;
        }
 
+       /* Level 0 tnode */
+       base_offset = chunk_offset << YAFFS_TNODES_LEVEL0_BITS;
+       ok = (yaffs2_checkpt_wr(dev, &base_offset, sizeof(base_offset)) ==
+                       sizeof(base_offset));
+       if (ok)
+               ok = (yaffs2_checkpt_wr(dev, tn, dev->tnode_size) ==
+                       dev->tnode_size);
+
        return ok;
 }
 
@@ -484,16 +482,16 @@ static int yaffs2_wr_checkpt_tnodes(struct yaffs_obj *obj)
        u32 end_marker = ~0;
        int ok = 1;
 
-       if (obj->variant_type == YAFFS_OBJECT_TYPE_FILE) {
-               ok = yaffs2_checkpt_tnode_worker(obj,
-                                                obj->variant.file_variant.top,
-                                                obj->variant.file_variant.
-                                                top_level, 0);
-               if (ok)
-                       ok = (yaffs2_checkpt_wr
-                             (obj->my_dev, &end_marker,
-                              sizeof(end_marker)) == sizeof(end_marker));
-       }
+       if (obj->variant_type != YAFFS_OBJECT_TYPE_FILE)
+               return ok;
+
+       ok = yaffs2_checkpt_tnode_worker(obj,
+                                        obj->variant.file_variant.top,
+                                        obj->variant.file_variant.
+                                        top_level, 0);
+       if (ok)
+               ok = (yaffs2_checkpt_wr(obj->my_dev, &end_marker,
+                               sizeof(end_marker)) == sizeof(end_marker));
 
        return ok ? 1 : 0;
 }
@@ -590,7 +588,8 @@ static int yaffs2_rd_checkpt_objs(struct yaffs_dev *dev)
        struct yaffs_checkpt_obj cp;
        int ok = 1;
        int done = 0;
-       struct yaffs_obj *hard_list = NULL;
+       LIST_HEAD(hard_list);
+
 
        while (ok && !done) {
                ok = (yaffs2_checkpt_rd(dev, &cp, sizeof(cp)) == sizeof(cp));
@@ -613,7 +612,7 @@ static int yaffs2_rd_checkpt_objs(struct yaffs_dev *dev)
                            yaffs_find_or_create_by_number(dev, cp.obj_id,
                                                           cp.variant_type);
                        if (obj) {
-                               ok = taffs2_checkpt_obj_to_obj(obj, &cp);
+                               ok = yaffs2_checkpt_obj_to_obj(obj, &cp);
                                if (!ok)
                                        break;
                                if (obj->variant_type ==
@@ -621,9 +620,7 @@ static int yaffs2_rd_checkpt_objs(struct yaffs_dev *dev)
                                        ok = yaffs2_rd_checkpt_tnodes(obj);
                                } else if (obj->variant_type ==
                                        YAFFS_OBJECT_TYPE_HARDLINK) {
-                                       obj->hard_links.next =
-                                           (struct list_head *)hard_list;
-                                       hard_list = obj;
+                                       list_add(&obj->hard_links, &hard_list);
                                }
                        } else {
                                ok = 0;
@@ -632,7 +629,7 @@ static int yaffs2_rd_checkpt_objs(struct yaffs_dev *dev)
        }
 
        if (ok)
-               yaffs_link_fixup(dev, hard_list);
+               yaffs_link_fixup(dev, &hard_list);
 
        return ok ? 1 : 0;
 }
@@ -928,8 +925,8 @@ static int yaffs2_ybicmp(const void *a, const void *b)
 
        if (aseq == bseq)
                return ablock - bblock;
-       else
-               return aseq - bseq;
+
+       return aseq - bseq;
 }
 
 static inline int yaffs2_scan_chunk(struct yaffs_dev *dev,
@@ -937,7 +934,7 @@ static inline int yaffs2_scan_chunk(struct yaffs_dev *dev,
                int blk, int chunk_in_block,
                int *found_chunks,
                u8 *chunk_data,
-               struct yaffs_obj **hard_list)
+               struct list_head *hard_list)
 {
        struct yaffs_obj_hdr *oh;
        struct yaffs_obj *in;
@@ -979,8 +976,8 @@ static inline int yaffs2_scan_chunk(struct yaffs_dev *dev,
                        bi->block_state = YAFFS_BLOCK_STATE_EMPTY;
                        dev->n_erased_blocks++;
                } else {
-                       if (bi->block_state == YAFFS_BLOCK_STATE_NEEDS_SCANNING
-                          || bi->block_state == YAFFS_BLOCK_STATE_ALLOCATING) {
+                       if (bi->block_state == YAFFS_BLOCK_STATE_NEEDS_SCAN ||
+                           bi->block_state == YAFFS_BLOCK_STATE_ALLOCATING) {
                                if (dev->seq_number == bi->seq_number) {
                                        /* Allocating from this block*/
                                        yaffs_trace(YAFFS_TRACE_SCAN,
@@ -1092,12 +1089,10 @@ static inline int yaffs2_scan_chunk(struct yaffs_dev *dev,
                }
 
                if (!in ||
-                   (!in->valid && dev->param.disable_lazy_load)
-                   || tags.extra_shadows ||
-                   (!in->valid && (tags.obj_id ==
-                               YAFFS_OBJECTID_ROOT
-                               || tags.obj_id ==
-                               YAFFS_OBJECTID_LOSTNFOUND))) {
+                   (!in->valid && dev->param.disable_lazy_load) ||
+                   tags.extra_shadows ||
+                   (!in->valid && (tags.obj_id == YAFFS_OBJECTID_ROOT ||
+                                tags.obj_id == YAFFS_OBJECTID_LOSTNFOUND))) {
 
                        /* If we don't have  valid info then we
                         * need to read the chunk
@@ -1308,9 +1303,7 @@ static inline int yaffs2_scan_chunk(struct yaffs_dev *dev,
                                hl_var = &in->variant.hardlink_variant;
                                if (!is_unlinked) {
                                        hl_var->equiv_id = equiv_id;
-                                       in->hard_links.next =
-                                           (struct list_head *) *hard_list;
-                                       *hard_list = in;
+                                       list_add(&in->hard_links, hard_list);
                                }
                                break;
                        case YAFFS_OBJECT_TYPE_DIRECTORY:
@@ -1344,7 +1337,7 @@ int yaffs2_scan_backwards(struct yaffs_dev *dev)
        enum yaffs_block_state state;
        int c;
        int deleted;
-       struct yaffs_obj *hard_list = NULL;
+       LIST_HEAD(hard_list);
        struct yaffs_block_info *bi;
        u32 seq_number;
        int n_blocks = dev->internal_end_block - dev->internal_start_block + 1;
@@ -1360,8 +1353,8 @@ int yaffs2_scan_backwards(struct yaffs_dev *dev)
 
        dev->seq_number = YAFFS_LOWEST_SEQUENCE_NUMBER;
 
-       block_index = kmalloc(n_blocks * sizeof(struct yaffs_block_index),
-                       GFP_NOFS);
+       block_index =
+               kmalloc(n_blocks * sizeof(struct yaffs_block_index), GFP_NOFS);
 
        if (!block_index) {
                block_index =
@@ -1413,7 +1406,7 @@ int yaffs2_scan_backwards(struct yaffs_dev *dev)
                        dev->n_erased_blocks++;
                        dev->n_free_chunks += dev->param.chunks_per_block;
                } else if (bi->block_state ==
-                               YAFFS_BLOCK_STATE_NEEDS_SCANNING) {
+                               YAFFS_BLOCK_STATE_NEEDS_SCAN) {
                        /* Determine the highest sequence number */
                        if (seq_number >= YAFFS_LOWEST_SEQUENCE_NUMBER &&
                            seq_number < YAFFS_HIGHEST_SEQUENCE_NUMBER) {
@@ -1450,7 +1443,8 @@ int yaffs2_scan_backwards(struct yaffs_dev *dev)
        yaffs_trace(YAFFS_TRACE_SCAN_DEBUG, "%d blocks to scan", n_to_scan);
 
        /* For each block.... backwards */
-       for (block_iter = end_iter; !alloc_failed && block_iter >= start_iter;
+       for (block_iter = end_iter;
+            !alloc_failed && block_iter >= start_iter;
             block_iter--) {
                /* Cooperative multitasking! This loop can run for so
                   long that watchdog timers expire. */
@@ -1465,19 +1459,18 @@ int yaffs2_scan_backwards(struct yaffs_dev *dev)
                found_chunks = 0;
                for (c = dev->param.chunks_per_block - 1;
                     !alloc_failed && c >= 0 &&
-                    (bi->block_state == YAFFS_BLOCK_STATE_NEEDS_SCANNING ||
+                    (bi->block_state == YAFFS_BLOCK_STATE_NEEDS_SCAN ||
                      bi->block_state == YAFFS_BLOCK_STATE_ALLOCATING); c--) {
                        /* Scan backwards...
                         * Read the tags and decide what to do
                         */
                        if (yaffs2_scan_chunk(dev, bi, blk, c,
                                        &found_chunks, chunk_data,
-                                       &hard_list) ==
-                               YAFFS_FAIL)
+                                       &hard_list) == YAFFS_FAIL)
                                alloc_failed = 1;
                }
 
-               if (bi->block_state == YAFFS_BLOCK_STATE_NEEDS_SCANNING) {
+               if (bi->block_state == YAFFS_BLOCK_STATE_NEEDS_SCAN) {
                        /* If we got this far while scanning, then the block
                         * is fully allocated. */
                        bi->block_state = YAFFS_BLOCK_STATE_FULL;
@@ -1503,7 +1496,7 @@ int yaffs2_scan_backwards(struct yaffs_dev *dev)
         * We have scanned all the objects, now it's time to add these
         * hardlinks.
         */
-       yaffs_link_fixup(dev, hard_list);
+       yaffs_link_fixup(dev, &hard_list);
 
        yaffs_release_temp_buffer(dev, chunk_data, __LINE__);