* [PATCH] btrfs-progs: fix uninitialized warining in btrfs_calc_stripe_index
@ 2014-10-02 0:32 Anand Jain
2014-10-06 17:19 ` David Sterba
0 siblings, 1 reply; 5+ messages in thread
From: Anand Jain @ 2014-10-02 0:32 UTC (permalink / raw)
To: linux-btrfs
chunk-recover.c: In function ‘btrfs_calc_stripe_index’:
chunk-recover.c:1481: warning: ‘index’ may be used uninitialized in this function
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
chunk-recover.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/chunk-recover.c b/chunk-recover.c
index 209d7a7..5daffe3 100644
--- a/chunk-recover.c
+++ b/chunk-recover.c
@@ -1478,7 +1478,7 @@ static int btrfs_calc_stripe_index(struct chunk_record *chunk, u64 logical)
u64 offset = logical - chunk->offset;
int stripe_nr;
int nr_data_stripes;
- int index;
+ int index = 0;
stripe_nr = offset / chunk->stripe_len;
if (chunk->type_flags & BTRFS_BLOCK_GROUP_RAID0) {
--
2.0.0.153.g79dcccc
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] btrfs-progs: fix uninitialized warining in btrfs_calc_stripe_index
2014-10-02 0:32 [PATCH] btrfs-progs: fix uninitialized warining in btrfs_calc_stripe_index Anand Jain
@ 2014-10-06 17:19 ` David Sterba
2014-10-06 22:17 ` [PATCH v2] " Anand Jain
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: David Sterba @ 2014-10-06 17:19 UTC (permalink / raw)
To: Anand Jain; +Cc: linux-btrfs
On Thu, Oct 02, 2014 at 08:32:01AM +0800, Anand Jain wrote:
> chunk-recover.c: In function ‘btrfs_calc_stripe_index’:
> chunk-recover.c:1481: warning: ‘index’ may be used uninitialized in this function
> --- a/chunk-recover.c
> +++ b/chunk-recover.c
> @@ -1478,7 +1478,7 @@ static int btrfs_calc_stripe_index(struct chunk_record *chunk, u64 logical)
> u64 offset = logical - chunk->offset;
> int stripe_nr;
> int nr_data_stripes;
> - int index;
> + int index = 0;
>
> stripe_nr = offset / chunk->stripe_len;
> if (chunk->type_flags & BTRFS_BLOCK_GROUP_RAID0) {
The catch-all branch does BUG_ON so the compiler probably misses that
for some reason, otherwise the index value is always defined. It would
be better to replace the BUG_ON with "return -1" and handle the error in
the callers.
The BUG_ON happens if there's an unknown block group type, these are
well known and any error here means there's a corruption or unsupported
type. Both condition could be handled in a better way.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] btrfs-progs: fix uninitialized warining in btrfs_calc_stripe_index
2014-10-06 17:19 ` David Sterba
@ 2014-10-06 22:17 ` Anand Jain
2014-10-06 22:20 ` [PATCH v3] btrfs-progs: fix uninitialized warning " Anand Jain
2014-10-06 22:27 ` [PATCH v4] " Anand Jain
2 siblings, 0 replies; 5+ messages in thread
From: Anand Jain @ 2014-10-06 22:17 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba
From: Anand Jain <Anand.Jain@oracle.com>
chunk-recover.c: In function ‘btrfs_calc_stripe_index’:
chunk-recover.c:1481: warning: ‘index’ may be used uninitialized in this function
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v2: Accept David review comment
chunk-recover.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/chunk-recover.c b/chunk-recover.c
index 14c25a7..058a652 100644
--- a/chunk-recover.c
+++ b/chunk-recover.c
@@ -1491,7 +1491,7 @@ static int btrfs_calc_stripe_index(struct chunk_record *chunk, u64 logical)
stripe_nr /= nr_data_stripes;
index = (index + stripe_nr) % chunk->num_stripes;
} else {
- BUG_ON(1);
+ return -1;
}
return index;
}
@@ -1554,6 +1554,7 @@ btrfs_rebuild_ordered_meta_chunk_stripes(struct recover_control *rc,
again:
er = container_of(cache, struct extent_record, cache);
index = btrfs_calc_stripe_index(chunk, er->cache.start);
+ BUG_ON(index == -1);
if (chunk->stripes[index].devid)
goto next;
list_for_each_entry_safe(devext, next, &devexts, chunk_list) {
@@ -1944,6 +1945,7 @@ next_csum:
if (list_is_last(candidates.next, &candidates)) {
index = btrfs_calc_stripe_index(chunk,
key.offset + csum_offset * blocksize);
+ BUG_ON(index == -1);
if (chunk->stripes[index].devid)
goto next_stripe;
ret = insert_stripe(&candidates, rc, chunk, index);
--
2.0.0.153.g79dcccc
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v3] btrfs-progs: fix uninitialized warning in btrfs_calc_stripe_index
2014-10-06 17:19 ` David Sterba
2014-10-06 22:17 ` [PATCH v2] " Anand Jain
@ 2014-10-06 22:20 ` Anand Jain
2014-10-06 22:27 ` [PATCH v4] " Anand Jain
2 siblings, 0 replies; 5+ messages in thread
From: Anand Jain @ 2014-10-06 22:20 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba
From: Anand Jain <Anand.Jain@oracle.com>
chunk-recover.c: In function ‘btrfs_calc_stripe_index’:
chunk-recover.c:1481: warning: ‘index’ may be used uninitialized in this function
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v3: fix typo in commit
v2: Accept David review comment
chunk-recover.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/chunk-recover.c b/chunk-recover.c
index 14c25a7..058a652 100644
--- a/chunk-recover.c
+++ b/chunk-recover.c
@@ -1491,7 +1491,7 @@ static int btrfs_calc_stripe_index(struct chunk_record *chunk, u64 logical)
stripe_nr /= nr_data_stripes;
index = (index + stripe_nr) % chunk->num_stripes;
} else {
- BUG_ON(1);
+ return -1;
}
return index;
}
@@ -1554,6 +1554,7 @@ btrfs_rebuild_ordered_meta_chunk_stripes(struct recover_control *rc,
again:
er = container_of(cache, struct extent_record, cache);
index = btrfs_calc_stripe_index(chunk, er->cache.start);
+ BUG_ON(index == -1);
if (chunk->stripes[index].devid)
goto next;
list_for_each_entry_safe(devext, next, &devexts, chunk_list) {
@@ -1944,6 +1945,7 @@ next_csum:
if (list_is_last(candidates.next, &candidates)) {
index = btrfs_calc_stripe_index(chunk,
key.offset + csum_offset * blocksize);
+ BUG_ON(index == -1);
if (chunk->stripes[index].devid)
goto next_stripe;
ret = insert_stripe(&candidates, rc, chunk, index);
--
2.0.0.153.g79dcccc
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v4] btrfs-progs: fix uninitialized warning in btrfs_calc_stripe_index
2014-10-06 17:19 ` David Sterba
2014-10-06 22:17 ` [PATCH v2] " Anand Jain
2014-10-06 22:20 ` [PATCH v3] btrfs-progs: fix uninitialized warning " Anand Jain
@ 2014-10-06 22:27 ` Anand Jain
2 siblings, 0 replies; 5+ messages in thread
From: Anand Jain @ 2014-10-06 22:27 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba
From: Anand Jain <Anand.Jain@oracle.com>
chunk-recover.c: In function btrfs_calc_stripe_index
chunk-recover.c:1481: warning: index may be used uninitialized in this function
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
v4: remove some unintended char in commit, sorry
v3: fix typo in commit
v2: Accept David review comment
chunk-recover.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/chunk-recover.c b/chunk-recover.c
index 14c25a7..058a652 100644
--- a/chunk-recover.c
+++ b/chunk-recover.c
@@ -1491,7 +1491,7 @@ static int btrfs_calc_stripe_index(struct chunk_record *chunk, u64 logical)
stripe_nr /= nr_data_stripes;
index = (index + stripe_nr) % chunk->num_stripes;
} else {
- BUG_ON(1);
+ return -1;
}
return index;
}
@@ -1554,6 +1554,7 @@ btrfs_rebuild_ordered_meta_chunk_stripes(struct recover_control *rc,
again:
er = container_of(cache, struct extent_record, cache);
index = btrfs_calc_stripe_index(chunk, er->cache.start);
+ BUG_ON(index == -1);
if (chunk->stripes[index].devid)
goto next;
list_for_each_entry_safe(devext, next, &devexts, chunk_list) {
@@ -1944,6 +1945,7 @@ next_csum:
if (list_is_last(candidates.next, &candidates)) {
index = btrfs_calc_stripe_index(chunk,
key.offset + csum_offset * blocksize);
+ BUG_ON(index == -1);
if (chunk->stripes[index].devid)
goto next_stripe;
ret = insert_stripe(&candidates, rc, chunk, index);
--
2.0.0.153.g79dcccc
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-10-07 6:22 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-02 0:32 [PATCH] btrfs-progs: fix uninitialized warining in btrfs_calc_stripe_index Anand Jain
2014-10-06 17:19 ` David Sterba
2014-10-06 22:17 ` [PATCH v2] " Anand Jain
2014-10-06 22:20 ` [PATCH v3] btrfs-progs: fix uninitialized warning " Anand Jain
2014-10-06 22:27 ` [PATCH v4] " Anand Jain
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.