[PATCH] rock: remove MAYBE_CONTINUE

- remove the MAYBE_CONTINUE macro

- kfree(NULL) is OK.

Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
Andrew Morton 2005-06-21 17:16:46 -07:00 committed by Linus Torvalds
parent 76ab07ebc3
commit ba40aaf043

View File

@ -22,6 +22,16 @@
#define SIG(A,B) ((A) | ((B) << 8)) /* isonum_721() */ #define SIG(A,B) ((A) | ((B) << 8)) /* isonum_721() */
struct rock_state {
void *buffer;
unsigned char *chr;
int len;
int cont_size;
int cont_extent;
int cont_offset;
struct inode *inode;
};
/* /*
* This is a way of ensuring that we have something in the system * This is a way of ensuring that we have something in the system
* use fields that is compatible with Rock Ridge. Return zero on success. * use fields that is compatible with Rock Ridge. Return zero on success.
@ -38,82 +48,96 @@ static int check_sp(struct rock_ridge *rr, struct inode *inode)
} }
static void setup_rock_ridge(struct iso_directory_record *de, static void setup_rock_ridge(struct iso_directory_record *de,
struct inode *inode, unsigned char **chr, int *len) struct inode *inode, struct rock_state *rs)
{ {
*len = sizeof(struct iso_directory_record) + de->name_len[0]; rs->len = sizeof(struct iso_directory_record) + de->name_len[0];
if (*len & 1) if (rs->len & 1)
(*len)++; (rs->len)++;
*chr = (unsigned char *)de + *len; rs->chr = (unsigned char *)de + rs->len;
*len = *((unsigned char *)de) - *len; rs->len = *((unsigned char *)de) - rs->len;
if (*len < 0) if (rs->len < 0)
*len = 0; rs->len = 0;
if (ISOFS_SB(inode->i_sb)->s_rock_offset != -1) { if (ISOFS_SB(inode->i_sb)->s_rock_offset != -1) {
*len -= ISOFS_SB(inode->i_sb)->s_rock_offset; rs->len -= ISOFS_SB(inode->i_sb)->s_rock_offset;
*chr += ISOFS_SB(inode->i_sb)->s_rock_offset; rs->chr += ISOFS_SB(inode->i_sb)->s_rock_offset;
if (*len < 0) if (rs->len < 0)
*len = 0; rs->len = 0;
} }
} }
#define MAYBE_CONTINUE(LABEL,DEV) \ static void init_rock_state(struct rock_state *rs, struct inode *inode)
{if (buffer) { kfree(buffer); buffer = NULL; } \ {
if (cont_extent){ \ memset(rs, 0, sizeof(*rs));
int block, offset, offset1; \ rs->inode = inode;
struct buffer_head * pbh; \ }
buffer = kmalloc(cont_size,GFP_KERNEL); \
if (!buffer) goto out; \ /*
block = cont_extent; \ * Returns 0 if the caller should continue scanning, 1 if the scan must end
offset = cont_offset; \ * and -ve on error.
offset1 = 0; \ */
pbh = sb_bread(DEV->i_sb, block); \ static int rock_continue(struct rock_state *rs)
if(pbh){ \ {
if (offset > pbh->b_size || offset + cont_size > pbh->b_size){ \ int ret = 1;
brelse(pbh); \
goto out; \ kfree(rs->buffer);
} \ rs->buffer = NULL;
memcpy(buffer + offset1, pbh->b_data + offset, cont_size - offset1); \ if (rs->cont_extent) {
brelse(pbh); \ struct buffer_head *bh;
chr = (unsigned char *) buffer; \
len = cont_size; \ rs->buffer = kmalloc(rs->cont_size, GFP_KERNEL);
cont_extent = 0; \ if (!rs->buffer) {
cont_size = 0; \ ret = -ENOMEM;
cont_offset = 0; \ goto out;
goto LABEL; \ }
} \ ret = -EIO;
printk("Unable to read rock-ridge attributes\n"); \ bh = sb_bread(rs->inode->i_sb, rs->cont_extent);
}} if (bh) {
memcpy(rs->buffer, bh->b_data + rs->cont_offset,
rs->cont_size);
put_bh(bh);
rs->chr = rs->buffer;
rs->len = rs->cont_size;
rs->cont_extent = 0;
rs->cont_size = 0;
rs->cont_offset = 0;
return 0;
}
printk("Unable to read rock-ridge attributes\n");
}
out:
kfree(rs->buffer);
rs->buffer = NULL;
return ret;
}
/* return length of name field; 0: not found, -1: to be ignored */ /* return length of name field; 0: not found, -1: to be ignored */
int get_rock_ridge_filename(struct iso_directory_record *de, int get_rock_ridge_filename(struct iso_directory_record *de,
char *retname, struct inode *inode) char *retname, struct inode *inode)
{ {
int len; struct rock_state rs;
unsigned char *chr;
int cont_extent = 0;
int cont_offset = 0;
int cont_size = 0;
void *buffer = NULL;
struct rock_ridge *rr; struct rock_ridge *rr;
int sig; int sig;
int retnamlen = 0; int retnamlen = 0;
int truncate = 0; int truncate = 0;
int ret = 0;
if (!ISOFS_SB(inode->i_sb)->s_rock) if (!ISOFS_SB(inode->i_sb)->s_rock)
return 0; return 0;
*retname = 0; *retname = 0;
setup_rock_ridge(de, inode, &chr, &len); init_rock_state(&rs, inode);
setup_rock_ridge(de, inode, &rs);
repeat: repeat:
while (len > 2) { /* There may be one byte for padding somewhere */ while (rs.len > 2) { /* There may be one byte for padding somewhere */
rr = (struct rock_ridge *)chr; rr = (struct rock_ridge *)rs.chr;
if (rr->len < 3) if (rr->len < 3)
goto out; /* Something got screwed up here */ goto out; /* Something got screwed up here */
sig = isonum_721(chr); sig = isonum_721(rs.chr);
chr += rr->len; rs.chr += rr->len;
len -= rr->len; rs.len -= rr->len;
if (len < 0) if (rs.len < 0)
goto out; /* corrupted isofs */ goto out; /* corrupted isofs */
switch (sig) { switch (sig) {
@ -126,9 +150,9 @@ repeat:
goto out; goto out;
break; break;
case SIG('C', 'E'): case SIG('C', 'E'):
cont_extent = isonum_733(rr->u.CE.extent); rs.cont_extent = isonum_733(rr->u.CE.extent);
cont_offset = isonum_733(rr->u.CE.offset); rs.cont_offset = isonum_733(rr->u.CE.offset);
cont_size = isonum_733(rr->u.CE.size); rs.cont_size = isonum_733(rr->u.CE.size);
break; break;
case SIG('N', 'M'): case SIG('N', 'M'):
if (truncate) if (truncate)
@ -158,58 +182,55 @@ repeat:
retnamlen += rr->len - 5; retnamlen += rr->len - 5;
break; break;
case SIG('R', 'E'): case SIG('R', 'E'):
if (buffer) kfree(rs.buffer);
kfree(buffer);
return -1; return -1;
default: default:
break; break;
} }
} }
MAYBE_CONTINUE(repeat, inode); ret = rock_continue(&rs);
kfree(buffer); if (ret == 0)
return retnamlen; /* If 0, this file did not have a NM field */ goto repeat;
if (ret == 1)
return retnamlen; /* If 0, this file did not have a NM field */
out: out:
if (buffer) kfree(rs.buffer);
kfree(buffer); return ret;
return 0;
} }
static int static int
parse_rock_ridge_inode_internal(struct iso_directory_record *de, parse_rock_ridge_inode_internal(struct iso_directory_record *de,
struct inode *inode, int regard_xa) struct inode *inode, int regard_xa)
{ {
int len;
unsigned char *chr;
int symlink_len = 0; int symlink_len = 0;
int cnt, sig; int cnt, sig;
struct inode *reloc; struct inode *reloc;
struct rock_ridge *rr; struct rock_ridge *rr;
int rootflag; int rootflag;
int cont_extent = 0; struct rock_state rs;
int cont_offset = 0; int ret = 0;
int cont_size = 0;
void *buffer = NULL;
if (!ISOFS_SB(inode->i_sb)->s_rock) if (!ISOFS_SB(inode->i_sb)->s_rock)
return 0; return 0;
setup_rock_ridge(de, inode, &chr, &len); init_rock_state(&rs, inode);
setup_rock_ridge(de, inode, &rs);
if (regard_xa) { if (regard_xa) {
chr += 14; rs.chr += 14;
len -= 14; rs.len -= 14;
if (len < 0) if (rs.len < 0)
len = 0; rs.len = 0;
} }
repeat: repeat:
while (len > 2) { /* There may be one byte for padding somewhere */ while (rs.len > 2) { /* There may be one byte for padding somewhere */
rr = (struct rock_ridge *)chr; rr = (struct rock_ridge *)rs.chr;
if (rr->len < 3) if (rr->len < 3)
goto out; /* Something got screwed up here */ goto out; /* Something got screwed up here */
sig = isonum_721(chr); sig = isonum_721(rs.chr);
chr += rr->len; rs.chr += rr->len;
len -= rr->len; rs.len -= rr->len;
if (len < 0) if (rs.len < 0)
goto out; /* corrupted isofs */ goto out; /* corrupted isofs */
switch (sig) { switch (sig) {
@ -225,9 +246,9 @@ repeat:
goto out; goto out;
break; break;
case SIG('C', 'E'): case SIG('C', 'E'):
cont_extent = isonum_733(rr->u.CE.extent); rs.cont_extent = isonum_733(rr->u.CE.extent);
cont_offset = isonum_733(rr->u.CE.offset); rs.cont_offset = isonum_733(rr->u.CE.offset);
cont_size = isonum_733(rr->u.CE.size); rs.cont_size = isonum_733(rr->u.CE.size);
break; break;
case SIG('E', 'R'): case SIG('E', 'R'):
ISOFS_SB(inode->i_sb)->s_rock = 1; ISOFS_SB(inode->i_sb)->s_rock = 1;
@ -433,11 +454,14 @@ repeat:
break; break;
} }
} }
MAYBE_CONTINUE(repeat, inode); ret = rock_continue(&rs);
if (ret == 0)
goto repeat;
if (ret == 1)
ret = 0;
out: out:
if (buffer) kfree(rs.buffer);
kfree(buffer); return ret;
return 0;
} }
static char *get_symlink_chunk(char *rpnt, struct rock_ridge *rr, char *plimit) static char *get_symlink_chunk(char *rpnt, struct rock_ridge *rr, char *plimit)
@ -533,19 +557,16 @@ static int rock_ridge_symlink_readpage(struct file *file, struct page *page)
char *rpnt = link; char *rpnt = link;
unsigned char *pnt; unsigned char *pnt;
struct iso_directory_record *raw_de; struct iso_directory_record *raw_de;
int cont_extent = 0;
int cont_offset = 0;
int cont_size = 0;
void *buffer = NULL;
unsigned long block, offset; unsigned long block, offset;
int sig; int sig;
int len;
unsigned char *chr;
struct rock_ridge *rr; struct rock_ridge *rr;
struct rock_state rs;
int ret;
if (!ISOFS_SB(inode->i_sb)->s_rock) if (!ISOFS_SB(inode->i_sb)->s_rock)
goto error; goto error;
init_rock_state(&rs, inode);
block = ei->i_iget5_block; block = ei->i_iget5_block;
lock_kernel(); lock_kernel();
bh = sb_bread(inode->i_sb, block); bh = sb_bread(inode->i_sb, block);
@ -566,17 +587,17 @@ static int rock_ridge_symlink_readpage(struct file *file, struct page *page)
/* Now test for possible Rock Ridge extensions which will override /* Now test for possible Rock Ridge extensions which will override
some of these numbers in the inode structure. */ some of these numbers in the inode structure. */
setup_rock_ridge(raw_de, inode, &chr, &len); setup_rock_ridge(raw_de, inode, &rs);
repeat: repeat:
while (len > 2) { /* There may be one byte for padding somewhere */ while (rs.len > 2) { /* There may be one byte for padding somewhere */
rr = (struct rock_ridge *)chr; rr = (struct rock_ridge *)rs.chr;
if (rr->len < 3) if (rr->len < 3)
goto out; /* Something got screwed up here */ goto out; /* Something got screwed up here */
sig = isonum_721(chr); sig = isonum_721(rs.chr);
chr += rr->len; rs.chr += rr->len;
len -= rr->len; rs.len -= rr->len;
if (len < 0) if (rs.len < 0)
goto out; /* corrupted isofs */ goto out; /* corrupted isofs */
switch (sig) { switch (sig) {
@ -596,15 +617,18 @@ repeat:
break; break;
case SIG('C', 'E'): case SIG('C', 'E'):
/* This tells is if there is a continuation record */ /* This tells is if there is a continuation record */
cont_extent = isonum_733(rr->u.CE.extent); rs.cont_extent = isonum_733(rr->u.CE.extent);
cont_offset = isonum_733(rr->u.CE.offset); rs.cont_offset = isonum_733(rr->u.CE.offset);
cont_size = isonum_733(rr->u.CE.size); rs.cont_size = isonum_733(rr->u.CE.size);
default: default:
break; break;
} }
} }
MAYBE_CONTINUE(repeat, inode); ret = rock_continue(&rs);
kfree(buffer); if (ret == 0)
goto repeat;
if (ret < 0)
goto fail;
if (rpnt == link) if (rpnt == link)
goto fail; goto fail;
@ -618,8 +642,7 @@ repeat:
/* error exit from macro */ /* error exit from macro */
out: out:
if (buffer) kfree(rs.buffer);
kfree(buffer);
goto fail; goto fail;
out_noread: out_noread:
printk("unable to read i-node block"); printk("unable to read i-node block");