aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/vmt.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/ubi/vmt.c')
-rw-r--r--drivers/mtd/ubi/vmt.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index d2d12deead5c..ec2dd3c65c43 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -201,8 +201,8 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
201 if (!vol) 201 if (!vol)
202 return -ENOMEM; 202 return -ENOMEM;
203 203
204 mutex_lock(&ubi->volumes_mutex);
204 spin_lock(&ubi->volumes_lock); 205 spin_lock(&ubi->volumes_lock);
205
206 if (vol_id == UBI_VOL_NUM_AUTO) { 206 if (vol_id == UBI_VOL_NUM_AUTO) {
207 /* Find unused volume ID */ 207 /* Find unused volume ID */
208 dbg_msg("search for vacant volume ID"); 208 dbg_msg("search for vacant volume ID");
@@ -350,6 +350,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
350 spin_unlock(&ubi->volumes_lock); 350 spin_unlock(&ubi->volumes_lock);
351 351
352 paranoid_check_volumes(ubi); 352 paranoid_check_volumes(ubi);
353 mutex_unlock(&ubi->volumes_mutex);
353 return 0; 354 return 0;
354 355
355out_gluebi: 356out_gluebi:
@@ -365,6 +366,7 @@ out_acc:
365 ubi->volumes[vol_id] = NULL; 366 ubi->volumes[vol_id] = NULL;
366out_unlock: 367out_unlock:
367 spin_unlock(&ubi->volumes_lock); 368 spin_unlock(&ubi->volumes_lock);
369 mutex_unlock(&ubi->volumes_mutex);
368 kfree(vol); 370 kfree(vol);
369 ubi_err("cannot create volume %d, error %d", vol_id, err); 371 ubi_err("cannot create volume %d, error %d", vol_id, err);
370 return err; 372 return err;
@@ -382,6 +384,7 @@ out_sysfs:
382 ubi->avail_pebs += vol->reserved_pebs; 384 ubi->avail_pebs += vol->reserved_pebs;
383 ubi->volumes[vol_id] = NULL; 385 ubi->volumes[vol_id] = NULL;
384 spin_unlock(&ubi->volumes_lock); 386 spin_unlock(&ubi->volumes_lock);
387 mutex_unlock(&ubi->volumes_mutex);
385 volume_sysfs_close(vol); 388 volume_sysfs_close(vol);
386 ubi_err("cannot create volume %d, error %d", vol_id, err); 389 ubi_err("cannot create volume %d, error %d", vol_id, err);
387 return err; 390 return err;
@@ -408,18 +411,19 @@ int ubi_remove_volume(struct ubi_volume_desc *desc)
408 if (ubi->ro_mode) 411 if (ubi->ro_mode)
409 return -EROFS; 412 return -EROFS;
410 413
414 mutex_lock(&ubi->volumes_mutex);
411 err = ubi_destroy_gluebi(vol); 415 err = ubi_destroy_gluebi(vol);
412 if (err) 416 if (err)
413 return err; 417 goto out;
414 418
415 err = ubi_change_vtbl_record(ubi, vol_id, NULL); 419 err = ubi_change_vtbl_record(ubi, vol_id, NULL);
416 if (err) 420 if (err)
417 return err; 421 goto out;
418 422
419 for (i = 0; i < vol->reserved_pebs; i++) { 423 for (i = 0; i < vol->reserved_pebs; i++) {
420 err = ubi_eba_unmap_leb(ubi, vol, i); 424 err = ubi_eba_unmap_leb(ubi, vol, i);
421 if (err) 425 if (err)
422 return err; 426 goto out;
423 } 427 }
424 428
425 spin_lock(&ubi->volumes_lock); 429 spin_lock(&ubi->volumes_lock);
@@ -449,8 +453,13 @@ int ubi_remove_volume(struct ubi_volume_desc *desc)
449 spin_unlock(&ubi->volumes_lock); 453 spin_unlock(&ubi->volumes_lock);
450 454
451 paranoid_check_volumes(ubi); 455 paranoid_check_volumes(ubi);
456 mutex_unlock(&ubi->volumes_mutex);
452 module_put(THIS_MODULE); 457 module_put(THIS_MODULE);
453 return 0; 458 return 0;
459
460out:
461 mutex_unlock(&ubi->volumes_mutex);
462 return err;
454} 463}
455 464
456/** 465/**
@@ -496,6 +505,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
496 new_mapping[i] = UBI_LEB_UNMAPPED; 505 new_mapping[i] = UBI_LEB_UNMAPPED;
497 506
498 /* Reserve physical eraseblocks */ 507 /* Reserve physical eraseblocks */
508 mutex_lock(&ubi->volumes_mutex);
499 pebs = reserved_pebs - vol->reserved_pebs; 509 pebs = reserved_pebs - vol->reserved_pebs;
500 if (pebs > 0) { 510 if (pebs > 0) {
501 spin_lock(&ubi->volumes_lock); 511 spin_lock(&ubi->volumes_lock);
@@ -556,6 +566,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
556 } 566 }
557 567
558 paranoid_check_volumes(ubi); 568 paranoid_check_volumes(ubi);
569 mutex_unlock(&ubi->volumes_mutex);
559 return 0; 570 return 0;
560 571
561out_acc: 572out_acc:
@@ -567,6 +578,7 @@ out_acc:
567 } 578 }
568out_free: 579out_free:
569 kfree(new_mapping); 580 kfree(new_mapping);
581 mutex_unlock(&ubi->volumes_mutex);
570 return err; 582 return err;
571} 583}
572 584
@@ -829,9 +841,7 @@ static void paranoid_check_volumes(struct ubi_device *ubi)
829{ 841{
830 int i; 842 int i;
831 843
832 mutex_lock(&ubi->vtbl_mutex);
833 for (i = 0; i < ubi->vtbl_slots; i++) 844 for (i = 0; i < ubi->vtbl_slots; i++)
834 paranoid_check_volume(ubi, i); 845 paranoid_check_volume(ubi, i);
835 mutex_unlock(&ubi->vtbl_mutex);
836} 846}
837#endif 847#endif