Skip to content

Commit 487767b

Browse files
Purva YeshiMikulas Patocka
authored andcommitted
md: dm-zoned-target: Initialize return variable r to avoid uninitialized use
Fix Smatch-detected error: drivers/md/dm-zoned-target.c:1073 dmz_iterate_devices() error: uninitialized symbol 'r'. Smatch detects a possible use of the uninitialized variable 'r' in dmz_iterate_devices() because if dmz->nr_ddevs is zero, the loop is skipped and 'r' is returned without being set, leading to undefined behavior. Initialize 'r' to 0 before the loop. This ensures that if there are no devices to iterate over, the function still returns a defined value. Signed-off-by: Purva Yeshi <[email protected]> Signed-off-by: Mikulas Patocka <[email protected]>
1 parent bdf253d commit 487767b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/md/dm-zoned-target.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ static int dmz_iterate_devices(struct dm_target *ti,
10621062
struct dmz_target *dmz = ti->private;
10631063
unsigned int zone_nr_sectors = dmz_zone_nr_sectors(dmz->metadata);
10641064
sector_t capacity;
1065-
int i, r;
1065+
int i, r = 0;
10661066

10671067
for (i = 0; i < dmz->nr_ddevs; i++) {
10681068
capacity = dmz->dev[i].capacity & ~(zone_nr_sectors - 1);

0 commit comments

Comments
 (0)