Commit f11c1c5693fac339d412b0b59b54693ddcb776ff

Authored by Mike Snitzer
1 parent 00c4fc3b1f

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>

Showing 1 changed file with 16 additions and 18 deletions Side-by-side Diff

drivers/md/dm-ioctl.c
... ... @@ -1262,26 +1262,21 @@
1262 1262  
1263 1263 r = dm_table_create(&t, get_mode(param), param->target_count, md);
1264 1264 if (r)
1265   - goto out;
  1265 + goto err;
1266 1266  
1267 1267 /* Protect md->type and md->queue against concurrent table loads. */
1268 1268 dm_lock_md_type(md);
1269 1269 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;
1275 1272  
1276 1273 immutable_target_type = dm_get_immutable_target_type(md);
1277 1274 if (immutable_target_type &&
1278 1275 (immutable_target_type != dm_table_get_immutable_target_type(t))) {
1279 1276 DMWARN("can't replace immutable target type %s",
1280 1277 immutable_target_type->name);
1281   - dm_table_destroy(t);
1282   - dm_unlock_md_type(md);
1283 1278 r = -EINVAL;
1284   - goto out;
  1279 + goto err_unlock_md_type;
1285 1280 }
1286 1281  
1287 1282 if (dm_get_md_type(md) == DM_TYPE_NONE)
1288 1283  
1289 1284  
... ... @@ -1289,19 +1284,15 @@
1289 1284 dm_set_md_type(md, dm_table_get_type(t));
1290 1285 else if (dm_get_md_type(md) != dm_table_get_type(t)) {
1291 1286 DMWARN("can't change device type after initial table load.");
1292   - dm_table_destroy(t);
1293   - dm_unlock_md_type(md);
1294 1287 r = -EINVAL;
1295   - goto out;
  1288 + goto err_unlock_md_type;
1296 1289 }
1297 1290  
1298 1291 /* setup md->queue to reflect md's type (may block) */
1299 1292 r = dm_setup_md_queue(md);
1300 1293 if (r) {
1301 1294 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;
1305 1296 }
1306 1297 dm_unlock_md_type(md);
1307 1298  
1308 1299  
... ... @@ -1311,9 +1302,8 @@
1311 1302 if (!hc || hc->md != md) {
1312 1303 DMWARN("device has been removed from the dev hash table.");
1313 1304 up_write(&_hash_lock);
1314   - dm_table_destroy(t);
1315 1305 r = -ENXIO;
1316   - goto out;
  1306 + goto err_destroy_table;
1317 1307 }
1318 1308  
1319 1309 if (hc->new_map)
1320 1310  
... ... @@ -1324,12 +1314,20 @@
1324 1314 param->flags |= DM_INACTIVE_PRESENT_FLAG;
1325 1315 __dev_status(md, param);
1326 1316  
1327   -out:
1328 1317 if (old_map) {
1329 1318 dm_sync_table(md);
1330 1319 dm_table_destroy(old_map);
1331 1320 }
1332 1321  
  1322 + dm_put(md);
  1323 +
  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:
1333 1331 dm_put(md);
1334 1332  
1335 1333 return r;