Mercurial > illumos > illumos-gate
changeset 2955:2aef90ea300f
6466526 some cleanup of error handling needed in devfsadm pci link generator
6466530 correction in link removal for devfsadm pci link generator
author | pjha |
---|---|
date | Fri, 20 Oct 2006 14:57:20 -0700 |
parents | b0b763bffb8e |
children | 1940b23c5e82 |
files | usr/src/cmd/devfsadm/cfg_link.c usr/src/cmd/devfsadm/cfg_link.h |
diffstat | 2 files changed, 18 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/usr/src/cmd/devfsadm/cfg_link.c Fri Oct 20 14:20:31 2006 -0700 +++ b/usr/src/cmd/devfsadm/cfg_link.c Fri Oct 20 14:57:20 2006 -0700 @@ -336,14 +336,12 @@ path = di_devfs_path(node); minor_nm = di_minor_name(minor); - buflen = snprintf(NULL, 0, "%s:%s", path, minor_nm); + buflen = snprintf(NULL, 0, "%s:%s", path, minor_nm) + 1; bufp = malloc(sizeof (char) * buflen); - if (bufp == NULL) - goto OUT; - (void) snprintf(bufp, buflen, "%s:%s", path, minor_nm); + if (bufp != NULL) + (void) snprintf(bufp, buflen, "%s:%s", path, minor_nm); -OUT: di_devfs_path_free(path); return (bufp); } @@ -580,6 +578,9 @@ } +/* + * returns the pci device number for <node> if found, else returns PCIDEV_NIL + */ static minor_t pci_cfg_pcidev(di_node_t node, di_prom_handle_t ph) { @@ -724,6 +725,12 @@ * the current node is on */ pci_dev = pci_cfg_pcidev(curnode, ph); + if (pci_dev == PCIDEV_NIL) { + dprint(("%s: cannot obtain pci device number " + "for %s%d\n", fnm, DRVINST(node))); + *pathptr = '\0'; + goto OUT; + } } while ((curnode = di_parent_node(curnode)) != DI_NODE_NIL); pathbuf[sizeof (pathbuf) - 1] = '\0'; @@ -1017,7 +1024,7 @@ char *fullpath = NULL; char *pathinfo = NULL; char *devpath = NULL; - int rv, fd; + int rv, fd = -1; size_t sz; di_prom_handle_t ph; di_node_t node; @@ -1114,6 +1121,8 @@ } OUT: + if (fd >= 0) + di_dli_close(fd); if (fullpath != NULL) free(fullpath); if (pathinfo != NULL)
--- a/usr/src/cmd/devfsadm/cfg_link.h Fri Oct 20 14:20:31 2006 -0700 +++ b/usr/src/cmd/devfsadm/cfg_link.h Fri Oct 20 14:57:20 2006 -0700 @@ -42,7 +42,8 @@ #define PCI_CFG_LINK_RE "^cfg/[:alnum:]$" #define IB_CFG_LINK_RE "^cfg/(hca[0-9A-F]+)$" #define SATA_CFG_LINK_RE "^cfg/((sata[0-9]+)/([0-9]+)([.]([0-9])+)*)$" -#define PCI_CFG_PATH_LINK_RE "^cfg/(.*pcie.*)$" +#define PCI_CFG_PATH_LINK_RE \ + "^cfg/(.*(pci[0-9]|pcie[0-9]|Slot[0-9]|\\<pci\\>|\\<pcie\\>).*)$" #define CFG_DIRNAME "cfg" @@ -61,6 +62,7 @@ #define AP_PATH_IOB_SEP "." #define VENDID_SUN 0x108e #define APNODE_DEFNAME 0x1 +#define PCIDEV_NIL ((minor_t)-1) /* converts size in bits to a mask covering those bit positions */ #define SIZE2MASK(s) ((1 << (s)) - 1)