Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+16 -18
+16 -18
drivers/md/dm-ioctl.c
··· 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) ··· 1284 1289 dm_set_md_type(md, dm_table_get_type(t)); 1285 1290 else if (dm_get_md_type(md) != dm_table_get_type(t)) { 1286 1291 DMWARN("can't change device type after initial table load."); 1287 - dm_table_destroy(t); 1288 - dm_unlock_md_type(md); 1289 1292 r = -EINVAL; 1290 - goto out; 1293 + goto err_unlock_md_type; 1291 1294 } 1292 1295 1293 1296 /* setup md->queue to reflect md's type (may block) */ 1294 1297 r = dm_setup_md_queue(md); 1295 1298 if (r) { 1296 1299 DMWARN("unable to set up device queue for new table."); 1297 - dm_table_destroy(t); 1298 - dm_unlock_md_type(md); 1299 - goto out; 1300 + goto err_unlock_md_type; 1300 1301 } 1301 1302 dm_unlock_md_type(md); 1302 1303 ··· 1302 1311 if (!hc || hc->md != md) { 1303 1312 DMWARN("device has been removed from the dev hash table."); 1304 1313 up_write(&_hash_lock); 1305 - dm_table_destroy(t); 1306 1314 r = -ENXIO; 1307 - goto out; 1315 + goto err_destroy_table; 1308 1316 } 1309 1317 1310 1318 if (hc->new_map) ··· 1314 1324 param->flags |= DM_INACTIVE_PRESENT_FLAG; 1315 1325 __dev_status(md, param); 1316 1326 1317 - out: 1318 1327 if (old_map) { 1319 1328 dm_sync_table(md); 1320 1329 dm_table_destroy(old_map); 1321 1330 } 1322 1331 1332 + dm_put(md); 1333 + 1334 + return 0; 1335 + 1336 + err_unlock_md_type: 1337 + dm_unlock_md_type(md); 1338 + err_destroy_table: 1339 + dm_table_destroy(t); 1340 + err: 1323 1341 dm_put(md); 1324 1342 1325 1343 return r;