summaryrefslogtreecommitdiff
path: root/usr/src/boot/sys
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/boot/sys')
-rw-r--r--usr/src/boot/sys/boot/common/module.c8
-rw-r--r--usr/src/boot/sys/boot/efi/loader/copy.c4
-rw-r--r--usr/src/boot/sys/cddl/boot/zfs/zfssubr.c65
3 files changed, 53 insertions, 24 deletions
diff --git a/usr/src/boot/sys/boot/common/module.c b/usr/src/boot/sys/boot/common/module.c
index 14aa790973..4936ec5a3c 100644
--- a/usr/src/boot/sys/boot/common/module.c
+++ b/usr/src/boot/sys/boot/common/module.c
@@ -671,7 +671,8 @@ file_loadraw(const char *fname, char *type, int argc, char **argv, int insert)
"error reading '%s': %s", name, strerror(errno));
free(name);
close(fd);
- if (archsw.arch_free_loadaddr != NULL) {
+ if (archsw.arch_free_loadaddr != NULL &&
+ st.st_size != 0) {
archsw.arch_free_loadaddr(loadaddr,
(uint64_t)
(roundup2(st.st_size, PAGE_SIZE) >> 12));
@@ -684,7 +685,7 @@ file_loadraw(const char *fname, char *type, int argc, char **argv, int insert)
/* Looks OK so far; create & populate control structure */
fp = file_alloc();
if (fp == NULL) {
- if (archsw.arch_free_loadaddr != NULL)
+ if (archsw.arch_free_loadaddr != NULL && st.st_size != 0)
archsw.arch_free_loadaddr(loadaddr,
(uint64_t)(roundup2(st.st_size, PAGE_SIZE) >> 12));
snprintf(command_errbuf, sizeof (command_errbuf),
@@ -1151,7 +1152,8 @@ file_discard(struct preloaded_file *fp)
if (fp == NULL)
return;
- if (archsw.arch_free_loadaddr != NULL && fp->f_addr) {
+ if (archsw.arch_free_loadaddr != NULL && fp->f_addr &&
+ fp->f_size != 0) {
archsw.arch_free_loadaddr(fp->f_addr,
(uint64_t)(roundup2(fp->f_size, PAGE_SIZE) >> 12));
}
diff --git a/usr/src/boot/sys/boot/efi/loader/copy.c b/usr/src/boot/sys/boot/efi/loader/copy.c
index 0dd8e8a5cc..77a0703136 100644
--- a/usr/src/boot/sys/boot/efi/loader/copy.c
+++ b/usr/src/boot/sys/boot/efi/loader/copy.c
@@ -174,6 +174,10 @@ efi_loadaddr(uint_t type, void *data, vm_offset_t addr)
size = st.st_size;
}
+ /* AllocatePages can not allocate 0 pages. */
+ if (size == 0)
+ return (addr);
+
pages = EFI_SIZE_TO_PAGES(size);
/* 4GB upper limit */
paddr = UINT32_MAX;
diff --git a/usr/src/boot/sys/cddl/boot/zfs/zfssubr.c b/usr/src/boot/sys/cddl/boot/zfs/zfssubr.c
index 0d509ed4a1..d4bcb9ac06 100644
--- a/usr/src/boot/sys/cddl/boot/zfs/zfssubr.c
+++ b/usr/src/boot/sys/cddl/boot/zfs/zfssubr.c
@@ -36,9 +36,6 @@ static uint64_t zfs_crc64_table[256];
#define ASSERT0(x) ((void)0)
#define ASSERT(x) ((void)0)
-#define kmem_alloc(size, flag) zfs_alloc((size))
-#define kmem_free(ptr, size) zfs_free((ptr), (size))
-
static void
zfs_init_crc(void)
{
@@ -377,9 +374,6 @@ zap_hash(uint64_t salt, const char *name)
return (crc);
}
-static void *zfs_alloc(size_t size);
-static void zfs_free(void *ptr, size_t size);
-
typedef struct raidz_col {
uint64_t rc_devidx; /* child device index for I/O */
uint64_t rc_offset; /* device offset */
@@ -982,7 +976,11 @@ vdev_raidz_matrix_reconstruct(raidz_map_t *rm, int n, int nmissing,
log = 0; /* gcc */
psize = sizeof (invlog[0][0]) * n * nmissing;
- p = zfs_alloc(psize);
+ p = malloc(psize);
+ if (p == NULL) {
+ printf("Out of memory\n");
+ return;
+ }
for (pp = p, i = 0; i < nmissing; i++) {
invlog[i] = pp;
@@ -1038,7 +1036,7 @@ vdev_raidz_matrix_reconstruct(raidz_map_t *rm, int n, int nmissing,
}
}
- zfs_free(p, psize);
+ free(p);
}
static int
@@ -1099,7 +1097,11 @@ vdev_raidz_reconstruct_general(raidz_map_t *rm, int *tgts, int ntgts)
psize = (sizeof (rows[0][0]) + sizeof (invrows[0][0])) *
nmissing_rows * n + sizeof (used[0]) * n;
- p = kmem_alloc(psize, KM_SLEEP);
+ p = malloc(psize);
+ if (p == NULL) {
+ printf("Out of memory\n");
+ return (code);
+ }
for (pp = p, i = 0; i < nmissing_rows; i++) {
rows[i] = pp;
@@ -1142,7 +1144,7 @@ vdev_raidz_reconstruct_general(raidz_map_t *rm, int *tgts, int ntgts)
vdev_raidz_matrix_reconstruct(rm, n, nmissing_rows, missing_rows,
invrows, used);
- kmem_free(p, psize);
+ free(p);
return (code);
}
@@ -1215,7 +1217,9 @@ vdev_raidz_map_alloc(void *data, off_t offset, size_t size, uint64_t unit_shift,
ASSERT3U(acols, <=, scols);
- rm = zfs_alloc(offsetof(raidz_map_t, rm_col[scols]));
+ rm = malloc(offsetof(raidz_map_t, rm_col[scols]));
+ if (rm == NULL)
+ return (rm);
rm->rm_cols = acols;
rm->rm_scols = scols;
@@ -1260,8 +1264,16 @@ vdev_raidz_map_alloc(void *data, off_t offset, size_t size, uint64_t unit_shift,
ASSERT3U(rm->rm_asize - asize, ==, rm->rm_nskip << unit_shift);
ASSERT3U(rm->rm_nskip, <=, nparity);
- for (c = 0; c < rm->rm_firstdatacol; c++)
- rm->rm_col[c].rc_data = zfs_alloc(rm->rm_col[c].rc_size);
+ for (c = 0; c < rm->rm_firstdatacol; c++) {
+ rm->rm_col[c].rc_data = malloc(rm->rm_col[c].rc_size);
+ if (rm->rm_col[c].rc_data == NULL) {
+ c++;
+ while (c != 0)
+ free(rm->rm_col[--c].rc_data);
+ free(rm);
+ return (NULL);
+ }
+ }
rm->rm_col[c].rc_data = data;
@@ -1313,9 +1325,9 @@ vdev_raidz_map_free(raidz_map_t *rm)
int c;
for (c = rm->rm_firstdatacol - 1; c >= 0; c--)
- zfs_free(rm->rm_col[c].rc_data, rm->rm_col[c].rc_size);
+ free(rm->rm_col[c].rc_data);
- zfs_free(rm, offsetof(raidz_map_t, rm_col[rm->rm_scols]));
+ free(rm);
}
static vdev_t *
@@ -1360,8 +1372,12 @@ raidz_parity_verify(raidz_map_t *rm)
rc = &rm->rm_col[c];
if (!rc->rc_tried || rc->rc_error != 0)
continue;
- orig[c] = zfs_alloc(rc->rc_size);
- bcopy(rc->rc_data, orig[c], rc->rc_size);
+ orig[c] = malloc(rc->rc_size);
+ if (orig[c] != NULL) {
+ bcopy(rc->rc_data, orig[c], rc->rc_size);
+ } else {
+ printf("Out of memory\n");
+ }
}
vdev_raidz_generate_parity(rm);
@@ -1370,11 +1386,12 @@ raidz_parity_verify(raidz_map_t *rm)
rc = &rm->rm_col[c];
if (!rc->rc_tried || rc->rc_error != 0)
continue;
- if (bcmp(orig[c], rc->rc_data, rc->rc_size) != 0) {
+ if (orig[c] == NULL ||
+ bcmp(orig[c], rc->rc_data, rc->rc_size) != 0) {
rc->rc_error = ECKSUM;
ret++;
}
- zfs_free(orig[c], rc->rc_size);
+ free(orig[c]);
}
return (ret);
@@ -1443,7 +1460,11 @@ vdev_raidz_combrec(const spa_t *spa, raidz_map_t *rm, const blkptr_t *bp,
ASSERT(orig[i] != NULL);
}
- orig[n - 1] = zfs_alloc(rm->rm_col[0].rc_size);
+ orig[n - 1] = malloc(rm->rm_col[0].rc_size);
+ if (orig[n - 1] == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
current = 0;
next = tgts[current];
@@ -1526,7 +1547,7 @@ vdev_raidz_combrec(const spa_t *spa, raidz_map_t *rm, const blkptr_t *bp,
n--;
done:
for (i = n - 1; i >= 0; i--) {
- zfs_free(orig[i], rm->rm_col[0].rc_size);
+ free(orig[i]);
}
return (ret);
@@ -1555,6 +1576,8 @@ vdev_raidz_read(vdev_t *vd, const blkptr_t *bp, void *data,
rm = vdev_raidz_map_alloc(data, offset, bytes, tvd->v_ashift,
vd->v_nchildren, vd->v_nparity);
+ if (rm == NULL)
+ return (ENOMEM);
/*
* Iterate over the columns in reverse order so that we hit the parity