aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/subr_blist.c
diff options
context:
space:
mode:
authorAlan Cox <alc@FreeBSD.org>2017-06-10 16:11:39 +0000
committerAlan Cox <alc@FreeBSD.org>2017-06-10 16:11:39 +0000
commit015d7db6b667db98805a67963f7280ab7cf9a6bc (patch)
tree6f296142666e51a334dc8ab9a2e6e387b5f8e1df /sys/kern/subr_blist.c
parentc645060dbb7b6da117f50c8793e0046036b5329c (diff)
downloadsrc-015d7db6b667db98805a67963f7280ab7cf9a6bc.tar.gz
src-015d7db6b667db98805a67963f7280ab7cf9a6bc.zip
Remove an unnecessary field from struct blist. (The comment describing
what this field represented was also inaccurate.) Suggested by: kib In r178792, blist_create() grew a malloc flag, allowing M_NOWAIT to be specified. However, blist_create() was not modified to handle the possibility that a malloc() call failed. Address this omission. Increase the width of the local variable "radix" to 64 bits. (This matches the width of the corresponding field in struct blist.) Reviewed by: kib MFC after: 6 weeks
Notes
Notes: svn path=/head/; revision=319793
Diffstat (limited to 'sys/kern/subr_blist.c')
-rw-r--r--sys/kern/subr_blist.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/sys/kern/subr_blist.c b/sys/kern/subr_blist.c
index f397dc8e16e6..102a403363fa 100644
--- a/sys/kern/subr_blist.c
+++ b/sys/kern/subr_blist.c
@@ -156,7 +156,7 @@ blist_t
blist_create(daddr_t blocks, int flags)
{
blist_t bl;
- int radix;
+ daddr_t nodes, radix;
int skip = 0;
/*
@@ -170,13 +170,19 @@ blist_create(daddr_t blocks, int flags)
}
bl = malloc(sizeof(struct blist), M_SWAP, flags | M_ZERO);
+ if (bl == NULL)
+ return (NULL);
bl->bl_blocks = blocks;
bl->bl_radix = radix;
bl->bl_skip = skip;
- bl->bl_rootblks = 1 +
- blst_radix_init(NULL, bl->bl_radix, bl->bl_skip, blocks);
- bl->bl_root = malloc(sizeof(blmeta_t) * bl->bl_rootblks, M_SWAP, flags);
+ nodes = 1 + blst_radix_init(NULL, radix, bl->bl_skip, blocks);
+ bl->bl_root = malloc(nodes * sizeof(blmeta_t), M_SWAP, flags);
+ if (bl->bl_root == NULL) {
+ free(bl, M_SWAP);
+ return (NULL);
+ }
+ blst_radix_init(bl->bl_root, radix, bl->bl_skip, blocks);
#if defined(BLIST_DEBUG)
printf(
@@ -184,14 +190,13 @@ blist_create(daddr_t blocks, int flags)
", requiring %lldK of ram\n",
(long long)bl->bl_blocks,
(long long)bl->bl_blocks * 4 / 1024,
- (long long)(bl->bl_rootblks * sizeof(blmeta_t) + 1023) / 1024
+ (long long)(nodes * sizeof(blmeta_t) + 1023) / 1024
);
printf("BLIST raw radix tree contains %lld records\n",
- (long long)bl->bl_rootblks);
+ (long long)nodes);
#endif
- blst_radix_init(bl->bl_root, bl->bl_radix, bl->bl_skip, blocks);
- return(bl);
+ return (bl);
}
void