Print this page
NEX-2985 libtopo leaks
Reviewed by: Marcel Telka <marcel.telka@nexenta.com>
Reviewed by: Josef Sipek <josef.sipek@nexenta.com>


 204                                 }
 205                         }
 206                 }
 207                 break;
 208         }
 209         if (rlabel != NULL) {
 210                 topo_mod_dprintf(mod, "%s: match found, label=%s\n",
 211                     __func__, rlabel);
 212         }
 213         return (rlabel);
 214 }
 215 
 216 /*
 217  * Do an overall slot label lookup for the device node.
 218  */
 219 char *
 220 pci_slot_label_lookup(topo_mod_t *mod, tnode_t *node, did_t *dp, did_t *pdp)
 221 {
 222         tnode_t *anode, *apnode;
 223         did_t *adp, *apdp;
 224         char *plat, *pp, *l, *ancestor_l = NULL, *new_l = NULL;
 225         int err, b, d, f, done = 0;
 226         size_t len;
 227 
 228         did_BDF(dp, &b, &d, &f);
 229 
 230         topo_mod_dprintf(mod, "%s: entry: node=%p, node_name=%s, "
 231             "node_inst=%d, dp=%p, dp_bdf=%d/%d/%d, pdp=%p\n",
 232             __func__, node, topo_node_name(node), topo_node_instance(node),
 233             dp, b, d, f, pdp);
 234 
 235         /*
 236          * If this device has a physical slot number then check if
 237          * an ancestor also has a slot label.
 238          *
 239          * If an ancestor has a slot label, then this node's label
 240          * is generated by concatenating a default label onto the
 241          * ancestor's label.
 242          *
 243          * We grab pairs of ancestors (parent and child) as we go up
 244          * the tree because the parent is checked for the presence


 380                  * - Platform specific lookup based on default label string.
 381                  * - Platform specific lookup based on device number.
 382                  * - Default label.
 383                  *   The default label is based on the slot names property
 384                  *   if it exists, else it is a generic name derived from
 385                  *   the slot #.
 386                  */
 387                 if ((l = (char *)pci_label_physlot_lookup(mod, pp, pdp))
 388                     == NULL) {
 389                         if ((l = (char *)did_physlot_name(pdp, d)) != NULL) {
 390                                 l = (char *)
 391                                     pci_label_slotname_lookup(mod, pp, l, dp);
 392                         }
 393                         if (l == NULL) {
 394                                 l = (char *)
 395                                     pci_label_missing_lookup(mod, pp, dp);
 396                         }
 397                 }
 398                 topo_mod_strfree(mod, plat);
 399         }



 400 
 401         /*
 402          * If we calculated a slot label,  then save it in the
 403          * node's data structure so we can free it later.
 404          */
 405         if (l) {
 406                 if (did_slot_label_get(dp) != NULL)
 407                         topo_mod_strfree(mod, did_slot_label_get(dp));
 408                 l = topo_mod_strdup(mod, l);
 409                 did_slot_label_set(dp, l);
 410         }
 411 
 412         topo_mod_dprintf(mod, "%s: exit: node=%p: label=%s\n",
 413             __func__, node, (l ? l : "NULL"));
 414 
 415         return (l);
 416 }
 417 
 418 int
 419 pci_label_cmn(topo_mod_t *mod, tnode_t *node, nvlist_t *in, nvlist_t **out)




 204                                 }
 205                         }
 206                 }
 207                 break;
 208         }
 209         if (rlabel != NULL) {
 210                 topo_mod_dprintf(mod, "%s: match found, label=%s\n",
 211                     __func__, rlabel);
 212         }
 213         return (rlabel);
 214 }
 215 
 216 /*
 217  * Do an overall slot label lookup for the device node.
 218  */
 219 char *
 220 pci_slot_label_lookup(topo_mod_t *mod, tnode_t *node, did_t *dp, did_t *pdp)
 221 {
 222         tnode_t *anode, *apnode;
 223         did_t *adp, *apdp;
 224         char *plat, *pp, *l = NULL, *ancestor_l = NULL, *new_l = NULL;
 225         int err, b, d, f, done = 0;
 226         size_t len;
 227 
 228         did_BDF(dp, &b, &d, &f);
 229 
 230         topo_mod_dprintf(mod, "%s: entry: node=%p, node_name=%s, "
 231             "node_inst=%d, dp=%p, dp_bdf=%d/%d/%d, pdp=%p\n",
 232             __func__, node, topo_node_name(node), topo_node_instance(node),
 233             dp, b, d, f, pdp);
 234 
 235         /*
 236          * If this device has a physical slot number then check if
 237          * an ancestor also has a slot label.
 238          *
 239          * If an ancestor has a slot label, then this node's label
 240          * is generated by concatenating a default label onto the
 241          * ancestor's label.
 242          *
 243          * We grab pairs of ancestors (parent and child) as we go up
 244          * the tree because the parent is checked for the presence


 380                  * - Platform specific lookup based on default label string.
 381                  * - Platform specific lookup based on device number.
 382                  * - Default label.
 383                  *   The default label is based on the slot names property
 384                  *   if it exists, else it is a generic name derived from
 385                  *   the slot #.
 386                  */
 387                 if ((l = (char *)pci_label_physlot_lookup(mod, pp, pdp))
 388                     == NULL) {
 389                         if ((l = (char *)did_physlot_name(pdp, d)) != NULL) {
 390                                 l = (char *)
 391                                     pci_label_slotname_lookup(mod, pp, l, dp);
 392                         }
 393                         if (l == NULL) {
 394                                 l = (char *)
 395                                     pci_label_missing_lookup(mod, pp, dp);
 396                         }
 397                 }
 398                 topo_mod_strfree(mod, plat);
 399         }
 400         if (ancestor_l != NULL) {
 401                 topo_mod_strfree(mod, ancestor_l);
 402         }
 403 
 404         /*
 405          * If we calculated a slot label,  then save it in the
 406          * node's data structure so we can free it later.
 407          */
 408         if (l) {
 409                 if (did_slot_label_get(dp) != NULL)
 410                         topo_mod_strfree(mod, did_slot_label_get(dp));
 411                 l = topo_mod_strdup(mod, l);
 412                 did_slot_label_set(dp, l);
 413         }
 414 
 415         topo_mod_dprintf(mod, "%s: exit: node=%p: label=%s\n",
 416             __func__, node, (l ? l : "NULL"));
 417 
 418         return (l);
 419 }
 420 
 421 int
 422 pci_label_cmn(topo_mod_t *mod, tnode_t *node, nvlist_t *in, nvlist_t **out)