Skip to content

Commit 3c12016

Browse files
Mikulas Patockasnitm
Mikulas Patocka
authored andcommitted
dm table: replace while loops with for loops
Also remove some unnecessary use of uninitialized_var(). Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
1 parent cc7e394 commit 3c12016

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

drivers/md/dm-table.c

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ static int upgrade_mode(struct dm_dev_internal *dd, fmode_t new_mode,
373373
*/
374374
dev_t dm_get_dev_t(const char *path)
375375
{
376-
dev_t uninitialized_var(dev);
376+
dev_t dev;
377377
struct block_device *bdev;
378378

379379
bdev = lookup_bdev(path);
@@ -627,13 +627,13 @@ static int validate_hardware_logical_block_alignment(struct dm_table *table,
627627

628628
struct dm_target *uninitialized_var(ti);
629629
struct queue_limits ti_limits;
630-
unsigned i = 0;
630+
unsigned i;
631631

632632
/*
633633
* Check each entry in the table in turn.
634634
*/
635-
while (i < dm_table_get_num_targets(table)) {
636-
ti = dm_table_get_target(table, i++);
635+
for (i = 0; i < dm_table_get_num_targets(table); i++) {
636+
ti = dm_table_get_target(table, i);
637637

638638
blk_set_stacking_limits(&ti_limits);
639639

@@ -854,11 +854,11 @@ static int device_supports_dax(struct dm_target *ti, struct dm_dev *dev,
854854
static bool dm_table_supports_dax(struct dm_table *t)
855855
{
856856
struct dm_target *ti;
857-
unsigned i = 0;
857+
unsigned i;
858858

859859
/* Ensure that all targets support DAX. */
860-
while (i < dm_table_get_num_targets(t)) {
861-
ti = dm_table_get_target(t, i++);
860+
for (i = 0; i < dm_table_get_num_targets(t); i++) {
861+
ti = dm_table_get_target(t, i);
862862

863863
if (!ti->type->direct_access)
864864
return false;
@@ -1010,11 +1010,11 @@ struct dm_target *dm_table_get_immutable_target(struct dm_table *t)
10101010

10111011
struct dm_target *dm_table_get_wildcard_target(struct dm_table *t)
10121012
{
1013-
struct dm_target *uninitialized_var(ti);
1014-
unsigned i = 0;
1013+
struct dm_target *ti;
1014+
unsigned i;
10151015

1016-
while (i < dm_table_get_num_targets(t)) {
1017-
ti = dm_table_get_target(t, i++);
1016+
for (i = 0; i < dm_table_get_num_targets(t); i++) {
1017+
ti = dm_table_get_target(t, i);
10181018
if (dm_target_is_wildcard(ti->type))
10191019
return ti;
10201020
}
@@ -1321,15 +1321,16 @@ static int count_device(struct dm_target *ti, struct dm_dev *dev,
13211321
*/
13221322
bool dm_table_has_no_data_devices(struct dm_table *table)
13231323
{
1324-
struct dm_target *uninitialized_var(ti);
1325-
unsigned i = 0, num_devices = 0;
1324+
struct dm_target *ti;
1325+
unsigned i, num_devices;
13261326

1327-
while (i < dm_table_get_num_targets(table)) {
1328-
ti = dm_table_get_target(table, i++);
1327+
for (i = 0; i < dm_table_get_num_targets(table); i++) {
1328+
ti = dm_table_get_target(table, i);
13291329

13301330
if (!ti->type->iterate_devices)
13311331
return false;
13321332

1333+
num_devices = 0;
13331334
ti->type->iterate_devices(ti, count_device, &num_devices);
13341335
if (num_devices)
13351336
return false;
@@ -1344,16 +1345,16 @@ bool dm_table_has_no_data_devices(struct dm_table *table)
13441345
int dm_calculate_queue_limits(struct dm_table *table,
13451346
struct queue_limits *limits)
13461347
{
1347-
struct dm_target *uninitialized_var(ti);
1348+
struct dm_target *ti;
13481349
struct queue_limits ti_limits;
1349-
unsigned i = 0;
1350+
unsigned i;
13501351

13511352
blk_set_stacking_limits(limits);
13521353

1353-
while (i < dm_table_get_num_targets(table)) {
1354+
for (i = 0; i < dm_table_get_num_targets(table); i++) {
13541355
blk_set_stacking_limits(&ti_limits);
13551356

1356-
ti = dm_table_get_target(table, i++);
1357+
ti = dm_table_get_target(table, i);
13571358

13581359
if (!ti->type->iterate_devices)
13591360
goto combine_limits;
@@ -1435,16 +1436,16 @@ static int device_flush_capable(struct dm_target *ti, struct dm_dev *dev,
14351436
static bool dm_table_supports_flush(struct dm_table *t, unsigned long flush)
14361437
{
14371438
struct dm_target *ti;
1438-
unsigned i = 0;
1439+
unsigned i;
14391440

14401441
/*
14411442
* Require at least one underlying device to support flushes.
14421443
* t->devices includes internal dm devices such as mirror logs
14431444
* so we need to use iterate_devices here, which targets
14441445
* supporting flushes must provide.
14451446
*/
1446-
while (i < dm_table_get_num_targets(t)) {
1447-
ti = dm_table_get_target(t, i++);
1447+
for (i = 0; i < dm_table_get_num_targets(t); i++) {
1448+
ti = dm_table_get_target(t, i);
14481449

14491450
if (!ti->num_flush_bios)
14501451
continue;
@@ -1504,10 +1505,10 @@ static bool dm_table_all_devices_attribute(struct dm_table *t,
15041505
iterate_devices_callout_fn func)
15051506
{
15061507
struct dm_target *ti;
1507-
unsigned i = 0;
1508+
unsigned i;
15081509

1509-
while (i < dm_table_get_num_targets(t)) {
1510-
ti = dm_table_get_target(t, i++);
1510+
for (i = 0; i < dm_table_get_num_targets(t); i++) {
1511+
ti = dm_table_get_target(t, i);
15111512

15121513
if (!ti->type->iterate_devices ||
15131514
!ti->type->iterate_devices(ti, func, NULL))
@@ -1528,10 +1529,10 @@ static int device_not_write_same_capable(struct dm_target *ti, struct dm_dev *de
15281529
static bool dm_table_supports_write_same(struct dm_table *t)
15291530
{
15301531
struct dm_target *ti;
1531-
unsigned i = 0;
1532+
unsigned i;
15321533

1533-
while (i < dm_table_get_num_targets(t)) {
1534-
ti = dm_table_get_target(t, i++);
1534+
for (i = 0; i < dm_table_get_num_targets(t); i++) {
1535+
ti = dm_table_get_target(t, i);
15351536

15361537
if (!ti->num_write_same_bios)
15371538
return false;
@@ -1555,7 +1556,7 @@ static int device_discard_capable(struct dm_target *ti, struct dm_dev *dev,
15551556
static bool dm_table_supports_discards(struct dm_table *t)
15561557
{
15571558
struct dm_target *ti;
1558-
unsigned i = 0;
1559+
unsigned i;
15591560

15601561
/*
15611562
* Unless any target used by the table set discards_supported,
@@ -1564,8 +1565,8 @@ static bool dm_table_supports_discards(struct dm_table *t)
15641565
* so we need to use iterate_devices here, which targets
15651566
* supporting discard selectively must provide.
15661567
*/
1567-
while (i < dm_table_get_num_targets(t)) {
1568-
ti = dm_table_get_target(t, i++);
1568+
for (i = 0; i < dm_table_get_num_targets(t); i++) {
1569+
ti = dm_table_get_target(t, i);
15691570

15701571
if (!ti->num_discard_bios)
15711572
continue;

0 commit comments

Comments
 (0)