nommu: ramfs: don't leak pages when adding to page cache fails
[safe/jmp/linux-2.6] / fs / udf / balloc.c
index 9892596..1b809bd 100644 (file)
@@ -145,12 +145,11 @@ static bool udf_add_free_space(struct udf_sb_info *sbi,
 {
        struct logicalVolIntegrityDesc *lvid;
 
-       if (sbi->s_lvid_bh)
+       if (sbi->s_lvid_bh == NULL)
                return false;
 
        lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data;
-       lvid->freeSpaceTable[partition] = cpu_to_le32(le32_to_cpu(
-                                       lvid->freeSpaceTable[partition]) + cnt);
+       le32_add_cpu(&lvid->freeSpaceTable[partition], cnt);
        return true;
 }
 
@@ -436,6 +435,7 @@ static void udf_table_free_blocks(struct super_block *sb,
        struct extent_position oepos, epos;
        int8_t etype;
        int i;
+       struct udf_inode_info *iinfo;
 
        mutex_lock(&sbi->s_alloc_mutex);
        if (bloc.logicalBlockNum < 0 ||
@@ -448,6 +448,7 @@ static void udf_table_free_blocks(struct super_block *sb,
                goto error_return;
        }
 
+       iinfo = UDF_I(table);
        /* We do this up front - There are some error conditions that
           could occure, but.. oh well */
        if (inode)
@@ -460,7 +461,7 @@ static void udf_table_free_blocks(struct super_block *sb,
 
        epos.offset = oepos.offset = sizeof(struct unallocSpaceEntry);
        elen = 0;
-       epos.block = oepos.block = UDF_I_LOCATION(table);
+       epos.block = oepos.block = iinfo->i_location;
        epos.bh = oepos.bh = NULL;
 
        while (count &&
@@ -539,11 +540,11 @@ static void udf_table_free_blocks(struct super_block *sb,
                elen = EXT_RECORDED_ALLOCATED |
                        (count << sb->s_blocksize_bits);
 
-               if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT) {
+               if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                        adsize = sizeof(short_ad);
-               } else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG) {
+               else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                        adsize = sizeof(long_ad);
-               else {
+               else {
                        brelse(oepos.bh);
                        brelse(epos.bh);
                        goto error_return;
@@ -573,7 +574,8 @@ static void udf_table_free_blocks(struct super_block *sb,
                        if (epos.offset + adsize > sb->s_blocksize) {
                                loffset = epos.offset;
                                aed->lengthAllocDescs = cpu_to_le32(adsize);
-                               sptr = UDF_I_DATA(table) + epos.offset - adsize;
+                               sptr = iinfo->i_ext.i_data + epos.offset
+                                                               - adsize;
                                dptr = epos.bh->b_data +
                                        sizeof(struct allocExtDesc);
                                memcpy(dptr, sptr, adsize);
@@ -586,13 +588,12 @@ static void udf_table_free_blocks(struct super_block *sb,
                                        sptr = oepos.bh->b_data + epos.offset;
                                        aed = (struct allocExtDesc *)
                                                oepos.bh->b_data;
-                                       aed->lengthAllocDescs =
-                                               cpu_to_le32(le32_to_cpu(
-                                                       aed->lengthAllocDescs) +
-                                                               adsize);
+                                       le32_add_cpu(&aed->lengthAllocDescs,
+                                                       adsize);
                                } else {
-                                       sptr = UDF_I_DATA(table) + epos.offset;
-                                       UDF_I_LENALLOC(table) += adsize;
+                                       sptr = iinfo->i_ext.i_data +
+                                                               epos.offset;
+                                       iinfo->i_lenAlloc += adsize;
                                        mark_inode_dirty(table);
                                }
                                epos.offset = sizeof(struct allocExtDesc);
@@ -606,7 +607,7 @@ static void udf_table_free_blocks(struct super_block *sb,
                                            2, 1, epos.block.logicalBlockNum,
                                            sizeof(tag));
 
-                       switch (UDF_I_ALLOCTYPE(table)) {
+                       switch (iinfo->i_alloc_type) {
                        case ICBTAG_FLAG_AD_SHORT:
                                sad = (short_ad *)sptr;
                                sad->extLength = cpu_to_le32(
@@ -637,13 +638,11 @@ static void udf_table_free_blocks(struct super_block *sb,
                        udf_write_aext(table, &epos, eloc, elen, 1);
 
                        if (!epos.bh) {
-                               UDF_I_LENALLOC(table) += adsize;
+                               iinfo->i_lenAlloc += adsize;
                                mark_inode_dirty(table);
                        } else {
                                aed = (struct allocExtDesc *)epos.bh->b_data;
-                               aed->lengthAllocDescs =
-                                       cpu_to_le32(le32_to_cpu(
-                                           aed->lengthAllocDescs) + adsize);
+                               le32_add_cpu(&aed->lengthAllocDescs, adsize);
                                udf_update_tag(epos.bh->b_data, epos.offset);
                                mark_buffer_dirty(epos.bh);
                        }
@@ -670,21 +669,23 @@ static int udf_table_prealloc_blocks(struct super_block *sb,
        kernel_lb_addr eloc;
        struct extent_position epos;
        int8_t etype = -1;
+       struct udf_inode_info *iinfo;
 
        if (first_block < 0 ||
                first_block >= sbi->s_partmaps[partition].s_partition_len)
                return 0;
 
-       if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT)
+       iinfo = UDF_I(table);
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                adsize = sizeof(short_ad);
-       else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG)
+       else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                adsize = sizeof(long_ad);
        else
                return 0;
 
        mutex_lock(&sbi->s_alloc_mutex);
        epos.offset = sizeof(struct unallocSpaceEntry);
-       epos.block = UDF_I_LOCATION(table);
+       epos.block = iinfo->i_location;
        epos.bh = NULL;
        eloc.logicalBlockNum = 0xFFFFFFFF;
 
@@ -737,12 +738,13 @@ static int udf_table_new_block(struct super_block *sb,
        kernel_lb_addr eloc, uninitialized_var(goal_eloc);
        struct extent_position epos, goal_epos;
        int8_t etype;
+       struct udf_inode_info *iinfo = UDF_I(table);
 
        *err = -ENOSPC;
 
-       if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT)
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                adsize = sizeof(short_ad);
-       else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG)
+       else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                adsize = sizeof(long_ad);
        else
                return newblock;
@@ -757,7 +759,7 @@ static int udf_table_new_block(struct super_block *sb,
           of the current closest match and use that when we are done.
         */
        epos.offset = sizeof(struct unallocSpaceEntry);
-       epos.block = UDF_I_LOCATION(table);
+       epos.block = iinfo->i_location;
        epos.bh = goal_epos.bh = NULL;
 
        while (spread &&