dm: core: Create a new header file for 'compat' features
[oweals/u-boot.git] / fs / ubifs / ubifs.c
index db29489eca7517c4a21151fcd91dbdc53b270dfc..e097d284444959c857996b40d1b5b6bc6a515f23 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * This file is part of UBIFS.
  *
@@ -8,15 +9,18 @@
  *
  * Authors: Artem Bityutskiy (Битюцкий Артём)
  *          Adrian Hunter
- *
- * SPDX-License-Identifier:    GPL-2.0
  */
 
 #include <common.h>
+#include <env.h>
+#include <gzip.h>
+#include <malloc.h>
 #include <memalign.h>
 #include "ubifs.h"
+#include <dm/devres.h>
 #include <u-boot/zlib.h>
 
+#include <linux/compat.h>
 #include <linux/err.h>
 #include <linux/lzo.h>
 
@@ -69,24 +73,6 @@ struct ubifs_compressor *ubifs_compressors[UBIFS_COMPR_TYPES_CNT];
 
 
 #ifdef __UBOOT__
-/* from mm/util.c */
-
-/**
- * kmemdup - duplicate region of memory
- *
- * @src: memory region to duplicate
- * @len: memory region length
- * @gfp: GFP mask to use
- */
-void *kmemdup(const void *src, size_t len, gfp_t gfp)
-{
-       void *p;
-
-       p = kmalloc(len, gfp);
-       if (p)
-               memcpy(p, src, len);
-       return p;
-}
 
 struct crypto_comp {
        int compressor;
@@ -126,6 +112,7 @@ crypto_comp_decompress(const struct ubifs_info *c, struct crypto_comp *tfm,
 {
        struct ubifs_compressor *compr = ubifs_compressors[tfm->compressor];
        int err;
+       size_t tmp_len = *dlen;
 
        if (compr->compr_type == UBIFS_COMPR_NONE) {
                memcpy(dst, src, slen);
@@ -133,11 +120,12 @@ crypto_comp_decompress(const struct ubifs_info *c, struct crypto_comp *tfm,
                return 0;
        }
 
-       err = compr->decompress(src, slen, dst, (size_t *)dlen);
+       err = compr->decompress(src, slen, dst, &tmp_len);
        if (err)
                ubifs_err(c, "cannot decompress %d bytes, compressor %s, "
                          "error %d", slen, compr->name, err);
 
+       *dlen = tmp_len;
        return err;
 
        return 0;
@@ -350,7 +338,9 @@ static int ubifs_printdir(struct file *file, void *dirent)
                dbg_gen("feed '%s', ino %llu, new f_pos %#x",
                        dent->name, (unsigned long long)le64_to_cpu(dent->inum),
                        key_hash_flash(c, &dent->key));
+#ifndef __UBOOT__
                ubifs_assert(le64_to_cpu(dent->ch.sqnum) > ubifs_inode(dir)->creat_sqnum);
+#endif
 
                nm.len = le16_to_cpu(dent->nlen);
                over = filldir(c, (char *)dent->name, nm.len,
@@ -432,7 +422,9 @@ static int ubifs_finddir(struct super_block *sb, char *dirname,
                dbg_gen("feed '%s', ino %llu, new f_pos %#x",
                        dent->name, (unsigned long long)le64_to_cpu(dent->inum),
                        key_hash_flash(c, &dent->key));
+#ifndef __UBOOT__
                ubifs_assert(le64_to_cpu(dent->ch.sqnum) > ubifs_inode(dir)->creat_sqnum);
+#endif
 
                nm.len = le16_to_cpu(dent->nlen);
                if ((strncmp(dirname, (char *)dent->name, nm.len) == 0) &&
@@ -462,14 +454,10 @@ out:
                dbg_gen("cannot find next direntry, error %d", err);
 
 out_free:
-       if (file->private_data)
-               kfree(file->private_data);
-       if (file)
-               free(file);
-       if (dentry)
-               free(dentry);
-       if (dir)
-               free(dir);
+       kfree(file->private_data);
+       free(file);
+       free(dentry);
+       free(dir);
 
        return ret;
 }
@@ -941,7 +929,7 @@ int ubifs_load(char *filename, u32 addr, u32 size)
 
        err = ubifs_read(filename, (void *)(uintptr_t)addr, 0, size, &actread);
        if (err == 0) {
-               setenv_hex("filesize", actread);
+               env_set_hex("filesize", actread);
                printf("Done\n");
        }