Author: cem
Date: Mon Sep 18 17:14:13 2017
New Revision: 323710
URL: https://svnweb.freebsd.org/changeset/base/323710

Log:
  linsysfs(5): Fix two unrelated issues
  
  1. Swap the order of device_get_ivars with device_get_devclass and devclass
     name validation.  This bug was introduced in r323692.
  
  2. Error check device_get_children and free the returned list.  This bug was
     introduced in the original linsysfs commit.
  
  Reported by:  Oleg V. Nauman <oleg AT theweb.org.ua>, hselasky (1); hselasky 
(2)
  Reviewed by:  hselasky
  Sponsored by: Dell EMC Isilon
  Differential Revision:        https://reviews.freebsd.org/D12407

Modified:
  head/sys/compat/linsysfs/linsysfs.c

Modified: head/sys/compat/linsysfs/linsysfs.c
==============================================================================
--- head/sys/compat/linsysfs/linsysfs.c Mon Sep 18 16:42:13 2017        
(r323709)
+++ head/sys/compat/linsysfs/linsysfs.c Mon Sep 18 17:14:13 2017        
(r323710)
@@ -252,7 +252,7 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, s
 {
        struct scsi_host_queue *scsi_host;
        struct pfs_node *sub_dir, *cur_file, *cur_chardev;
-       int i, nchildren;
+       int i, nchildren, error;
        device_t *children, parent;
        devclass_t devclass;
        const char *name = NULL;
@@ -353,13 +353,15 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, s
                        }
                }
 
-               dinfo = device_get_ivars(parent);
-               if (dinfo != NULL && dinfo->cfg.baseclass == PCIC_DISPLAY) {
-                       devclass = device_get_devclass(dev);
-                       if (devclass != NULL)
-                               name = devclass_get_name(devclass);
-                       if (name != NULL && strcmp(name, DRMN_DEV) == 0 &&
-                           device_get_unit(dev) >= 0) {
+               devclass = device_get_devclass(dev);
+               if (devclass != NULL)
+                       name = devclass_get_name(devclass);
+               else
+                       name = NULL;
+               if (name != NULL && strcmp(name, DRMN_DEV) == 0 &&
+                   device_get_unit(dev) >= 0) {
+                       dinfo = device_get_ivars(parent);
+                       if (dinfo != NULL && dinfo->cfg.baseclass == 
PCIC_DISPLAY) {
                                sprintf(chardevname, "226:%d",
                                    device_get_unit(dev));
                                cur_chardev = pfs_create_dir(chardev,
@@ -376,10 +378,13 @@ linsysfs_run_bus(device_t dev, struct pfs_node *dir, s
                }
        }
 
-       device_get_children(dev, &children, &nchildren);
-       for (i = 0; i < nchildren; i++) {
-               if (children[i])
-                       linsysfs_run_bus(children[i], dir, scsi, chardev, 
new_path, prefix);
+       error = device_get_children(dev, &children, &nchildren);
+       if (error == 0) {
+               for (i = 0; i < nchildren; i++)
+                       if (children[i])
+                               linsysfs_run_bus(children[i], dir, scsi,
+                                   chardev, new_path, prefix);
+               free(children, M_TEMP);
        }
        if (new_path != path)
                free(new_path, M_TEMP);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to