fs: ext4: Fix alignment of cache buffers
[oweals/u-boot.git] / fs / ubifs / lprops.c
index fc6686bb08b14f52a7fef241d7811764552a6897..a7c45dd5ecb045a58ce1ef6d7d83af7fac692875 100644 (file)
@@ -1,10 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * This file is part of UBIFS.
  *
  * Copyright (C) 2006-2008 Nokia Corporation.
  *
- * SPDX-License-Identifier:    GPL-2.0+
- *
  * Authors: Adrian Hunter
  *          Artem Bityutskiy (Битюцкий Артём)
  */
@@ -17,8 +16,8 @@
  * an empty LEB for the journal, or a very dirty LEB for garbage collection.
  */
 
-#define __UBOOT__
 #ifdef __UBOOT__
+#include <malloc.h>
 #include <linux/err.h>
 #endif
 #include "ubifs.h"
@@ -675,7 +674,7 @@ int ubifs_change_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
 out:
        ubifs_release_lprops(c);
        if (err)
-               ubifs_err("cannot change properties of LEB %d, error %d",
+               ubifs_err(c, "cannot change properties of LEB %d, error %d",
                          lnum, err);
        return err;
 }
@@ -714,7 +713,7 @@ int ubifs_update_one_lp(struct ubifs_info *c, int lnum, int free, int dirty,
 out:
        ubifs_release_lprops(c);
        if (err)
-               ubifs_err("cannot update properties of LEB %d, error %d",
+               ubifs_err(c, "cannot update properties of LEB %d, error %d",
                          lnum, err);
        return err;
 }
@@ -739,7 +738,7 @@ int ubifs_read_one_lp(struct ubifs_info *c, int lnum, struct ubifs_lprops *lp)
        lpp = ubifs_lpt_lookup(c, lnum);
        if (IS_ERR(lpp)) {
                err = PTR_ERR(lpp);
-               ubifs_err("cannot read properties of LEB %d, error %d",
+               ubifs_err(c, "cannot read properties of LEB %d, error %d",
                          lnum, err);
                goto out;
        }
@@ -866,13 +865,13 @@ int dbg_check_cats(struct ubifs_info *c)
 
        list_for_each_entry(lprops, &c->empty_list, list) {
                if (lprops->free != c->leb_size) {
-                       ubifs_err("non-empty LEB %d on empty list (free %d dirty %d flags %d)",
+                       ubifs_err(c, "non-empty LEB %d on empty list (free %d dirty %d flags %d)",
                                  lprops->lnum, lprops->free, lprops->dirty,
                                  lprops->flags);
                        return -EINVAL;
                }
                if (lprops->flags & LPROPS_TAKEN) {
-                       ubifs_err("taken LEB %d on empty list (free %d dirty %d flags %d)",
+                       ubifs_err(c, "taken LEB %d on empty list (free %d dirty %d flags %d)",
                                  lprops->lnum, lprops->free, lprops->dirty,
                                  lprops->flags);
                        return -EINVAL;
@@ -882,13 +881,13 @@ int dbg_check_cats(struct ubifs_info *c)
        i = 0;
        list_for_each_entry(lprops, &c->freeable_list, list) {
                if (lprops->free + lprops->dirty != c->leb_size) {
-                       ubifs_err("non-freeable LEB %d on freeable list (free %d dirty %d flags %d)",
+                       ubifs_err(c, "non-freeable LEB %d on freeable list (free %d dirty %d flags %d)",
                                  lprops->lnum, lprops->free, lprops->dirty,
                                  lprops->flags);
                        return -EINVAL;
                }
                if (lprops->flags & LPROPS_TAKEN) {
-                       ubifs_err("taken LEB %d on freeable list (free %d dirty %d flags %d)",
+                       ubifs_err(c, "taken LEB %d on freeable list (free %d dirty %d flags %d)",
                                  lprops->lnum, lprops->free, lprops->dirty,
                                  lprops->flags);
                        return -EINVAL;
@@ -896,7 +895,7 @@ int dbg_check_cats(struct ubifs_info *c)
                i += 1;
        }
        if (i != c->freeable_cnt) {
-               ubifs_err("freeable list count %d expected %d", i,
+               ubifs_err(c, "freeable list count %d expected %d", i,
                          c->freeable_cnt);
                return -EINVAL;
        }
@@ -905,26 +904,26 @@ int dbg_check_cats(struct ubifs_info *c)
        list_for_each(pos, &c->idx_gc)
                i += 1;
        if (i != c->idx_gc_cnt) {
-               ubifs_err("idx_gc list count %d expected %d", i,
+               ubifs_err(c, "idx_gc list count %d expected %d", i,
                          c->idx_gc_cnt);
                return -EINVAL;
        }
 
        list_for_each_entry(lprops, &c->frdi_idx_list, list) {
                if (lprops->free + lprops->dirty != c->leb_size) {
-                       ubifs_err("non-freeable LEB %d on frdi_idx list (free %d dirty %d flags %d)",
+                       ubifs_err(c, "non-freeable LEB %d on frdi_idx list (free %d dirty %d flags %d)",
                                  lprops->lnum, lprops->free, lprops->dirty,
                                  lprops->flags);
                        return -EINVAL;
                }
                if (lprops->flags & LPROPS_TAKEN) {
-                       ubifs_err("taken LEB %d on frdi_idx list (free %d dirty %d flags %d)",
+                       ubifs_err(c, "taken LEB %d on frdi_idx list (free %d dirty %d flags %d)",
                                  lprops->lnum, lprops->free, lprops->dirty,
                                  lprops->flags);
                        return -EINVAL;
                }
                if (!(lprops->flags & LPROPS_INDEX)) {
-                       ubifs_err("non-index LEB %d on frdi_idx list (free %d dirty %d flags %d)",
+                       ubifs_err(c, "non-index LEB %d on frdi_idx list (free %d dirty %d flags %d)",
                                  lprops->lnum, lprops->free, lprops->dirty,
                                  lprops->flags);
                        return -EINVAL;
@@ -937,15 +936,15 @@ int dbg_check_cats(struct ubifs_info *c)
                for (i = 0; i < heap->cnt; i++) {
                        lprops = heap->arr[i];
                        if (!lprops) {
-                               ubifs_err("null ptr in LPT heap cat %d", cat);
+                               ubifs_err(c, "null ptr in LPT heap cat %d", cat);
                                return -EINVAL;
                        }
                        if (lprops->hpos != i) {
-                               ubifs_err("bad ptr in LPT heap cat %d", cat);
+                               ubifs_err(c, "bad ptr in LPT heap cat %d", cat);
                                return -EINVAL;
                        }
                        if (lprops->flags & LPROPS_TAKEN) {
-                               ubifs_err("taken LEB in LPT heap cat %d", cat);
+                               ubifs_err(c, "taken LEB in LPT heap cat %d", cat);
                                return -EINVAL;
                        }
                }
@@ -981,7 +980,7 @@ void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat,
                        goto out;
                }
                if (lprops != lp) {
-                       ubifs_err("lprops %zx lp %zx lprops->lnum %d lp->lnum %d",
+                       ubifs_err(c, "lprops %zx lp %zx lprops->lnum %d lp->lnum %d",
                                  (size_t)lprops, (size_t)lp, lprops->lnum,
                                  lp->lnum);
                        err = 4;
@@ -1001,7 +1000,7 @@ void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat,
        }
 out:
        if (err) {
-               ubifs_err("failed cat %d hpos %d err %d", cat, i, err);
+               ubifs_err(c, "failed cat %d hpos %d err %d", cat, i, err);
                dump_stack();
                ubifs_dump_heap(c, heap, cat);
        }
@@ -1025,14 +1024,14 @@ static int scan_check_cb(struct ubifs_info *c,
 {
        struct ubifs_scan_leb *sleb;
        struct ubifs_scan_node *snod;
-       int cat, lnum = lp->lnum, is_idx = 0, used = 0, freef, dirty, ret;
+       int cat, lnum = lp->lnum, is_idx = 0, used = 0, free, dirty, ret;
        void *buf = NULL;
 
        cat = lp->flags & LPROPS_CAT_MASK;
        if (cat != LPROPS_UNCAT) {
                cat = ubifs_categorize_lprops(c, lp);
                if (cat != (lp->flags & LPROPS_CAT_MASK)) {
-                       ubifs_err("bad LEB category %d expected %d",
+                       ubifs_err(c, "bad LEB category %d expected %d",
                                  (lp->flags & LPROPS_CAT_MASK), cat);
                        return -EINVAL;
                }
@@ -1067,7 +1066,7 @@ static int scan_check_cb(struct ubifs_info *c,
                                }
                        }
                        if (!found) {
-                               ubifs_err("bad LPT list (category %d)", cat);
+                               ubifs_err(c, "bad LPT list (category %d)", cat);
                                return -EINVAL;
                        }
                }
@@ -1079,7 +1078,7 @@ static int scan_check_cb(struct ubifs_info *c,
 
                if ((lp->hpos != -1 && heap->arr[lp->hpos]->lnum != lnum) ||
                    lp != heap->arr[lp->hpos]) {
-                       ubifs_err("bad LPT heap (category %d)", cat);
+                       ubifs_err(c, "bad LPT heap (category %d)", cat);
                        return -EINVAL;
                }
        }
@@ -1126,7 +1125,7 @@ static int scan_check_cb(struct ubifs_info *c,
                        is_idx = (snod->type == UBIFS_IDX_NODE) ? 1 : 0;
 
                if (is_idx && snod->type != UBIFS_IDX_NODE) {
-                       ubifs_err("indexing node in data LEB %d:%d",
+                       ubifs_err(c, "indexing node in data LEB %d:%d",
                                  lnum, snod->offs);
                        goto out_destroy;
                }
@@ -1147,20 +1146,20 @@ static int scan_check_cb(struct ubifs_info *c,
                }
        }
 
-       freef = c->leb_size - sleb->endpt;
+       free = c->leb_size - sleb->endpt;
        dirty = sleb->endpt - used;
 
-       if (freef > c->leb_size || freef < 0 || dirty > c->leb_size ||
+       if (free > c->leb_size || free < 0 || dirty > c->leb_size ||
            dirty < 0) {
-               ubifs_err("bad calculated accounting for LEB %d: free %d, dirty %d",
-                         lnum, freef, dirty);
+               ubifs_err(c, "bad calculated accounting for LEB %d: free %d, dirty %d",
+                         lnum, free, dirty);
                goto out_destroy;
        }
 
        if (lp->free + lp->dirty == c->leb_size &&
-           freef + dirty == c->leb_size)
+           free + dirty == c->leb_size)
                if ((is_idx && !(lp->flags & LPROPS_INDEX)) ||
-                   (!is_idx && freef == c->leb_size) ||
+                   (!is_idx && free == c->leb_size) ||
                    lp->free == c->leb_size) {
                        /*
                         * Empty or freeable LEBs could contain index
@@ -1169,12 +1168,12 @@ static int scan_check_cb(struct ubifs_info *c,
                         * the same reason. Or it may simply not have been
                         * unmapped.
                         */
-                       freef = lp->free;
+                       free = lp->free;
                        dirty = lp->dirty;
                        is_idx = 0;
                    }
 
-       if (is_idx && lp->free + lp->dirty == freef + dirty &&
+       if (is_idx && lp->free + lp->dirty == free + dirty &&
            lnum != c->ihead_lnum) {
                /*
                 * After an unclean unmount, an index LEB could have a different
@@ -1187,41 +1186,41 @@ static int scan_check_cb(struct ubifs_info *c,
                 * write to the free space at the end of an index LEB - except
                 * by the in-the-gaps method for which it is not a problem.
                 */
-               freef = lp->free;
+               free = lp->free;
                dirty = lp->dirty;
        }
 
-       if (lp->free != freef || lp->dirty != dirty)
+       if (lp->free != free || lp->dirty != dirty)
                goto out_print;
 
        if (is_idx && !(lp->flags & LPROPS_INDEX)) {
-               if (freef == c->leb_size)
+               if (free == c->leb_size)
                        /* Free but not unmapped LEB, it's fine */
                        is_idx = 0;
                else {
-                       ubifs_err("indexing node without indexing flag");
+                       ubifs_err(c, "indexing node without indexing flag");
                        goto out_print;
                }
        }
 
        if (!is_idx && (lp->flags & LPROPS_INDEX)) {
-               ubifs_err("data node with indexing flag");
+               ubifs_err(c, "data node with indexing flag");
                goto out_print;
        }
 
-       if (freef == c->leb_size)
+       if (free == c->leb_size)
                lst->empty_lebs += 1;
 
        if (is_idx)
                lst->idx_lebs += 1;
 
        if (!(lp->flags & LPROPS_INDEX))
-               lst->total_used += c->leb_size - freef - dirty;
-       lst->total_free += freef;
+               lst->total_used += c->leb_size - free - dirty;
+       lst->total_free += free;
        lst->total_dirty += dirty;
 
        if (!(lp->flags & LPROPS_INDEX)) {
-               int spc = freef + dirty;
+               int spc = free + dirty;
 
                if (spc < c->dead_wm)
                        lst->total_dead += spc;
@@ -1234,8 +1233,8 @@ static int scan_check_cb(struct ubifs_info *c,
        return LPT_SCAN_CONTINUE;
 
 out_print:
-       ubifs_err("bad accounting of LEB %d: free %d, dirty %d flags %#x, should be free %d, dirty %d",
-                 lnum, lp->free, lp->dirty, lp->flags, freef, dirty);
+       ubifs_err(c, "bad accounting of LEB %d: free %d, dirty %d flags %#x, should be free %d, dirty %d",
+                 lnum, lp->free, lp->dirty, lp->flags, free, dirty);
        ubifs_dump_leb(c, lnum);
 out_destroy:
        ubifs_scan_destroy(sleb);
@@ -1286,11 +1285,11 @@ int dbg_check_lprops(struct ubifs_info *c)
            lst.total_free != c->lst.total_free ||
            lst.total_dirty != c->lst.total_dirty ||
            lst.total_used != c->lst.total_used) {
-               ubifs_err("bad overall accounting");
-               ubifs_err("calculated: empty_lebs %d, idx_lebs %d, total_free %lld, total_dirty %lld, total_used %lld",
+               ubifs_err(c, "bad overall accounting");
+               ubifs_err(c, "calculated: empty_lebs %d, idx_lebs %d, total_free %lld, total_dirty %lld, total_used %lld",
                          lst.empty_lebs, lst.idx_lebs, lst.total_free,
                          lst.total_dirty, lst.total_used);
-               ubifs_err("read from lprops: empty_lebs %d, idx_lebs %d, total_free %lld, total_dirty %lld, total_used %lld",
+               ubifs_err(c, "read from lprops: empty_lebs %d, idx_lebs %d, total_free %lld, total_dirty %lld, total_used %lld",
                          c->lst.empty_lebs, c->lst.idx_lebs, c->lst.total_free,
                          c->lst.total_dirty, c->lst.total_used);
                err = -EINVAL;
@@ -1299,10 +1298,10 @@ int dbg_check_lprops(struct ubifs_info *c)
 
        if (lst.total_dead != c->lst.total_dead ||
            lst.total_dark != c->lst.total_dark) {
-               ubifs_err("bad dead/dark space accounting");
-               ubifs_err("calculated: total_dead %lld, total_dark %lld",
+               ubifs_err(c, "bad dead/dark space accounting");
+               ubifs_err(c, "calculated: total_dead %lld, total_dark %lld",
                          lst.total_dead, lst.total_dark);
-               ubifs_err("read from lprops: total_dead %lld, total_dark %lld",
+               ubifs_err(c, "read from lprops: total_dead %lld, total_dark %lld",
                          c->lst.total_dead, c->lst.total_dark);
                err = -EINVAL;
                goto out;