Skip to content

Commit

Permalink
Fix the udf code not to pass structs on stack where possible.
Browse files Browse the repository at this point in the history
Signed-off-by: Pekka Enberg <[email protected]>
Signed-off-by: Jan Kara <[email protected]>
  • Loading branch information
Pekka Enberg authored and jankara committed Apr 2, 2009
1 parent 5ca4e4b commit 97e961f
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 116 deletions.
59 changes: 31 additions & 28 deletions fs/udf/balloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static int read_block_bitmap(struct super_block *sb,
loc.logicalBlockNum = bitmap->s_extPosition;
loc.partitionReferenceNum = UDF_SB(sb)->s_partition;

bh = udf_tread(sb, udf_get_lb_pblock(sb, loc, block));
bh = udf_tread(sb, udf_get_lb_pblock(sb, &loc, block));
if (!bh)
retval = -EIO;

Expand Down Expand Up @@ -156,11 +156,13 @@ static bool udf_add_free_space(struct udf_sb_info *sbi,
static void udf_bitmap_free_blocks(struct super_block *sb,
struct inode *inode,
struct udf_bitmap *bitmap,
struct kernel_lb_addr bloc, uint32_t offset,
struct kernel_lb_addr *bloc,
uint32_t offset,
uint32_t count)
{
struct udf_sb_info *sbi = UDF_SB(sb);
struct buffer_head *bh = NULL;
struct udf_part_map *partmap;
unsigned long block;
unsigned long block_group;
unsigned long bit;
Expand All @@ -169,17 +171,17 @@ static void udf_bitmap_free_blocks(struct super_block *sb,
unsigned long overflow;

mutex_lock(&sbi->s_alloc_mutex);
if (bloc.logicalBlockNum < 0 ||
(bloc.logicalBlockNum + count) >
sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
if (bloc->logicalBlockNum < 0 ||
(bloc->logicalBlockNum + count) >
partmap->s_partition_len) {
udf_debug("%d < %d || %d + %d > %d\n",
bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
sbi->s_partmaps[bloc.partitionReferenceNum].
s_partition_len);
bloc->logicalBlockNum, 0, bloc->logicalBlockNum,
count, partmap->s_partition_len);
goto error_return;
}

block = bloc.logicalBlockNum + offset +
block = bloc->logicalBlockNum + offset +
(sizeof(struct spaceBitmapDesc) << 3);

do {
Expand Down Expand Up @@ -425,10 +427,12 @@ static int udf_bitmap_new_block(struct super_block *sb,
static void udf_table_free_blocks(struct super_block *sb,
struct inode *inode,
struct inode *table,
struct kernel_lb_addr bloc, uint32_t offset,
struct kernel_lb_addr *bloc,
uint32_t offset,
uint32_t count)
{
struct udf_sb_info *sbi = UDF_SB(sb);
struct udf_part_map *partmap;
uint32_t start, end;
uint32_t elen;
struct kernel_lb_addr eloc;
Expand All @@ -438,13 +442,13 @@ static void udf_table_free_blocks(struct super_block *sb,
struct udf_inode_info *iinfo;

mutex_lock(&sbi->s_alloc_mutex);
if (bloc.logicalBlockNum < 0 ||
(bloc.logicalBlockNum + count) >
sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
if (bloc->logicalBlockNum < 0 ||
(bloc->logicalBlockNum + count) >
partmap->s_partition_len) {
udf_debug("%d < %d || %d + %d > %d\n",
bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
sbi->s_partmaps[bloc.partitionReferenceNum].
s_partition_len);
partmap->s_partition_len);
goto error_return;
}

Expand All @@ -456,8 +460,8 @@ static void udf_table_free_blocks(struct super_block *sb,
if (udf_add_free_space(sbi, sbi->s_partition, count))
mark_buffer_dirty(sbi->s_lvid_bh);

start = bloc.logicalBlockNum + offset;
end = bloc.logicalBlockNum + offset + count - 1;
start = bloc->logicalBlockNum + offset;
end = bloc->logicalBlockNum + offset + count - 1;

epos.offset = oepos.offset = sizeof(struct unallocSpaceEntry);
elen = 0;
Expand All @@ -483,7 +487,7 @@ static void udf_table_free_blocks(struct super_block *sb,
start += count;
count = 0;
}
udf_write_aext(table, &oepos, eloc, elen, 1);
udf_write_aext(table, &oepos, &eloc, elen, 1);
} else if (eloc.logicalBlockNum == (end + 1)) {
if ((0x3FFFFFFF - elen) <
(count << sb->s_blocksize_bits)) {
Expand All @@ -502,7 +506,7 @@ static void udf_table_free_blocks(struct super_block *sb,
end -= count;
count = 0;
}
udf_write_aext(table, &oepos, eloc, elen, 1);
udf_write_aext(table, &oepos, &eloc, elen, 1);
}

if (epos.bh != oepos.bh) {
Expand Down Expand Up @@ -563,7 +567,7 @@ static void udf_table_free_blocks(struct super_block *sb,
elen -= sb->s_blocksize;

epos.bh = udf_tread(sb,
udf_get_lb_pblock(sb, epos.block, 0));
udf_get_lb_pblock(sb, &epos.block, 0));
if (!epos.bh) {
brelse(oepos.bh);
goto error_return;
Expand Down Expand Up @@ -635,7 +639,7 @@ static void udf_table_free_blocks(struct super_block *sb,

/* It's possible that stealing the block emptied the extent */
if (elen) {
udf_write_aext(table, &epos, eloc, elen, 1);
udf_write_aext(table, &epos, &eloc, elen, 1);

if (!epos.bh) {
iinfo->i_lenAlloc += adsize;
Expand Down Expand Up @@ -707,7 +711,7 @@ static int udf_table_prealloc_blocks(struct super_block *sb,
alloc_count = block_count;
eloc.logicalBlockNum += alloc_count;
elen -= (alloc_count << sb->s_blocksize_bits);
udf_write_aext(table, &epos, eloc,
udf_write_aext(table, &epos, &eloc,
(etype << 30) | elen, 1);
} else
udf_delete_aext(table, epos, eloc,
Expand Down Expand Up @@ -814,7 +818,7 @@ static int udf_table_new_block(struct super_block *sb,
}

if (goal_elen)
udf_write_aext(table, &goal_epos, goal_eloc, goal_elen, 1);
udf_write_aext(table, &goal_epos, &goal_eloc, goal_elen, 1);
else
udf_delete_aext(table, goal_epos, goal_eloc, goal_elen);
brelse(goal_epos.bh);
Expand All @@ -828,12 +832,11 @@ static int udf_table_new_block(struct super_block *sb,
return newblock;
}

inline void udf_free_blocks(struct super_block *sb,
struct inode *inode,
struct kernel_lb_addr bloc, uint32_t offset,
uint32_t count)
void udf_free_blocks(struct super_block *sb, struct inode *inode,
struct kernel_lb_addr *bloc, uint32_t offset,
uint32_t count)
{
uint16_t partition = bloc.partitionReferenceNum;
uint16_t partition = bloc->partitionReferenceNum;
struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];

if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) {
Expand Down
6 changes: 3 additions & 3 deletions fs/udf/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static int do_udf_readdir(struct inode *dir, struct file *filp,
ret = -ENOENT;
goto out;
}
block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
block = udf_get_lb_pblock(dir->i_sb, &eloc, offset);
if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
epos.offset -= sizeof(struct short_ad);
Expand All @@ -101,7 +101,7 @@ static int do_udf_readdir(struct inode *dir, struct file *filp,
if (i + offset > (elen >> dir->i_sb->s_blocksize_bits))
i = (elen >> dir->i_sb->s_blocksize_bits) - offset;
for (num = 0; i > 0; i--) {
block = udf_get_lb_pblock(dir->i_sb, eloc, offset + i);
block = udf_get_lb_pblock(dir->i_sb, &eloc, offset + i);
tmp = udf_tgetblk(dir->i_sb, block);
if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp))
bha[num++] = tmp;
Expand Down Expand Up @@ -163,7 +163,7 @@ static int do_udf_readdir(struct inode *dir, struct file *filp,
} else {
struct kernel_lb_addr tloc = lelb_to_cpu(cfi.icb.extLocation);

iblock = udf_get_lb_pblock(dir->i_sb, tloc, 0);
iblock = udf_get_lb_pblock(dir->i_sb, &tloc, 0);
flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
dt_type = DT_UNKNOWN;
}
Expand Down
6 changes: 3 additions & 3 deletions fs/udf/directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos,
(EXT_RECORDED_ALLOCATED >> 30))
return NULL;

block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
block = udf_get_lb_pblock(dir->i_sb, eloc, *offset);

(*offset)++;

Expand All @@ -131,7 +131,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos,
if (i + *offset > (*elen >> blocksize_bits))
i = (*elen >> blocksize_bits)-*offset;
for (num = 0; i > 0; i--) {
block = udf_get_lb_pblock(dir->i_sb, *eloc,
block = udf_get_lb_pblock(dir->i_sb, eloc,
*offset + i);
tmp = udf_tgetblk(dir->i_sb, block);
if (tmp && !buffer_uptodate(tmp) &&
Expand Down Expand Up @@ -169,7 +169,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos,
(EXT_RECORDED_ALLOCATED >> 30))
return NULL;

block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
block = udf_get_lb_pblock(dir->i_sb, eloc, *offset);

(*offset)++;

Expand Down
4 changes: 2 additions & 2 deletions fs/udf/ialloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void udf_free_inode(struct inode *inode)
}
mutex_unlock(&sbi->s_alloc_mutex);

udf_free_blocks(sb, NULL, UDF_I(inode)->i_location, 0, 1);
udf_free_blocks(sb, NULL, &UDF_I(inode)->i_location, 0, 1);
}

struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
Expand Down Expand Up @@ -138,7 +138,7 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
iinfo->i_location.logicalBlockNum = block;
iinfo->i_location.partitionReferenceNum =
dinfo->i_location.partitionReferenceNum;
inode->i_ino = udf_get_lb_pblock(sb, iinfo->i_location, 0);
inode->i_ino = udf_get_lb_pblock(sb, &iinfo->i_location, 0);
inode->i_blocks = 0;
iinfo->i_lenEAttr = 0;
iinfo->i_lenAlloc = 0;
Expand Down
Loading

0 comments on commit 97e961f

Please sign in to comment.