Commit 9695ef16 authored by Evgeniy Dushistov's avatar Evgeniy Dushistov Committed by Linus Torvalds

[PATCH] ufs: wrong type cast

There are two ugly macros in ufs code:
#define UCPI_UBH ((struct ufs_buffer_head *)ucpi)
#define USPI_UBH ((struct ufs_buffer_head *)uspi)
when uspi looks like
struct {
struct ufs_buffer_head ;
}
and USPI_UBH has some sence,
ucpi looks like
struct {
struct not_ufs_buffer_head;
}

To prevent bugs in future, this patch convert macros to inline function and
fix "ucpi" structure.
Signed-off-by: default avatarEvgeniy Dushistov <dushistov@mail.ru>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent b71034e5
This diff is collapsed.
...@@ -47,14 +47,14 @@ static void ufs_read_cylinder (struct super_block * sb, ...@@ -47,14 +47,14 @@ static void ufs_read_cylinder (struct super_block * sb,
ucpi = sbi->s_ucpi[bitmap_nr]; ucpi = sbi->s_ucpi[bitmap_nr];
ucg = (struct ufs_cylinder_group *)sbi->s_ucg[cgno]->b_data; ucg = (struct ufs_cylinder_group *)sbi->s_ucg[cgno]->b_data;
UCPI_UBH->fragment = ufs_cgcmin(cgno); UCPI_UBH(ucpi)->fragment = ufs_cgcmin(cgno);
UCPI_UBH->count = uspi->s_cgsize >> sb->s_blocksize_bits; UCPI_UBH(ucpi)->count = uspi->s_cgsize >> sb->s_blocksize_bits;
/* /*
* We have already the first fragment of cylinder group block in buffer * We have already the first fragment of cylinder group block in buffer
*/ */
UCPI_UBH->bh[0] = sbi->s_ucg[cgno]; UCPI_UBH(ucpi)->bh[0] = sbi->s_ucg[cgno];
for (i = 1; i < UCPI_UBH->count; i++) for (i = 1; i < UCPI_UBH(ucpi)->count; i++)
if (!(UCPI_UBH->bh[i] = sb_bread(sb, UCPI_UBH->fragment + i))) if (!(UCPI_UBH(ucpi)->bh[i] = sb_bread(sb, UCPI_UBH(ucpi)->fragment + i)))
goto failed; goto failed;
sbi->s_cgno[bitmap_nr] = cgno; sbi->s_cgno[bitmap_nr] = cgno;
...@@ -103,7 +103,7 @@ void ufs_put_cylinder (struct super_block * sb, unsigned bitmap_nr) ...@@ -103,7 +103,7 @@ void ufs_put_cylinder (struct super_block * sb, unsigned bitmap_nr)
return; return;
} }
ucpi = sbi->s_ucpi[bitmap_nr]; ucpi = sbi->s_ucpi[bitmap_nr];
ucg = ubh_get_ucg(UCPI_UBH); ucg = ubh_get_ucg(UCPI_UBH(ucpi));
if (uspi->s_ncg > UFS_MAX_GROUP_LOADED && bitmap_nr >= sbi->s_cg_loaded) { if (uspi->s_ncg > UFS_MAX_GROUP_LOADED && bitmap_nr >= sbi->s_cg_loaded) {
ufs_panic (sb, "ufs_put_cylinder", "internal error"); ufs_panic (sb, "ufs_put_cylinder", "internal error");
...@@ -116,9 +116,9 @@ void ufs_put_cylinder (struct super_block * sb, unsigned bitmap_nr) ...@@ -116,9 +116,9 @@ void ufs_put_cylinder (struct super_block * sb, unsigned bitmap_nr)
ucg->cg_rotor = cpu_to_fs32(sb, ucpi->c_rotor); ucg->cg_rotor = cpu_to_fs32(sb, ucpi->c_rotor);
ucg->cg_frotor = cpu_to_fs32(sb, ucpi->c_frotor); ucg->cg_frotor = cpu_to_fs32(sb, ucpi->c_frotor);
ucg->cg_irotor = cpu_to_fs32(sb, ucpi->c_irotor); ucg->cg_irotor = cpu_to_fs32(sb, ucpi->c_irotor);
ubh_mark_buffer_dirty (UCPI_UBH); ubh_mark_buffer_dirty (UCPI_UBH(ucpi));
for (i = 1; i < UCPI_UBH->count; i++) { for (i = 1; i < UCPI_UBH(ucpi)->count; i++) {
brelse (UCPI_UBH->bh[i]); brelse (UCPI_UBH(ucpi)->bh[i]);
} }
sbi->s_cgno[bitmap_nr] = UFS_CGNO_EMPTY; sbi->s_cgno[bitmap_nr] = UFS_CGNO_EMPTY;
......
...@@ -91,7 +91,7 @@ void ufs_free_inode (struct inode * inode) ...@@ -91,7 +91,7 @@ void ufs_free_inode (struct inode * inode)
unlock_super (sb); unlock_super (sb);
return; return;
} }
ucg = ubh_get_ucg(UCPI_UBH); ucg = ubh_get_ucg(UCPI_UBH(ucpi));
if (!ufs_cg_chkmagic(sb, ucg)) if (!ufs_cg_chkmagic(sb, ucg))
ufs_panic (sb, "ufs_free_fragments", "internal error, bad cg magic number"); ufs_panic (sb, "ufs_free_fragments", "internal error, bad cg magic number");
...@@ -104,10 +104,10 @@ void ufs_free_inode (struct inode * inode) ...@@ -104,10 +104,10 @@ void ufs_free_inode (struct inode * inode)
clear_inode (inode); clear_inode (inode);
if (ubh_isclr (UCPI_UBH, ucpi->c_iusedoff, bit)) if (ubh_isclr (UCPI_UBH(ucpi), ucpi->c_iusedoff, bit))
ufs_error(sb, "ufs_free_inode", "bit already cleared for inode %u", ino); ufs_error(sb, "ufs_free_inode", "bit already cleared for inode %u", ino);
else { else {
ubh_clrbit (UCPI_UBH, ucpi->c_iusedoff, bit); ubh_clrbit (UCPI_UBH(ucpi), ucpi->c_iusedoff, bit);
if (ino < ucpi->c_irotor) if (ino < ucpi->c_irotor)
ucpi->c_irotor = ino; ucpi->c_irotor = ino;
fs32_add(sb, &ucg->cg_cs.cs_nifree, 1); fs32_add(sb, &ucg->cg_cs.cs_nifree, 1);
...@@ -121,11 +121,11 @@ void ufs_free_inode (struct inode * inode) ...@@ -121,11 +121,11 @@ void ufs_free_inode (struct inode * inode)
} }
} }
ubh_mark_buffer_dirty (USPI_UBH); ubh_mark_buffer_dirty (USPI_UBH(uspi));
ubh_mark_buffer_dirty (UCPI_UBH); ubh_mark_buffer_dirty (UCPI_UBH(ucpi));
if (sb->s_flags & MS_SYNCHRONOUS) { if (sb->s_flags & MS_SYNCHRONOUS) {
ubh_ll_rw_block (SWRITE, 1, (struct ufs_buffer_head **) &ucpi); ubh_ll_rw_block (SWRITE, 1, (struct ufs_buffer_head **) &ucpi);
ubh_wait_on_buffer (UCPI_UBH); ubh_wait_on_buffer (UCPI_UBH(ucpi));
} }
sb->s_dirt = 1; sb->s_dirt = 1;
...@@ -213,14 +213,14 @@ struct inode * ufs_new_inode(struct inode * dir, int mode) ...@@ -213,14 +213,14 @@ struct inode * ufs_new_inode(struct inode * dir, int mode)
ucpi = ufs_load_cylinder (sb, cg); ucpi = ufs_load_cylinder (sb, cg);
if (!ucpi) if (!ucpi)
goto failed; goto failed;
ucg = ubh_get_ucg(UCPI_UBH); ucg = ubh_get_ucg(UCPI_UBH(ucpi));
if (!ufs_cg_chkmagic(sb, ucg)) if (!ufs_cg_chkmagic(sb, ucg))
ufs_panic (sb, "ufs_new_inode", "internal error, bad cg magic number"); ufs_panic (sb, "ufs_new_inode", "internal error, bad cg magic number");
start = ucpi->c_irotor; start = ucpi->c_irotor;
bit = ubh_find_next_zero_bit (UCPI_UBH, ucpi->c_iusedoff, uspi->s_ipg, start); bit = ubh_find_next_zero_bit (UCPI_UBH(ucpi), ucpi->c_iusedoff, uspi->s_ipg, start);
if (!(bit < uspi->s_ipg)) { if (!(bit < uspi->s_ipg)) {
bit = ubh_find_first_zero_bit (UCPI_UBH, ucpi->c_iusedoff, start); bit = ubh_find_first_zero_bit (UCPI_UBH(ucpi), ucpi->c_iusedoff, start);
if (!(bit < start)) { if (!(bit < start)) {
ufs_error (sb, "ufs_new_inode", ufs_error (sb, "ufs_new_inode",
"cylinder group %u corrupted - error in inode bitmap\n", cg); "cylinder group %u corrupted - error in inode bitmap\n", cg);
...@@ -228,8 +228,8 @@ struct inode * ufs_new_inode(struct inode * dir, int mode) ...@@ -228,8 +228,8 @@ struct inode * ufs_new_inode(struct inode * dir, int mode)
} }
} }
UFSD(("start = %u, bit = %u, ipg = %u\n", start, bit, uspi->s_ipg)) UFSD(("start = %u, bit = %u, ipg = %u\n", start, bit, uspi->s_ipg))
if (ubh_isclr (UCPI_UBH, ucpi->c_iusedoff, bit)) if (ubh_isclr (UCPI_UBH(ucpi), ucpi->c_iusedoff, bit))
ubh_setbit (UCPI_UBH, ucpi->c_iusedoff, bit); ubh_setbit (UCPI_UBH(ucpi), ucpi->c_iusedoff, bit);
else { else {
ufs_panic (sb, "ufs_new_inode", "internal error"); ufs_panic (sb, "ufs_new_inode", "internal error");
goto failed; goto failed;
...@@ -245,11 +245,11 @@ struct inode * ufs_new_inode(struct inode * dir, int mode) ...@@ -245,11 +245,11 @@ struct inode * ufs_new_inode(struct inode * dir, int mode)
fs32_add(sb, &sbi->fs_cs(cg).cs_ndir, 1); fs32_add(sb, &sbi->fs_cs(cg).cs_ndir, 1);
} }
ubh_mark_buffer_dirty (USPI_UBH); ubh_mark_buffer_dirty (USPI_UBH(uspi));
ubh_mark_buffer_dirty (UCPI_UBH); ubh_mark_buffer_dirty (UCPI_UBH(ucpi));
if (sb->s_flags & MS_SYNCHRONOUS) { if (sb->s_flags & MS_SYNCHRONOUS) {
ubh_ll_rw_block (SWRITE, 1, (struct ufs_buffer_head **) &ucpi); ubh_ll_rw_block (SWRITE, 1, (struct ufs_buffer_head **) &ucpi);
ubh_wait_on_buffer (UCPI_UBH); ubh_wait_on_buffer (UCPI_UBH(ucpi));
} }
sb->s_dirt = 1; sb->s_dirt = 1;
......
...@@ -225,7 +225,7 @@ void ufs_error (struct super_block * sb, const char * function, ...@@ -225,7 +225,7 @@ void ufs_error (struct super_block * sb, const char * function,
if (!(sb->s_flags & MS_RDONLY)) { if (!(sb->s_flags & MS_RDONLY)) {
usb1->fs_clean = UFS_FSBAD; usb1->fs_clean = UFS_FSBAD;
ubh_mark_buffer_dirty(USPI_UBH); ubh_mark_buffer_dirty(USPI_UBH(uspi));
sb->s_dirt = 1; sb->s_dirt = 1;
sb->s_flags |= MS_RDONLY; sb->s_flags |= MS_RDONLY;
} }
...@@ -257,7 +257,7 @@ void ufs_panic (struct super_block * sb, const char * function, ...@@ -257,7 +257,7 @@ void ufs_panic (struct super_block * sb, const char * function,
if (!(sb->s_flags & MS_RDONLY)) { if (!(sb->s_flags & MS_RDONLY)) {
usb1->fs_clean = UFS_FSBAD; usb1->fs_clean = UFS_FSBAD;
ubh_mark_buffer_dirty(USPI_UBH); ubh_mark_buffer_dirty(USPI_UBH(uspi));
sb->s_dirt = 1; sb->s_dirt = 1;
} }
va_start (args, fmt); va_start (args, fmt);
...@@ -1014,7 +1014,7 @@ static void ufs_write_super (struct super_block *sb) { ...@@ -1014,7 +1014,7 @@ static void ufs_write_super (struct super_block *sb) {
|| (flags & UFS_ST_MASK) == UFS_ST_SUNx86) || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
ufs_set_fs_state(sb, usb1, usb3, ufs_set_fs_state(sb, usb1, usb3,
UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time)); UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
ubh_mark_buffer_dirty (USPI_UBH); ubh_mark_buffer_dirty (USPI_UBH(uspi));
} }
sb->s_dirt = 0; sb->s_dirt = 0;
UFSD(("EXIT\n")) UFSD(("EXIT\n"))
...@@ -1083,7 +1083,7 @@ static int ufs_remount (struct super_block *sb, int *mount_flags, char *data) ...@@ -1083,7 +1083,7 @@ static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
|| (flags & UFS_ST_MASK) == UFS_ST_SUNx86) || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
ufs_set_fs_state(sb, usb1, usb3, ufs_set_fs_state(sb, usb1, usb3,
UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time)); UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
ubh_mark_buffer_dirty (USPI_UBH); ubh_mark_buffer_dirty (USPI_UBH(uspi));
sb->s_dirt = 0; sb->s_dirt = 0;
sb->s_flags |= MS_RDONLY; sb->s_flags |= MS_RDONLY;
} }
......
...@@ -63,17 +63,17 @@ struct ufs_buffer_head * ubh_bread_uspi (struct ufs_sb_private_info * uspi, ...@@ -63,17 +63,17 @@ struct ufs_buffer_head * ubh_bread_uspi (struct ufs_sb_private_info * uspi,
count = size >> uspi->s_fshift; count = size >> uspi->s_fshift;
if (count <= 0 || count > UFS_MAXFRAG) if (count <= 0 || count > UFS_MAXFRAG)
return NULL; return NULL;
USPI_UBH->fragment = fragment; USPI_UBH(uspi)->fragment = fragment;
USPI_UBH->count = count; USPI_UBH(uspi)->count = count;
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
if (!(USPI_UBH->bh[i] = sb_bread(sb, fragment + i))) if (!(USPI_UBH(uspi)->bh[i] = sb_bread(sb, fragment + i)))
goto failed; goto failed;
for (; i < UFS_MAXFRAG; i++) for (; i < UFS_MAXFRAG; i++)
USPI_UBH->bh[i] = NULL; USPI_UBH(uspi)->bh[i] = NULL;
return USPI_UBH; return USPI_UBH(uspi);
failed: failed:
for (j = 0; j < i; j++) for (j = 0; j < i; j++)
brelse (USPI_UBH->bh[j]); brelse (USPI_UBH(uspi)->bh[j]);
return NULL; return NULL;
} }
...@@ -90,11 +90,11 @@ void ubh_brelse (struct ufs_buffer_head * ubh) ...@@ -90,11 +90,11 @@ void ubh_brelse (struct ufs_buffer_head * ubh)
void ubh_brelse_uspi (struct ufs_sb_private_info * uspi) void ubh_brelse_uspi (struct ufs_sb_private_info * uspi)
{ {
unsigned i; unsigned i;
if (!USPI_UBH) if (!USPI_UBH(uspi))
return; return;
for ( i = 0; i < USPI_UBH->count; i++ ) { for ( i = 0; i < USPI_UBH(uspi)->count; i++ ) {
brelse (USPI_UBH->bh[i]); brelse (USPI_UBH(uspi)->bh[i]);
USPI_UBH->bh[i] = NULL; USPI_UBH(uspi)->bh[i] = NULL;
} }
} }
......
...@@ -17,10 +17,16 @@ ...@@ -17,10 +17,16 @@
#define in_range(b,first,len) ((b)>=(first)&&(b)<(first)+(len)) #define in_range(b,first,len) ((b)>=(first)&&(b)<(first)+(len))
/* /*
* macros used for retyping * functions used for retyping
*/ */
#define UCPI_UBH ((struct ufs_buffer_head *)ucpi) static inline struct ufs_buffer_head *UCPI_UBH(struct ufs_cg_private_info *cpi)
#define USPI_UBH ((struct ufs_buffer_head *)uspi) {
return &cpi->c_ubh;
}
static inline struct ufs_buffer_head *USPI_UBH(struct ufs_sb_private_info *spi)
{
return &spi->s_ubh;
}
...@@ -326,10 +332,10 @@ static inline void *get_usb_offset(struct ufs_sb_private_info *uspi, ...@@ -326,10 +332,10 @@ static inline void *get_usb_offset(struct ufs_sb_private_info *uspi,
* Macros to access cylinder group array structures * Macros to access cylinder group array structures
*/ */
#define ubh_cg_blktot(ucpi,cylno) \ #define ubh_cg_blktot(ucpi,cylno) \
(*((__fs32*)ubh_get_addr(UCPI_UBH, (ucpi)->c_btotoff + ((cylno) << 2)))) (*((__fs32*)ubh_get_addr(UCPI_UBH(ucpi), (ucpi)->c_btotoff + ((cylno) << 2))))
#define ubh_cg_blks(ucpi,cylno,rpos) \ #define ubh_cg_blks(ucpi,cylno,rpos) \
(*((__fs16*)ubh_get_addr(UCPI_UBH, \ (*((__fs16*)ubh_get_addr(UCPI_UBH(ucpi), \
(ucpi)->c_boff + (((cylno) * uspi->s_nrpos + (rpos)) << 1 )))) (ucpi)->c_boff + (((cylno) * uspi->s_nrpos + (rpos)) << 1 ))))
/* /*
......
...@@ -666,7 +666,7 @@ struct ufs_buffer_head { ...@@ -666,7 +666,7 @@ struct ufs_buffer_head {
}; };
struct ufs_cg_private_info { struct ufs_cg_private_info {
struct ufs_cylinder_group ucg; struct ufs_buffer_head c_ubh;
__u32 c_cgx; /* number of cylidner group */ __u32 c_cgx; /* number of cylidner group */
__u16 c_ncyl; /* number of cyl's this cg */ __u16 c_ncyl; /* number of cyl's this cg */
__u16 c_niblk; /* number of inode blocks this cg */ __u16 c_niblk; /* number of inode blocks this cg */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment