Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Avoid a potential crash: get more struct device in...



details:   https://anonhg.NetBSD.org/src/rev/328aa0a7722a
branches:  trunk
changeset: 752213:328aa0a7722a
user:      dyoung <dyoung%NetBSD.org@localhost>
date:      Fri Feb 19 22:28:47 2010 +0000

description:
Avoid a potential crash:  get more struct device initialization
out of the way before trying to get a unit number.  If we cannot
get a unit number, we call config_devfree(), which expects for
fields such as dv_flags, dv_cfattach, and dv_private to be initialized.

diffstat:

 sys/kern/subr_autoconf.c |  23 ++++++++++++-----------
 1 files changed, 12 insertions(+), 11 deletions(-)

diffs (58 lines):

diff -r 25b50fd3aa8b -r 328aa0a7722a sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c  Fri Feb 19 19:09:15 2010 +0000
+++ b/sys/kern/subr_autoconf.c  Fri Feb 19 22:28:47 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.201 2010/02/15 20:20:34 dyoung Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.202 2010/02/19 22:28:47 dyoung Exp $ */
 
 /*
  * Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.201 2010/02/15 20:20:34 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.202 2010/02/19 22:28:47 dyoung Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1184,6 +1184,15 @@
        if (dev == NULL)
                panic("config_devalloc: memory allocation for device_t failed");
 
+       dev->dv_class = cd->cd_class;
+       dev->dv_cfdata = cf;
+       dev->dv_cfdriver = cd;
+       dev->dv_cfattach = ca;
+       dev->dv_activity_count = 0;
+       dev->dv_activity_handlers = NULL;
+       dev->dv_private = dev_private;
+       dev->dv_flags = ca->ca_flags;   /* inherit flags from class */
+
        myunit = config_unit_alloc(dev, cd, cf);
        if (myunit == -1) {
                config_devfree(dev);
@@ -1202,13 +1211,6 @@
        mutex_init(&dvl->dvl_mtx, MUTEX_DEFAULT, IPL_NONE);
        cv_init(&dvl->dvl_cv, "pmfsusp");
 
-       dev->dv_class = cd->cd_class;
-       dev->dv_cfdata = cf;
-       dev->dv_cfdriver = cd;
-       dev->dv_cfattach = ca;
-       dev->dv_activity_count = 0;
-       dev->dv_activity_handlers = NULL;
-       dev->dv_private = dev_private;
        memcpy(dev->dv_xname, cd->cd_name, lname);
        memcpy(dev->dv_xname + lname, xunit, lunit);
        dev->dv_parent = parent;
@@ -1216,8 +1218,7 @@
                dev->dv_depth = parent->dv_depth + 1;
        else
                dev->dv_depth = 0;
-       dev->dv_flags = DVF_ACTIVE;     /* always initially active */
-       dev->dv_flags |= ca->ca_flags;  /* inherit flags from class */
+       dev->dv_flags |= DVF_ACTIVE;    /* always initially active */
        if (locs) {
                KASSERT(parent); /* no locators at root */
                ia = cfiattr_lookup(cfdata_ifattr(cf), parent->dv_cfdriver);



Home | Main Index | Thread Index | Old Index