Print this page
8954 libtopo cannot handle any array type other than string_array.
Reviewed by: Andy Stormont astormont@racktopsystems.com
Reviewed by: David Höppner 0xffea@gmail.com
Reviewed by: Rob Johnston rob.johnston@joyent.com

*** 20,29 **** --- 20,30 ---- */ /* * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, Joyent, Inc. All rights reserved. + * Copyright (c) 2018, Western Digital Technologies, Inc. All rights reserved. */ #include <libxml/parser.h> #include <libxml/xinclude.h> #include <sys/fm/protocol.h>
*** 192,202 **** return (rv); } static int xlate_common(topo_mod_t *mp, xmlNodePtr xn, topo_type_t ptype, nvlist_t *nvl, ! const char *name) { int rv; uint64_t ui; uint_t i = 0, nelems = 0; nvlist_t *fmri; --- 193,203 ---- return (rv); } static int xlate_common(topo_mod_t *mp, xmlNodePtr xn, topo_type_t ptype, nvlist_t *nvl, ! const char *name) { int rv; uint64_t ui; uint_t i = 0, nelems = 0; nvlist_t *fmri;
*** 242,266 **** break; case TOPO_TYPE_INT32_ARRAY: case TOPO_TYPE_UINT32_ARRAY: case TOPO_TYPE_INT64_ARRAY: case TOPO_TYPE_UINT64_ARRAY: - for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) - if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || - (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) - nelems++; - - if (nelems < 1) { - topo_dprintf(mp->tm_hdl, TOPO_DBG_ERR, "No <propitem> " - "or <argitem> elements found for array val"); - return (-1); - } - if ((arrbuf = topo_mod_alloc(mp, (nelems * sizeof (uint64_t)))) - == NULL) - return (topo_mod_seterrno(mp, ETOPO_NOMEM)); - break; case TOPO_TYPE_STRING_ARRAY: for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) nelems++; --- 243,254 ---- break; case TOPO_TYPE_INT32_ARRAY: case TOPO_TYPE_UINT32_ARRAY: case TOPO_TYPE_INT64_ARRAY: case TOPO_TYPE_UINT64_ARRAY: case TOPO_TYPE_STRING_ARRAY: + case TOPO_TYPE_FMRI_ARRAY: for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) nelems++;
*** 267,308 **** if (nelems < 1) { topo_dprintf(mp->tm_hdl, TOPO_DBG_ERR, "No <propitem> " "or <argitem> elements found for array val"); return (-1); } - if ((strarrbuf = topo_mod_alloc(mp, (nelems * sizeof (char *)))) - == NULL) - return (topo_mod_seterrno(mp, ETOPO_NOMEM)); break; - case TOPO_TYPE_FMRI_ARRAY: - for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) - if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || - (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) - nelems++; - - if (nelems < 1) { - topo_dprintf(mp->tm_hdl, TOPO_DBG_ERR, "No <propitem> " - "elements found for array prop"); - return (-1); - } - if ((nvlarrbuf = topo_mod_alloc(mp, (nelems * - sizeof (nvlist_t *)))) == NULL) - return (topo_mod_seterrno(mp, ETOPO_NOMEM)); - break; default: topo_dprintf(mp->tm_hdl, TOPO_DBG_ERR, "Unrecognized type attribute (ptype = %d)\n", ptype); return (topo_mod_seterrno(mp, ETOPO_PRSR_BADTYPE)); } switch (ptype) { case TOPO_TYPE_INT32_ARRAY: for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) { if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) { ! if ((str = xmlGetProp(xn, (xmlChar *)Value)) == NULL) return (-1); ((int32_t *)arrbuf)[i++] = atoi((const char *)str); --- 255,281 ---- if (nelems < 1) { topo_dprintf(mp->tm_hdl, TOPO_DBG_ERR, "No <propitem> " "or <argitem> elements found for array val"); return (-1); } break; default: topo_dprintf(mp->tm_hdl, TOPO_DBG_ERR, "Unrecognized type attribute (ptype = %d)\n", ptype); return (topo_mod_seterrno(mp, ETOPO_PRSR_BADTYPE)); } switch (ptype) { case TOPO_TYPE_INT32_ARRAY: + if ((arrbuf = topo_mod_alloc(mp, (nelems * sizeof (int32_t)))) + == NULL) + return (topo_mod_seterrno(mp, ETOPO_NOMEM)); for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) { if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) { ! if ((str = xmlGetProp(cn, (xmlChar *)Value)) == NULL) return (-1); ((int32_t *)arrbuf)[i++] = atoi((const char *)str);
*** 310,327 **** } } rv = nvlist_add_int32_array(nvl, name, (int32_t *)arrbuf, nelems); ! free(arrbuf); break; case TOPO_TYPE_UINT32_ARRAY: for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) { if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) { ! if ((str = xmlGetProp(xn, (xmlChar *)Value)) == NULL) return (-1); ((uint32_t *)arrbuf)[i++] = atoi((const char *)str); --- 283,303 ---- } } rv = nvlist_add_int32_array(nvl, name, (int32_t *)arrbuf, nelems); ! topo_mod_free(mp, arrbuf, (nelems * sizeof (int32_t))); break; case TOPO_TYPE_UINT32_ARRAY: + if ((arrbuf = topo_mod_alloc(mp, (nelems * sizeof (uint32_t)))) + == NULL) + return (topo_mod_seterrno(mp, ETOPO_NOMEM)); for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) { if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) { ! if ((str = xmlGetProp(cn, (xmlChar *)Value)) == NULL) return (-1); ((uint32_t *)arrbuf)[i++] = atoi((const char *)str);
*** 329,346 **** } } rv = nvlist_add_uint32_array(nvl, name, (uint32_t *)arrbuf, nelems); ! free(arrbuf); break; case TOPO_TYPE_INT64_ARRAY: for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) { if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) { ! if ((str = xmlGetProp(xn, (xmlChar *)Value)) == NULL) return (-1); ((int64_t *)arrbuf)[i++] = atol((const char *)str); --- 305,325 ---- } } rv = nvlist_add_uint32_array(nvl, name, (uint32_t *)arrbuf, nelems); ! topo_mod_free(mp, arrbuf, (nelems * sizeof (uint32_t))); break; case TOPO_TYPE_INT64_ARRAY: + if ((arrbuf = topo_mod_alloc(mp, (nelems * sizeof (int64_t)))) + == NULL) + return (topo_mod_seterrno(mp, ETOPO_NOMEM)); for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) { if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) { ! if ((str = xmlGetProp(cn, (xmlChar *)Value)) == NULL) return (-1); ((int64_t *)arrbuf)[i++] = atol((const char *)str);
*** 348,365 **** } } rv = nvlist_add_int64_array(nvl, name, (int64_t *)arrbuf, nelems); ! free(arrbuf); break; case TOPO_TYPE_UINT64_ARRAY: for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) { if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) { ! if ((str = xmlGetProp(xn, (xmlChar *)Value)) == NULL) return (-1); ((uint64_t *)arrbuf)[i++] = atol((const char *)str); --- 327,347 ---- } } rv = nvlist_add_int64_array(nvl, name, (int64_t *)arrbuf, nelems); ! topo_mod_free(mp, arrbuf, (nelems * sizeof (int64_t))); break; case TOPO_TYPE_UINT64_ARRAY: + if ((arrbuf = topo_mod_alloc(mp, (nelems * sizeof (uint64_t)))) + == NULL) + return (topo_mod_seterrno(mp, ETOPO_NOMEM)); for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) { if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) { ! if ((str = xmlGetProp(cn, (xmlChar *)Value)) == NULL) return (-1); ((uint64_t *)arrbuf)[i++] = atol((const char *)str);
*** 367,379 **** } } rv = nvlist_add_uint64_array(nvl, name, arrbuf, nelems); ! free(arrbuf); break; case TOPO_TYPE_STRING_ARRAY: for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) { if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) { if ((str = xmlGetProp(cn, (xmlChar *)Value)) --- 349,364 ---- } } rv = nvlist_add_uint64_array(nvl, name, arrbuf, nelems); ! topo_mod_free(mp, arrbuf, (nelems * sizeof (uint64_t))); break; case TOPO_TYPE_STRING_ARRAY: + if ((strarrbuf = topo_mod_alloc(mp, (nelems * sizeof (char *)))) + == NULL) + return (topo_mod_seterrno(mp, ETOPO_NOMEM)); for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) { if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) { if ((str = xmlGetProp(cn, (xmlChar *)Value))
*** 388,402 **** rv = nvlist_add_string_array(nvl, name, strarrbuf, nelems); strarr_free(mp, strarrbuf, nelems); break; case TOPO_TYPE_FMRI_ARRAY: for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) { if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) { ! if ((str = xmlGetProp(xn, (xmlChar *)Value)) == NULL) return (-1); if (topo_mod_str2nvl(mp, (const char *)str, &(nvlarrbuf[i++])) < 0) { --- 373,390 ---- rv = nvlist_add_string_array(nvl, name, strarrbuf, nelems); strarr_free(mp, strarrbuf, nelems); break; case TOPO_TYPE_FMRI_ARRAY: + if ((nvlarrbuf = topo_mod_alloc(mp, (nelems * + sizeof (nvlist_t *)))) == NULL) + return (topo_mod_seterrno(mp, ETOPO_NOMEM)); for (cn = xn->xmlChildrenNode; cn != NULL; cn = cn->next) { if ((xmlStrcmp(cn->name, (xmlChar *)Propitem) == 0) || (xmlStrcmp(cn->name, (xmlChar *)Argitem) == 0)) { ! if ((str = xmlGetProp(cn, (xmlChar *)Value)) == NULL) return (-1); if (topo_mod_str2nvl(mp, (const char *)str, &(nvlarrbuf[i++])) < 0) {
*** 407,417 **** } } rv = nvlist_add_nvlist_array(nvl, name, nvlarrbuf, nelems); ! free(nvlarrbuf); break; } if (rv != 0) { topo_dprintf(mp->tm_hdl, TOPO_DBG_ERR, --- 395,405 ---- } } rv = nvlist_add_nvlist_array(nvl, name, nvlarrbuf, nelems); ! topo_mod_free(mp, nvlarrbuf, (nelems * sizeof (nvlist_t *))); break; } if (rv != 0) { topo_dprintf(mp->tm_hdl, TOPO_DBG_ERR,