Print this page
10100 Illumos is confused about calloc() arguments
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libipmi/common/libipmi.c
+++ new/usr/src/lib/libipmi/common/libipmi.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 + *
25 + * Copyright (c) 2018, Joyent, Inc.
24 26 */
25 27
26 28 #include <libipmi.h>
27 29 #include <string.h>
28 30
29 31 #include "ipmi_impl.h"
30 32
31 33 ipmi_handle_t *
32 34 ipmi_open(int *errp, char **msg, uint_t xport_type, nvlist_t *params)
33 35 {
34 36 ipmi_handle_t *ihp;
35 37 static char errmsg[48];
36 38
37 39 if (msg)
38 40 *msg = NULL;
39 41
40 - if ((ihp = calloc(sizeof (ipmi_handle_t), 1)) == NULL) {
42 + if ((ihp = calloc(1, sizeof (ipmi_handle_t))) == NULL) {
41 43 *errp = EIPMI_NOMEM;
42 44 if (msg)
43 45 *msg = "memory allocation failure";
44 46 return (NULL);
45 47 }
46 48
47 49 switch (xport_type) {
48 50 case IPMI_TRANSPORT_BMC:
49 51 ihp->ih_transport = &ipmi_transport_bmc;
50 52 break;
51 53 case IPMI_TRANSPORT_LAN:
52 54 ihp->ih_transport = &ipmi_transport_lan;
53 55 break;
54 56 default:
55 57 *msg = "invalid transport type specified";
56 58 return (NULL);
57 59 }
58 60
59 61 ihp->ih_retries = 3;
60 62
61 63 if ((ihp->ih_tdata = ihp->ih_transport->it_open(ihp, params)) == NULL ||
62 64 ipmi_sdr_init(ihp) != 0 || ipmi_entity_init(ihp) != 0) {
63 65 *errp = ihp->ih_errno;
64 66 if (msg) {
65 67 (void) strncpy(errmsg, ipmi_errmsg(ihp), 47);
66 68 errmsg[47] = '\0';
67 69 *msg = errmsg;
68 70 }
69 71 ipmi_close(ihp);
70 72 return (NULL);
71 73 }
72 74
73 75 return (ihp);
74 76 }
75 77
76 78 void
77 79 ipmi_close(ipmi_handle_t *ihp)
78 80 {
79 81 if (ihp->ih_transport && ihp->ih_tdata)
80 82 ihp->ih_transport->it_close(ihp->ih_tdata);
81 83 ipmi_free(ihp, ihp->ih_deviceid);
82 84 ipmi_free(ihp, ihp->ih_firmware_rev);
83 85 ipmi_user_clear(ihp);
84 86 ipmi_sdr_fini(ihp);
85 87 ipmi_entity_fini(ihp);
86 88 free(ihp);
87 89 }
88 90
89 91 /*
90 92 * See section 5.2 for a description of the completion codes.
91 93 */
92 94 static struct ipmi_err_conv {
93 95 int bmc_err;
94 96 int ipmi_err;
95 97 } ipmi_errtable[] = {
96 98 { 0xC0, EIPMI_BUSY },
97 99 { 0xC1, EIPMI_INVALID_COMMAND },
98 100 { 0xC2, EIPMI_INVALID_COMMAND },
99 101 { 0xC3, EIPMI_COMMAND_TIMEOUT },
100 102 { 0xC4, EIPMI_NOSPACE },
101 103 { 0xC5, EIPMI_INVALID_RESERVATION },
102 104 { 0xC6, EIPMI_INVALID_REQUEST },
103 105 { 0xC7, EIPMI_INVALID_REQUEST },
104 106 { 0xC8, EIPMI_INVALID_REQUEST },
105 107 { 0xC9, EIPMI_INVALID_REQUEST },
106 108 { 0xCA, EIPMI_DATA_LENGTH_EXCEEDED },
107 109 { 0xCB, EIPMI_NOT_PRESENT },
108 110 { 0xCC, EIPMI_INVALID_REQUEST },
109 111 { 0xCD, EIPMI_INVALID_COMMAND },
110 112 { 0xCE, EIPMI_UNAVAILABLE },
111 113 { 0xCF, EIPMI_UNAVAILABLE },
112 114 { 0xD0, EIPMI_BUSY },
113 115 { 0xD1, EIPMI_BUSY },
114 116 { 0xD2, EIPMI_BUSY },
115 117 { 0xD3, EIPMI_NOT_PRESENT },
116 118 { 0xD4, EIPMI_ACCESS },
117 119 { 0xD5, EIPMI_UNAVAILABLE },
118 120 { 0xD6, EIPMI_UNAVAILABLE },
119 121 { 0xFF, EIPMI_UNSPECIFIED },
120 122 };
121 123
122 124 #define IPMI_ERROR_COUNT \
123 125 (sizeof (ipmi_errtable) / sizeof (ipmi_errtable[0]))
124 126
125 127 ipmi_cmd_t *
126 128 ipmi_send(ipmi_handle_t *ihp, ipmi_cmd_t *cmd)
127 129 {
128 130 int i;
129 131
130 132 if (ihp->ih_transport->it_send(ihp->ih_tdata, cmd, &ihp->ih_response,
131 133 &ihp->ih_completion) != 0)
132 134 return (NULL);
133 135
134 136 if (ihp->ih_completion != 0) {
135 137 for (i = 0; i < IPMI_ERROR_COUNT; i++) {
136 138 if (ihp->ih_completion == ipmi_errtable[i].bmc_err) {
137 139 (void) ipmi_set_error(ihp,
138 140 ipmi_errtable[i].ipmi_err,
139 141 "IPMI completion code 0x%x",
140 142 ihp->ih_completion);
141 143 return (NULL);
142 144 }
143 145 }
144 146
145 147 (void) ipmi_set_error(ihp, EIPMI_UNKNOWN,
146 148 "IPMI completion code 0x%x", ihp->ih_completion);
147 149 return (NULL);
148 150 }
149 151
150 152 return (&ihp->ih_response);
151 153 }
↓ open down ↓ |
101 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX