Skip to content

Commit f11c1c5

Browse files
committed
dm ioctl: cleanup error handling in table_load
Make use of common cleanup code. Signed-off-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
1 parent 00c4fc3 commit f11c1c5

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

‎drivers/md/dm-ioctl.c‎

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,46 +1262,37 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
12621262

12631263
r = dm_table_create(&t, get_mode(param), param->target_count, md);
12641264
if (r)
1265-
goto out;
1265+
goto err;
12661266

12671267
/* Protect md->type and md->queue against concurrent table loads. */
12681268
dm_lock_md_type(md);
12691269
r = populate_table(t, param, param_size);
1270-
if (r) {
1271-
dm_table_destroy(t);
1272-
dm_unlock_md_type(md);
1273-
goto out;
1274-
}
1270+
if (r)
1271+
goto err_unlock_md_type;
12751272

12761273
immutable_target_type = dm_get_immutable_target_type(md);
12771274
if (immutable_target_type &&
12781275
(immutable_target_type != dm_table_get_immutable_target_type(t))) {
12791276
DMWARN("can't replace immutable target type %s",
12801277
immutable_target_type->name);
1281-
dm_table_destroy(t);
1282-
dm_unlock_md_type(md);
12831278
r = -EINVAL;
1284-
goto out;
1279+
goto err_unlock_md_type;
12851280
}
12861281

12871282
if (dm_get_md_type(md) == DM_TYPE_NONE)
12881283
/* Initial table load: acquire type of table. */
12891284
dm_set_md_type(md, dm_table_get_type(t));
12901285
else if (dm_get_md_type(md) != dm_table_get_type(t)) {
12911286
DMWARN("can't change device type after initial table load.");
1292-
dm_table_destroy(t);
1293-
dm_unlock_md_type(md);
12941287
r = -EINVAL;
1295-
goto out;
1288+
goto err_unlock_md_type;
12961289
}
12971290

12981291
/* setup md->queue to reflect md's type (may block) */
12991292
r = dm_setup_md_queue(md);
13001293
if (r) {
13011294
DMWARN("unable to set up device queue for new table.");
1302-
dm_table_destroy(t);
1303-
dm_unlock_md_type(md);
1304-
goto out;
1295+
goto err_unlock_md_type;
13051296
}
13061297
dm_unlock_md_type(md);
13071298

@@ -1311,9 +1302,8 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
13111302
if (!hc || hc->md != md) {
13121303
DMWARN("device has been removed from the dev hash table.");
13131304
up_write(&_hash_lock);
1314-
dm_table_destroy(t);
13151305
r = -ENXIO;
1316-
goto out;
1306+
goto err_destroy_table;
13171307
}
13181308

13191309
if (hc->new_map)
@@ -1324,14 +1314,22 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
13241314
param->flags |= DM_INACTIVE_PRESENT_FLAG;
13251315
__dev_status(md, param);
13261316

1327-
out:
13281317
if (old_map) {
13291318
dm_sync_table(md);
13301319
dm_table_destroy(old_map);
13311320
}
13321321

13331322
dm_put(md);
13341323

1324+
return 0;
1325+
1326+
err_unlock_md_type:
1327+
dm_unlock_md_type(md);
1328+
err_destroy_table:
1329+
dm_table_destroy(t);
1330+
err:
1331+
dm_put(md);
1332+
13351333
return r;
13361334
}
13371335

0 commit comments

Comments
 (0)