UBI: Fastmap: Calc fastmap size correctly
[sfrench/cifs-2.6.git] / drivers / mtd / ubi / wl.c
index 0f3425dac91046300f93587d4f341e080c98e322..6654f191868e59e264270c89942cffad41fba982 100644 (file)
@@ -272,7 +272,7 @@ static int produce_free_peb(struct ubi_device *ubi)
 {
        int err;
 
-       while (!ubi->free.rb_node) {
+       while (!ubi->free.rb_node && ubi->works_count) {
                spin_unlock(&ubi->wl_lock);
 
                dbg_wl("do one work synchronously");
@@ -835,7 +835,7 @@ repeat:
  * @wrk: the work to schedule
  *
  * This function adds a work defined by @wrk to the tail of the pending works
- * list. Can only be used of ubi->work_sem is already held in read mode!
+ * list. Can only be used if ubi->work_sem is already held in read mode!
  */
 static void __schedule_ubi_work(struct ubi_device *ubi, struct ubi_work *wrk)
 {
@@ -864,7 +864,7 @@ static void schedule_ubi_work(struct ubi_device *ubi, struct ubi_work *wrk)
 }
 
 static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
-                       int cancel);
+                       int shutdown);
 
 #ifdef CONFIG_MTD_UBI_FASTMAP
 /**
@@ -990,14 +990,15 @@ int ubi_wl_put_fm_peb(struct ubi_device *ubi, struct ubi_wl_entry *fm_e,
  * wear_leveling_worker - wear-leveling worker function.
  * @ubi: UBI device description object
  * @wrk: the work object
- * @cancel: non-zero if the worker has to free memory and exit
+ * @shutdown: non-zero if the worker has to free memory and exit
+ * because the WL-subsystem is shutting down
  *
  * This function copies a more worn out physical eraseblock to a less worn out
  * one. Returns zero in case of success and a negative error code in case of
  * failure.
  */
 static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
-                               int cancel)
+                               int shutdown)
 {
        int err, scrubbing = 0, torture = 0, protect = 0, erroneous = 0;
        int vol_id = -1, uninitialized_var(lnum);
@@ -1008,7 +1009,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk,
        struct ubi_vid_hdr *vid_hdr;
 
        kfree(wrk);
-       if (cancel)
+       if (shutdown)
                return 0;
 
        vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_NOFS);
@@ -1407,7 +1408,8 @@ int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
  * erase_worker - physical eraseblock erase worker function.
  * @ubi: UBI device description object
  * @wl_wrk: the work object
- * @cancel: non-zero if the worker has to free memory and exit
+ * @shutdown: non-zero if the worker has to free memory and exit
+ * because the WL sub-system is shutting down
  *
  * This function erases a physical eraseblock and perform torture testing if
  * needed. It also takes care about marking the physical eraseblock bad if
@@ -1415,7 +1417,7 @@ int ubi_ensure_anchor_pebs(struct ubi_device *ubi)
  * failure.
  */
 static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
-                       int cancel)
+                       int shutdown)
 {
        struct ubi_wl_entry *e = wl_wrk->e;
        int pnum = e->pnum;
@@ -1423,7 +1425,7 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
        int lnum = wl_wrk->lnum;
        int err, available_consumed = 0;
 
-       if (cancel) {
+       if (shutdown) {
                dbg_wl("cancel erasure of PEB %d EC %d", pnum, e->ec);
                kfree(wl_wrk);
                kmem_cache_free(ubi_wl_entry_slab, e);
@@ -1718,12 +1720,12 @@ int ubi_wl_flush(struct ubi_device *ubi, int vol_id, int lnum)
               vol_id, lnum, ubi->works_count);
 
        while (found) {
-               struct ubi_work *wrk;
+               struct ubi_work *wrk, *tmp;
                found = 0;
 
                down_read(&ubi->work_sem);
                spin_lock(&ubi->wl_lock);
-               list_for_each_entry(wrk, &ubi->works, list) {
+               list_for_each_entry_safe(wrk, tmp, &ubi->works, list) {
                        if ((vol_id == UBI_ALL || wrk->vol_id == vol_id) &&
                            (lnum == UBI_ALL || wrk->lnum == lnum)) {
                                list_del(&wrk->list);
@@ -1845,10 +1847,10 @@ int ubi_thread(void *u)
 }
 
 /**
- * cancel_pending - cancel all pending works.
+ * shutdown_work - shutdown all pending works.
  * @ubi: UBI device description object
  */
-static void cancel_pending(struct ubi_device *ubi)
+static void shutdown_work(struct ubi_device *ubi)
 {
        while (!list_empty(&ubi->works)) {
                struct ubi_work *wrk;
@@ -1997,7 +1999,7 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai)
        return 0;
 
 out_free:
-       cancel_pending(ubi);
+       shutdown_work(ubi);
        tree_destroy(&ubi->used);
        tree_destroy(&ubi->free);
        tree_destroy(&ubi->scrub);
@@ -2029,7 +2031,7 @@ static void protection_queue_destroy(struct ubi_device *ubi)
 void ubi_wl_close(struct ubi_device *ubi)
 {
        dbg_wl("close the WL sub-system");
-       cancel_pending(ubi);
+       shutdown_work(ubi);
        protection_queue_destroy(ubi);
        tree_destroy(&ubi->used);
        tree_destroy(&ubi->erroneous);