aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/ubi/eba.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/ubi/eba.c')
-rw-r--r--drivers/mtd/ubi/eba.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 85297cde4ac5..7ce91ca742b1 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -78,7 +78,7 @@ static unsigned long long next_sqnum(struct ubi_device *ubi)
78 */ 78 */
79static int ubi_get_compat(const struct ubi_device *ubi, int vol_id) 79static int ubi_get_compat(const struct ubi_device *ubi, int vol_id)
80{ 80{
81 if (vol_id == UBI_LAYOUT_VOL_ID) 81 if (vol_id == UBI_LAYOUT_VOLUME_ID)
82 return UBI_LAYOUT_VOLUME_COMPAT; 82 return UBI_LAYOUT_VOLUME_COMPAT;
83 return 0; 83 return 0;
84} 84}
@@ -137,10 +137,12 @@ static struct ubi_ltree_entry *ltree_add_entry(struct ubi_device *ubi,
137{ 137{
138 struct ubi_ltree_entry *le, *le1, *le_free; 138 struct ubi_ltree_entry *le, *le1, *le_free;
139 139
140 le = kmem_cache_alloc(ubi_ltree_slab, GFP_NOFS); 140 le = kmalloc(sizeof(struct ubi_ltree_entry), GFP_NOFS);
141 if (!le) 141 if (!le)
142 return ERR_PTR(-ENOMEM); 142 return ERR_PTR(-ENOMEM);
143 143
144 le->users = 0;
145 init_rwsem(&le->mutex);
144 le->vol_id = vol_id; 146 le->vol_id = vol_id;
145 le->lnum = lnum; 147 le->lnum = lnum;
146 148
@@ -188,7 +190,7 @@ static struct ubi_ltree_entry *ltree_add_entry(struct ubi_device *ubi,
188 spin_unlock(&ubi->ltree_lock); 190 spin_unlock(&ubi->ltree_lock);
189 191
190 if (le_free) 192 if (le_free)
191 kmem_cache_free(ubi_ltree_slab, le_free); 193 kfree(le_free);
192 194
193 return le; 195 return le;
194} 196}
@@ -236,7 +238,7 @@ static void leb_read_unlock(struct ubi_device *ubi, int vol_id, int lnum)
236 238
237 up_read(&le->mutex); 239 up_read(&le->mutex);
238 if (free) 240 if (free)
239 kmem_cache_free(ubi_ltree_slab, le); 241 kfree(le);
240} 242}
241 243
242/** 244/**
@@ -292,7 +294,7 @@ static int leb_write_trylock(struct ubi_device *ubi, int vol_id, int lnum)
292 free = 0; 294 free = 0;
293 spin_unlock(&ubi->ltree_lock); 295 spin_unlock(&ubi->ltree_lock);
294 if (free) 296 if (free)
295 kmem_cache_free(ubi_ltree_slab, le); 297 kfree(le);
296 298
297 return 1; 299 return 1;
298} 300}
@@ -321,7 +323,7 @@ static void leb_write_unlock(struct ubi_device *ubi, int vol_id, int lnum)
321 323
322 up_write(&le->mutex); 324 up_write(&le->mutex);
323 if (free) 325 if (free)
324 kmem_cache_free(ubi_ltree_slab, le); 326 kfree(le);
325} 327}
326 328
327/** 329/**
@@ -339,9 +341,6 @@ int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol,
339{ 341{
340 int err, pnum, vol_id = vol->vol_id; 342 int err, pnum, vol_id = vol->vol_id;
341 343
342 ubi_assert(ubi->ref_count > 0);
343 ubi_assert(vol->ref_count > 0);
344
345 if (ubi->ro_mode) 344 if (ubi->ro_mode)
346 return -EROFS; 345 return -EROFS;
347 346
@@ -390,9 +389,6 @@ int ubi_eba_read_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
390 struct ubi_vid_hdr *vid_hdr; 389 struct ubi_vid_hdr *vid_hdr;
391 uint32_t uninitialized_var(crc); 390 uint32_t uninitialized_var(crc);
392 391
393 ubi_assert(ubi->ref_count > 0);
394 ubi_assert(vol->ref_count > 0);
395
396 err = leb_read_lock(ubi, vol_id, lnum); 392 err = leb_read_lock(ubi, vol_id, lnum);
397 if (err) 393 if (err)
398 return err; 394 return err;
@@ -616,9 +612,6 @@ int ubi_eba_write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
616 int err, pnum, tries = 0, vol_id = vol->vol_id; 612 int err, pnum, tries = 0, vol_id = vol->vol_id;
617 struct ubi_vid_hdr *vid_hdr; 613 struct ubi_vid_hdr *vid_hdr;
618 614
619 ubi_assert(ubi->ref_count > 0);
620 ubi_assert(vol->ref_count > 0);
621
622 if (ubi->ro_mode) 615 if (ubi->ro_mode)
623 return -EROFS; 616 return -EROFS;
624 617
@@ -752,9 +745,6 @@ int ubi_eba_write_leb_st(struct ubi_device *ubi, struct ubi_volume *vol,
752 struct ubi_vid_hdr *vid_hdr; 745 struct ubi_vid_hdr *vid_hdr;
753 uint32_t crc; 746 uint32_t crc;
754 747
755 ubi_assert(ubi->ref_count > 0);
756 ubi_assert(vol->ref_count > 0);
757
758 if (ubi->ro_mode) 748 if (ubi->ro_mode)
759 return -EROFS; 749 return -EROFS;
760 750
@@ -869,12 +859,20 @@ int ubi_eba_atomic_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
869 struct ubi_vid_hdr *vid_hdr; 859 struct ubi_vid_hdr *vid_hdr;
870 uint32_t crc; 860 uint32_t crc;
871 861
872 ubi_assert(ubi->ref_count > 0);
873 ubi_assert(vol->ref_count > 0);
874
875 if (ubi->ro_mode) 862 if (ubi->ro_mode)
876 return -EROFS; 863 return -EROFS;
877 864
865 if (len == 0) {
866 /*
867 * Special case when data length is zero. In this case the LEB
868 * has to be unmapped and mapped somewhere else.
869 */
870 err = ubi_eba_unmap_leb(ubi, vol, lnum);
871 if (err)
872 return err;
873 return ubi_eba_write_leb(ubi, vol, lnum, NULL, 0, 0, dtype);
874 }
875
878 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS); 876 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS);
879 if (!vid_hdr) 877 if (!vid_hdr)
880 return -ENOMEM; 878 return -ENOMEM;