Print this page
12001 cpu_uarray_free(NULL) panics
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/os/cpu_uarray.c
+++ new/usr/src/uts/common/os/cpu_uarray.c
1 1 /*
2 2 * This file and its contents are supplied under the terms of the
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
3 3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 4 * You may only use this file in accordance with the terms of version
5 5 * 1.0 of the CDDL.
6 6 *
7 7 * A full copy of the text of the CDDL should have accompanied this
8 8 * source. A copy of the CDDL is also available via the Internet at
9 9 * http://www.illumos.org/license/CDDL.
10 10 */
11 11
12 12 /*
13 - * Copyright (c) 2018, Joyent, Inc.
13 + * Copyright 2019 Joyent, Inc.
14 14 */
15 15
16 16 #include <sys/cpu_uarray.h>
17 17 #include <sys/sysmacros.h>
18 18 #include <sys/cpuvar.h>
19 19 #include <sys/debug.h>
20 20 #include <sys/kmem.h>
21 21
22 22 static size_t
23 23 cpu_uarray_size(size_t nr_items)
24 24 {
25 25 size_t size = P2ROUNDUP(nr_items * sizeof (uint64_t), CUA_ALIGN);
26 26 size *= NCPU;
27 27 return (sizeof (cpu_uarray_t) + size);
28 28 }
29 29
30 30 cpu_uarray_t *
31 31 cpu_uarray_zalloc(size_t nr_items, int kmflags)
32 32 {
33 33 cpu_uarray_t *cua;
34 34
35 35 cua = kmem_zalloc(cpu_uarray_size(nr_items), kmflags);
36 36
37 37 if (cua != NULL) {
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
38 38 VERIFY(IS_P2ALIGNED(cua->cu_vals, CUA_ALIGN));
39 39 cua->cu_nr_items = nr_items;
40 40 }
41 41
42 42 return (cua);
43 43 }
44 44
45 45 void
46 46 cpu_uarray_free(cpu_uarray_t *cua)
47 47 {
48 - kmem_free(cua, cpu_uarray_size(cua->cu_nr_items));
48 + if (cua != NULL)
49 + kmem_free(cua, cpu_uarray_size(cua->cu_nr_items));
49 50 }
50 51
51 52 uint64_t
52 53 cpu_uarray_sum(cpu_uarray_t *cua, size_t index)
53 54 {
54 55 uint64_t sum = 0;
55 56
56 57 VERIFY3U(index, <, cua->cu_nr_items);
57 58
58 59 for (size_t c = 0; c < ncpus; c++) {
59 60 uint64_t addend = CPU_UARRAY_VAL(cua, c, index);
60 61 sum = UINT64_OVERFLOW_ADD(sum, addend);
61 62 }
62 63
63 64 return (sum);
64 65 }
65 66
66 67 uint64_t
67 68 cpu_uarray_sum_all(cpu_uarray_t *cua)
68 69 {
69 70 uint64_t sum = 0;
70 71
71 72 for (size_t c = 0; c < ncpus; c++) {
72 73 for (size_t i = 0; i < cua->cu_nr_items; i++) {
73 74 uint64_t addend = CPU_UARRAY_VAL(cua, c, i);
74 75 sum = UINT64_OVERFLOW_ADD(sum, addend);
75 76 }
76 77 }
77 78
78 79 return (sum);
79 80 }
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX