dm: core: Require users of devres to include the header
[oweals/u-boot.git] / fs / ubifs / scan.c
index 6fc464bb4850dce5852895cadc9e98b18489067c..876a6ee6616b0eed2d7ff3d7371a528ed9fbf715 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,6 +16,8 @@
  */
 
 #ifdef __UBOOT__
+#include <hexdump.h>
+#include <dm/devres.h>
 #include <linux/err.h>
 #endif
 #include "ubifs.h"
@@ -92,7 +93,7 @@ int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
                if (pad_len < 0 ||
                    offs + node_len + pad_len > c->leb_size) {
                        if (!quiet) {
-                               ubifs_err("bad pad node at LEB %d:%d",
+                               ubifs_err(c, "bad pad node at LEB %d:%d",
                                          lnum, offs);
                                ubifs_dump_node(c, pad);
                        }
@@ -102,7 +103,7 @@ int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
                /* Make the node pads to 8-byte boundary */
                if ((node_len + pad_len) & 7) {
                        if (!quiet)
-                               ubifs_err("bad padding length %d - %d",
+                               ubifs_err(c, "bad padding length %d - %d",
                                          offs, offs + node_len + pad_len);
                        return SCANNED_A_BAD_PAD_NODE;
                }
@@ -123,7 +124,8 @@ int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
  * @offs: offset to start at (usually zero)
  * @sbuf: scan buffer (must be c->leb_size)
  *
- * This function returns %0 on success and a negative error code on failure.
+ * This function returns the scanned information on success and a negative error
+ * code on failure.
  */
 struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum,
                                        int offs, void *sbuf)
@@ -143,15 +145,16 @@ struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum,
 
        err = ubifs_leb_read(c, lnum, sbuf + offs, offs, c->leb_size - offs, 0);
        if (err && err != -EBADMSG) {
-               ubifs_err("cannot read %d bytes from LEB %d:%d, error %d",
+               ubifs_err(c, "cannot read %d bytes from LEB %d:%d, error %d",
                          c->leb_size - offs, lnum, offs, err);
                kfree(sleb);
                return ERR_PTR(err);
        }
 
-       if (err == -EBADMSG)
-               sleb->ecc = 1;
-
+       /*
+        * Note, we ignore integrity errors (EBASMSG) because all the nodes are
+        * protected by CRC checksums.
+        */
        return sleb;
 }
 
@@ -161,8 +164,6 @@ struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum,
  * @sleb: scanning information
  * @lnum: logical eraseblock number
  * @offs: offset to start at (usually zero)
- *
- * This function returns %0 on success and a negative error code on failure.
  */
 void ubifs_end_scan(const struct ubifs_info *c, struct ubifs_scan_leb *sleb,
                    int lnum, int offs)
@@ -232,12 +233,12 @@ void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs,
 {
        int len;
 
-       ubifs_err("corruption at LEB %d:%d", lnum, offs);
+       ubifs_err(c, "corruption at LEB %d:%d", lnum, offs);
        len = c->leb_size - offs;
        if (len > 8192)
                len = 8192;
-       ubifs_err("first %d bytes from LEB %d:%d", len, lnum, offs);
-       print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 4, buf, len, 1);
+       ubifs_err(c, "first %d bytes from LEB %d:%d", len, lnum, offs);
+       print_hex_dump("", DUMP_PREFIX_OFFSET, 32, 4, buf, len, 1);
 }
 
 /**
@@ -249,7 +250,7 @@ void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs,
  * @quiet: print no messages
  *
  * This function scans LEB number @lnum and returns complete information about
- * its contents. Returns the scaned information in case of success and,
+ * its contents. Returns the scanned information in case of success and,
  * %-EUCLEAN if the LEB neads recovery, and other negative error codes in case
  * of failure.
  *
@@ -291,16 +292,16 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
 
                switch (ret) {
                case SCANNED_GARBAGE:
-                       ubifs_err("garbage");
+                       ubifs_err(c, "garbage");
                        goto corrupted;
                case SCANNED_A_NODE:
                        break;
                case SCANNED_A_CORRUPT_NODE:
                case SCANNED_A_BAD_PAD_NODE:
-                       ubifs_err("bad node");
+                       ubifs_err(c, "bad node");
                        goto corrupted;
                default:
-                       ubifs_err("unknown");
+                       ubifs_err(c, "unknown");
                        err = -EINVAL;
                        goto error;
                }
@@ -317,7 +318,7 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
 
        if (offs % c->min_io_size) {
                if (!quiet)
-                       ubifs_err("empty space starts at non-aligned offset %d",
+                       ubifs_err(c, "empty space starts at non-aligned offset %d",
                                  offs);
                goto corrupted;
        }
@@ -330,7 +331,7 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
        for (; len; offs++, buf++, len--)
                if (*(uint8_t *)buf != 0xff) {
                        if (!quiet)
-                               ubifs_err("corrupt empty space at LEB %d:%d",
+                               ubifs_err(c, "corrupt empty space at LEB %d:%d",
                                          lnum, offs);
                        goto corrupted;
                }
@@ -340,14 +341,14 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
 corrupted:
        if (!quiet) {
                ubifs_scanned_corruption(c, lnum, offs, buf);
-               ubifs_err("LEB %d scanning failed", lnum);
+               ubifs_err(c, "LEB %d scanning failed", lnum);
        }
        err = -EUCLEAN;
        ubifs_scan_destroy(sleb);
        return ERR_PTR(err);
 
 error:
-       ubifs_err("LEB %d scanning failed, error %d", lnum, err);
+       ubifs_err(c, "LEB %d scanning failed, error %d", lnum, err);
        ubifs_scan_destroy(sleb);
        return ERR_PTR(err);
 }