fdtdec: Add weak function to patch U-Boot DT right after fdtdec_setup()
[oweals/u-boot.git] / fs / zfs / zfs.c
index 1b73244c004732e3de0edbe717b650c3992e4908..1fec96cd5ce5a67171d1c66e1b0974870704571d 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  *
  * ZFS filesystem ported to u-boot by
@@ -7,23 +8,10 @@
  *     Copyright (C) 1999,2000,2001,2002,2003,2004
  *     Free Software Foundation, Inc.
  *     Copyright 2004  Sun Microsystems, Inc.
- *
- *     GRUB is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- *
- *     GRUB is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- *
- *     You should have received a copy of the GNU General Public License
- *     along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
- *
  */
 
 #include <common.h>
+#include <log.h>
 #include <malloc.h>
 #include <linux/stat.h>
 #include <linux/time.h>
@@ -32,7 +20,7 @@
 #include "zfs_common.h"
 #include "div64.h"
 
-block_dev_desc_t *zfs_dev_desc;
+struct blk_desc *zfs_dev_desc;
 
 /*
  * The zfs plug-in routines for GRUB are:
@@ -748,7 +736,7 @@ zap_hash(uint64_t salt, const char *name)
        uint64_t crc = salt;
 
        if (table[128] == 0) {
-               uint64_t *ct;
+               uint64_t *ct = NULL;
                int i, j;
                for (i = 0; i < 256; i++) {
                        for (ct = table + i, *ct = i, j = 8; j > 0; j--)
@@ -784,7 +772,7 @@ zap_leaf_array_equal(zap_leaf_phys_t *l, zfs_endian_t endian,
 
        while (bseen < array_len) {
                struct zap_leaf_array *la = &ZAP_LEAF_CHUNK(l, blksft, chunk).l_array;
-               int toread = MIN(array_len - bseen, ZAP_LEAF_ARRAY_BYTES);
+               int toread = min(array_len - bseen, ZAP_LEAF_ARRAY_BYTES);
 
                if (chunk >= ZAP_LEAF_NUMCHUNKS(blksft))
                        return 0;
@@ -806,7 +794,7 @@ zap_leaf_array_get(zap_leaf_phys_t *l, zfs_endian_t endian, int blksft,
 
        while (bseen < array_len) {
                struct zap_leaf_array *la = &ZAP_LEAF_CHUNK(l, blksft, chunk).l_array;
-               int toread = MIN(array_len - bseen, ZAP_LEAF_ARRAY_BYTES);
+               int toread = min(array_len - bseen, ZAP_LEAF_ARRAY_BYTES);
 
                if (chunk >= ZAP_LEAF_NUMCHUNKS(blksft))
                        /* Don't use errno because this error is to be ignored.  */
@@ -1072,6 +1060,7 @@ zap_lookup(dnode_end_t *zap_dnode, char *name, uint64_t *val,
        }
 
        printf("unknown ZAP type\n");
+       free(zapbuf);
        return ZFS_ERR_BAD_FS;
 }
 
@@ -1106,6 +1095,7 @@ zap_iterate(dnode_end_t *zap_dnode,
                return ret;
        }
        printf("unknown ZAP type\n");
+       free(zapbuf);
        return 0;
 }
 
@@ -1877,6 +1867,7 @@ zfs_mount(device_t dev)
 
        ubbest = malloc(sizeof(*ubbest));
        if (!ubbest) {
+               free(ub_array);
                zfs_unmount(data);
                return 0;
        }
@@ -1965,6 +1956,7 @@ zfs_mount(device_t dev)
        if (err) {
                printf("couldn't zio_read object directory\n");
                zfs_unmount(data);
+               free(osp);
                free(ubbest);
                return 0;
        }
@@ -2064,6 +2056,9 @@ zfs_open(struct zfs_file *file, const char *fsfilename)
 
                hdrsize = SA_HDR_SIZE(((sa_hdr_phys_t *) sahdrp));
                file->size = *(uint64_t *) ((char *) sahdrp + hdrsize + SA_SIZE_OFFSET);
+               if ((data->dnode.dn.dn_bonuslen == 0) &&
+                       (data->dnode.dn.dn_flags & DNODE_FLAG_SPILL_BLKPTR))
+                       free(sahdrp);
        } else {
                file->size = zfs_to_cpu64(((znode_phys_t *) DN_BONUS(&data->dnode.dn))->zp_size, data->dnode.endian);
        }
@@ -2130,7 +2125,7 @@ zfs_read(zfs_file_t file, char *buf, uint64_t len)
                data->file_start = blkid * blksz;
                data->file_end = data->file_start + blksz;
 
-               movesize = MIN(length, data->file_end - (int) file->offset - red);
+               movesize = min(length, data->file_end - (int)file->offset - red);
 
                memmove(buf, data->file_buf + file->offset + red
                                - data->file_start, movesize);