* [Cluster-devel] gfs2_dir_read_data(): fix uninitialized variable usage
@ 2006-10-19 14:02 Adrian Bunk
2006-10-19 15:18 ` [Cluster-devel] " Steven Whitehouse
0 siblings, 1 reply; 2+ messages in thread
From: Adrian Bunk @ 2006-10-19 14:02 UTC (permalink / raw)
To: cluster-devel.redhat.com
In the "if (extlen)" case, "bh" was used uninitialized.
This patch changes the code to what seems to have been intended.
Spotted by the Coverity checker.
This patch also removes a pointless "bh = NULL" asignment (the variable
is never accessed again after this point).
Signed-off-by: Adrian Bunk <bunk@stusta.de>
--- linux-2.6/fs/gfs2/dir.c.old 2006-10-19 15:33:52.000000000 +0200
+++ linux-2.6/fs/gfs2/dir.c 2006-10-19 15:35:44.000000000 +0200
@@ -301,54 +301,52 @@ static int gfs2_dir_read_data(struct gfs
while (copied < size) {
unsigned int amount;
struct buffer_head *bh;
int new;
amount = size - copied;
if (amount > sdp->sd_sb.sb_bsize - o)
amount = sdp->sd_sb.sb_bsize - o;
if (!extlen) {
new = 0;
error = gfs2_extent_map(&ip->i_inode, lblock, &new,
&dblock, &extlen);
if (error || !dblock)
goto fail;
BUG_ON(extlen < 1);
if (!ra)
extlen = 1;
bh = gfs2_meta_ra(ip->i_gl, dblock, extlen);
- }
- if (!bh) {
+ } else {
error = gfs2_meta_read(ip->i_gl, dblock, DIO_WAIT, &bh);
if (error)
goto fail;
}
error = gfs2_metatype_check(sdp, bh, GFS2_METATYPE_JD);
if (error) {
brelse(bh);
goto fail;
}
dblock++;
extlen--;
memcpy(buf, bh->b_data + o, amount);
brelse(bh);
- bh = NULL;
buf += amount;
copied += amount;
lblock++;
o = sizeof(struct gfs2_meta_header);
}
return copied;
fail:
return (copied) ? copied : error;
}
static inline int __gfs2_dirent_find(const struct gfs2_dirent *dent,
const struct qstr *name, int ret)
{
if (dent->de_inum.no_addr != 0 &&
be32_to_cpu(dent->de_hash) == name->hash &&
be16_to_cpu(dent->de_name_len) == name->len &&
memcmp(dent+1, name->name, name->len) == 0)
return ret;
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Cluster-devel] Re: gfs2_dir_read_data(): fix uninitialized variable usage
2006-10-19 14:02 [Cluster-devel] gfs2_dir_read_data(): fix uninitialized variable usage Adrian Bunk
@ 2006-10-19 15:18 ` Steven Whitehouse
0 siblings, 0 replies; 2+ messages in thread
From: Steven Whitehouse @ 2006-10-19 15:18 UTC (permalink / raw)
To: cluster-devel.redhat.com
Hi,
This one is now in the GFS2 tree too. Thanks,
Steve.
On Thu, 2006-10-19 at 16:02 +0200, Adrian Bunk wrote:
> In the "if (extlen)" case, "bh" was used uninitialized.
>
> This patch changes the code to what seems to have been intended.
>
> Spotted by the Coverity checker.
>
> This patch also removes a pointless "bh = NULL" asignment (the variable
> is never accessed again after this point).
>
> Signed-off-by: Adrian Bunk <bunk@stusta.de>
>
> --- linux-2.6/fs/gfs2/dir.c.old 2006-10-19 15:33:52.000000000 +0200
> +++ linux-2.6/fs/gfs2/dir.c 2006-10-19 15:35:44.000000000 +0200
> @@ -301,54 +301,52 @@ static int gfs2_dir_read_data(struct gfs
> while (copied < size) {
> unsigned int amount;
> struct buffer_head *bh;
> int new;
>
> amount = size - copied;
> if (amount > sdp->sd_sb.sb_bsize - o)
> amount = sdp->sd_sb.sb_bsize - o;
>
> if (!extlen) {
> new = 0;
> error = gfs2_extent_map(&ip->i_inode, lblock, &new,
> &dblock, &extlen);
> if (error || !dblock)
> goto fail;
> BUG_ON(extlen < 1);
> if (!ra)
> extlen = 1;
> bh = gfs2_meta_ra(ip->i_gl, dblock, extlen);
> - }
> - if (!bh) {
> + } else {
> error = gfs2_meta_read(ip->i_gl, dblock, DIO_WAIT, &bh);
> if (error)
> goto fail;
> }
> error = gfs2_metatype_check(sdp, bh, GFS2_METATYPE_JD);
> if (error) {
> brelse(bh);
> goto fail;
> }
> dblock++;
> extlen--;
> memcpy(buf, bh->b_data + o, amount);
> brelse(bh);
> - bh = NULL;
> buf += amount;
> copied += amount;
> lblock++;
> o = sizeof(struct gfs2_meta_header);
> }
>
> return copied;
> fail:
> return (copied) ? copied : error;
> }
>
> static inline int __gfs2_dirent_find(const struct gfs2_dirent *dent,
> const struct qstr *name, int ret)
> {
> if (dent->de_inum.no_addr != 0 &&
> be32_to_cpu(dent->de_hash) == name->hash &&
> be16_to_cpu(dent->de_name_len) == name->len &&
> memcmp(dent+1, name->name, name->len) == 0)
> return ret;
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-10-19 15:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-19 14:02 [Cluster-devel] gfs2_dir_read_data(): fix uninitialized variable usage Adrian Bunk
2006-10-19 15:18 ` [Cluster-devel] " Steven Whitehouse
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).