yaffsfs.c: Fix NULL dereference in yaffs_unmount2_reldev()
[yaffs2.git] / yaffs_yaffs2.c
index 6d4681726a60b3ae63adc3456661a8652790194a..6be3d6a0c6208f082e0fd1a4a22845c97ba118c2 100644 (file)
@@ -1,8 +1,7 @@
 /*
  * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
  *
- * Copyright (C) 2002-2011 Aleph One Ltd.
- *   for Toby Churchill Ltd and Brightstar Engineering
+ * Copyright (C) 2002-2018 Aleph One Ltd.
  *
  * Created by Charles Manning <charles@aleph1.co.uk>
  *
@@ -42,7 +41,7 @@
  */
 void yaffs_calc_oldest_dirty_seq(struct yaffs_dev *dev)
 {
-       int i;
+       u32 i;
        unsigned seq;
        unsigned block_no = 0;
        struct yaffs_block_info *b;
@@ -55,7 +54,7 @@ void yaffs_calc_oldest_dirty_seq(struct yaffs_dev *dev)
        b = dev->block_info;
        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) <
+                   (u32)(b->pages_in_use - b->soft_del_pages) <
                    dev->param.chunks_per_block &&
                    b->seq_number < seq) {
                        seq = b->seq_number;
@@ -345,7 +344,7 @@ static int yaffs2_wr_checkpt_dev(struct yaffs_dev *dev)
        u32 n_bytes;
        u32 n_blocks = dev->internal_end_block - dev->internal_start_block + 1;
        int ok;
-       int i;
+       u32 i;
        union yaffs_block_info_union bu;
 
        /* Write device runtime values */
@@ -359,7 +358,8 @@ static int yaffs2_wr_checkpt_dev(struct yaffs_dev *dev)
        /* Write block info. */
        if (!dev->swap_endian) {
                n_bytes = n_blocks * sizeof(struct yaffs_block_info);
-               ok = (yaffs2_checkpt_wr(dev, dev->block_info, n_bytes) == n_bytes);
+               ok = (yaffs2_checkpt_wr(dev, dev->block_info, n_bytes) ==
+                       (int)n_bytes);
        } else {
                /*
                 * Need to swap the endianisms. We can't do this in place
@@ -382,7 +382,8 @@ static int yaffs2_wr_checkpt_dev(struct yaffs_dev *dev)
         * no endian conversion is needed.
         */
        n_bytes = n_blocks * dev->chunk_bit_stride;
-       ok = (yaffs2_checkpt_wr(dev, dev->chunk_bits, n_bytes) == n_bytes);
+       ok = (yaffs2_checkpt_wr(dev, dev->chunk_bits, n_bytes) ==
+               (int)n_bytes);
 
        return ok ? 1 : 0;
 }
@@ -407,7 +408,8 @@ static int yaffs2_rd_checkpt_dev(struct yaffs_dev *dev)
 
        n_bytes = n_blocks * sizeof(struct yaffs_block_info);
 
-       ok = (yaffs2_checkpt_rd(dev, dev->block_info, n_bytes) == n_bytes);
+       ok = (yaffs2_checkpt_rd(dev, dev->block_info, n_bytes) ==
+               (int)n_bytes);
 
        if (!ok)
                return 0;
@@ -424,7 +426,8 @@ static int yaffs2_rd_checkpt_dev(struct yaffs_dev *dev)
 
        n_bytes = n_blocks * dev->chunk_bit_stride;
 
-       ok = (yaffs2_checkpt_rd(dev, dev->chunk_bits, n_bytes) == n_bytes);
+       ok = (yaffs2_checkpt_rd(dev, dev->chunk_bits, n_bytes) ==
+               (int)n_bytes);
 
 
        return ok ? 1 : 0;
@@ -604,7 +607,7 @@ static int yaffs2_checkpt_tnode_worker(struct yaffs_obj *in,
                 */
                tn = yaffs2_do_endian_tnode_copy(dev, tn);
                ok = (yaffs2_checkpt_wr(dev, tn, dev->tnode_size) ==
-                       dev->tnode_size);
+                       (int)dev->tnode_size);
        }
        return ok;
 }
@@ -649,7 +652,7 @@ static int yaffs2_rd_checkpt_tnodes(struct yaffs_obj *obj)
                tn = yaffs_get_tnode(dev);
                if (tn) {
                        ok = (yaffs2_checkpt_rd(dev, tn, dev->tnode_size) ==
-                               dev->tnode_size);
+                               (int)dev->tnode_size);
                        yaffs2_do_endian_tnode(dev, tn);
                }
                else
@@ -704,6 +707,8 @@ static int yaffs2_wr_checkpt_objs(struct yaffs_dev *dev)
         * dumping them to the checkpointing stream.
         */
 
+       (void) cp_variant_type;
+
        for (i = 0; ok && i < YAFFS_NOBJECT_BUCKETS; i++) {
                list_for_each(lh, &dev->obj_bucket[i].list) {
                        obj = list_entry(lh, struct yaffs_obj, hash_link);
@@ -768,7 +773,7 @@ static int yaffs2_rd_checkpt_objs(struct yaffs_dev *dev)
                        cp.obj_id, cp.parent_id, cp_variant_type,
                        cp.hdr_chunk);
 
-               if (ok && cp.obj_id == ~0) {
+               if (ok && cp.obj_id == (u32)(~0)) {
                        done = 1;
                } else if (ok) {
                        obj =
@@ -1050,7 +1055,7 @@ int yaffs2_handle_hole(struct yaffs_obj *obj, loff_t new_size)
 
                while (increase > 0 && small_increase_ok) {
                        this_write = increase;
-                       if (this_write > dev->data_bytes_per_chunk)
+                       if (this_write > (int)dev->data_bytes_per_chunk)
                                this_write = dev->data_bytes_per_chunk;
                        written =
                            yaffs_do_file_wr(obj, local_buffer, pos, this_write,
@@ -1136,6 +1141,9 @@ static inline int yaffs2_scan_chunk(struct yaffs_dev *dev,
                dev->summary_used++;
        }
 
+       if (result == YAFFS_FAIL)
+               yaffs_trace(YAFFS_TRACE_SCAN,
+                               "Could not get tags for chunk %d\n", chunk);
        /* Let's have a good look at this chunk... */
 
        if (!tags.chunk_used) {
@@ -1334,7 +1342,7 @@ static inline int yaffs2_scan_chunk(struct yaffs_dev *dev,
                                        yaffs_oh_to_size(dev, oh, 0) :
                                        tags.extra_file_size;
                                u32 parent_obj_id = (oh) ?
-                                       oh->parent_obj_id :
+                                       (u32)oh->parent_obj_id :
                                        tags.extra_parent_id;
 
                                is_shrink = (oh) ?
@@ -1517,7 +1525,7 @@ static inline int yaffs2_scan_chunk(struct yaffs_dev *dev,
 
 int yaffs2_scan_backwards(struct yaffs_dev *dev)
 {
-       int blk;
+       u32 blk;
        int block_iter;
        int start_iter;
        int end_iter;