The cam_sim structure was being deallocated unconditionally by device
authorMatthew Dillon <dillon@dragonflybsd.org>
Mon, 15 Mar 2004 01:10:45 +0000 (01:10 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Mon, 15 Mar 2004 01:10:45 +0000 (01:10 +0000)
driver detach routines.  The problem with this is that part of the CAM
bus structure may still be active (for example, with pending timeout()'s),
and even though the bus, target, and device is freed, since the sim IS
freed any accesses through the sim will hit 0xdeadc0de.  This case most often
occurs with USB UMASS devices.

The CAM_XPT and CAM_SIM layer has been revamped.  CAM_DEV_UNCONFIGURED is now
accounted for in the device->refcount, and the cam_sim structure is now
ref-counted as well.  Additionally, the cam_simq* code which handles the
device queues has been revamped to refcount as well, so shared device queues
(raid and multi-channel devices) are not free()'d before all references have
gone away.

scsi_low free'd its cam_sim twice.  Fixed.

USB was improperly using M_NOWAIT.  All M_NOWAIT instances have been renamed
to M_INTWAIT.

45 files changed:
sys/bus/cam/cam_queue.c
sys/bus/cam/cam_queue.h
sys/bus/cam/cam_sim.c
sys/bus/cam/cam_sim.h
sys/bus/cam/cam_xpt.c
sys/bus/cam/scsi/scsi_low.c
sys/dev/disk/advansys/advansys.c
sys/dev/disk/advansys/adwcam.c
sys/dev/disk/aha/aha.c
sys/dev/disk/ahb/ahb.c
sys/dev/disk/aic/aic.c
sys/dev/disk/aic7xxx/ahc_eisa.c
sys/dev/disk/aic7xxx/ahc_pci.c
sys/dev/disk/aic7xxx/ahd_pci.c
sys/dev/disk/aic7xxx/aic79xx.c
sys/dev/disk/aic7xxx/aic79xx_osm.c
sys/dev/disk/aic7xxx/aic7xxx.c
sys/dev/disk/aic7xxx/aic7xxx_osm.c
sys/dev/disk/amd/amd.c
sys/dev/disk/ata/ata-all.c
sys/dev/disk/ata/ata-disk.c
sys/dev/disk/ata/atapi-all.c
sys/dev/disk/ata/atapi-cam.c
sys/dev/disk/buslogic/bt.c
sys/dev/disk/ccd/ccd.c
sys/dev/disk/fd/fd.c
sys/dev/disk/i386/bs/bsfunc.c
sys/dev/disk/i386/bs/bsif.c
sys/dev/disk/isp/isp_freebsd.c
sys/dev/disk/isp/isp_pci.c
sys/dev/disk/ispfw/ispfw.c
sys/dev/disk/mpt/mpt_freebsd.c
sys/dev/disk/ncr/ncr.c
sys/dev/disk/sbp/sbp.c
sys/dev/disk/simos/simos.c
sys/dev/disk/sym/sym_hipd.c
sys/dev/disk/trm/trm.c
sys/dev/disk/vpo/immio.c
sys/dev/disk/vpo/vpo.c
sys/dev/disk/vpo/vpoio.c
sys/dev/usbmisc/uhid/uhid.c
sys/dev/usbmisc/ukbd/ukbd.c
sys/dev/usbmisc/umass/umass.c
sys/dev/usbmisc/umct/umct.c
sys/dev/usbmisc/ums/ums.c

index 78ad59c..2c3ab4a 100644 (file)
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/cam_queue.c,v 1.5 1999/08/28 00:40:41 peter Exp $
- * $DragonFly: src/sys/bus/cam/cam_queue.c,v 1.4 2004/03/12 03:23:13 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/cam_queue.c,v 1.5 2004/03/15 01:10:30 dillon Exp $
  */
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -213,15 +213,24 @@ cam_devq_init(struct cam_devq *devq, int devices, int openings)
        devq->alloc_active = 0;
        devq->send_openings = openings;
        devq->send_active = 0;  
+       devq->refcount = 1;
        return (0);     
 }
 
 void
-cam_devq_free(struct cam_devq *devq)
+cam_devq_reference(struct cam_devq *devq)
 {
-       camq_fini(&devq->alloc_queue);
-       camq_fini(&devq->send_queue);
-       free(devq, M_DEVBUF);
+       ++devq->refcount;
+}
+
+void
+cam_devq_release(struct cam_devq *devq)
+{
+       if (--devq->refcount == 0) {
+               camq_fini(&devq->alloc_queue);
+               camq_fini(&devq->send_queue);
+               free(devq, M_DEVBUF);
+       }
 }
 
 u_int32_t
index 4c43332..d37443b 100644 (file)
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/cam_queue.h,v 1.6 1999/12/29 04:54:26 peter Exp $
- * $DragonFly: src/sys/bus/cam/cam_queue.h,v 1.2 2003/06/17 04:28:18 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/cam_queue.h,v 1.3 2004/03/15 01:10:30 dillon Exp $
  */
 
 #ifndef _CAM_CAM_QUEUE_H
@@ -74,6 +74,7 @@ struct cam_devq {
        int     alloc_active;
        int     send_openings;
        int     send_active;
+       int     refcount;
 };
 
 
@@ -81,9 +82,8 @@ struct cam_devq *cam_devq_alloc(int devices, int openings);
 
 int             cam_devq_init(struct cam_devq *devq, int devices,
                               int openings);
-
-void            cam_devq_free(struct cam_devq *devq);
-
+void            cam_devq_reference(struct cam_devq *devq);
+void            cam_devq_release(struct cam_devq *devq);
 u_int32_t       cam_devq_resize(struct cam_devq *camq, int openings);
        
 /*
index 26862fb..ca48a32 100644 (file)
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/cam_sim.c,v 1.3 1999/08/28 00:40:42 peter Exp $
- * $DragonFly: src/sys/bus/cam/cam_sim.c,v 1.5 2004/03/12 03:23:13 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/cam_sim.c,v 1.6 2004/03/15 01:10:30 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -47,9 +47,9 @@ cam_simq_alloc(u_int32_t max_sim_transactions)
 }
 
 void
-cam_simq_free(struct cam_devq *devq)
+cam_simq_release(struct cam_devq *devq)
 {
-       cam_devq_free(devq);
+       cam_devq_release(devq);
 }
 
 /*
@@ -65,7 +65,25 @@ cam_sim_alloc(sim_action_func sim_action, sim_poll_func sim_poll,
 {
        struct cam_sim *sim;
 
-       sim = malloc(sizeof(struct cam_sim), M_DEVBUF, M_INTWAIT);
+       /*
+        * XXX ahd was limited to 256 instead of 512 for unknown reasons,
+        * move that to a global limit here.  We may be able to remove this
+        * code, needs testing.
+        */
+       if (max_dev_transactions > 256)
+               max_dev_transactions = 256;
+       if (max_tagged_dev_transactions > 256)
+               max_tagged_dev_transactions = 256;
+
+       /*
+        * Allocate a simq or use the supplied (possibly shared) simq.
+        */
+       if (queue == NULL)
+               queue = cam_simq_alloc(max_tagged_dev_transactions);
+       else
+               cam_devq_reference(queue);
+
+       sim = malloc(sizeof(struct cam_sim), M_DEVBUF, M_INTWAIT | M_ZERO);
        sim->sim_action = sim_action;
        sim->sim_poll = sim_poll;
        sim->sim_name = sim_name;
@@ -76,6 +94,7 @@ cam_sim_alloc(sim_action_func sim_action, sim_poll_func sim_poll,
        sim->max_tagged_dev_openings = max_tagged_dev_transactions;
        sim->max_dev_openings = max_dev_transactions;
        sim->flags = 0;
+       sim->refcount = 1;
        callout_handle_init(&sim->c_handle);
        sim->devq = queue;
 
@@ -83,11 +102,26 @@ cam_sim_alloc(sim_action_func sim_action, sim_poll_func sim_poll,
 }
 
 void
-cam_sim_free(struct cam_sim *sim, int free_devq)
+cam_sim_free(struct cam_sim *sim)
+{
+       cam_sim_release(sim, CAM_SIM_DEVQ | CAM_SIM_SOFTC);
+}
+
+void
+cam_sim_release(struct cam_sim *sim, int flags)
 {
-       if (free_devq)
-               cam_simq_free(sim->devq);
-       free(sim, M_DEVBUF);
+       if (flags & CAM_SIM_SOFTC)
+               sim->softc = NULL;
+       if (flags & CAM_SIM_DEVQ) {
+               cam_simq_release(sim->devq);
+               sim->devq = NULL;
+       }
+       if (sim->refcount == 1) {
+               sim->refcount = 0;
+               free(sim, M_DEVBUF);
+       } else {
+               --sim->refcount;
+       }
 }
 
 void
index e155874..91dd56e 100644 (file)
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/cam_sim.h,v 1.4 1999/12/29 04:54:27 peter Exp $
- * $DragonFly: src/sys/bus/cam/cam_sim.h,v 1.3 2003/07/23 02:30:12 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/cam_sim.h,v 1.4 2004/03/15 01:10:30 dillon Exp $
  */
 
 #ifndef _CAM_CAM_SIM_H
@@ -50,7 +50,7 @@ typedef void (*sim_action_func)(struct cam_sim *sim, union ccb *ccb);
 typedef void (*sim_poll_func)(struct cam_sim *sim);
 
 struct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions);
-void             cam_simq_free(struct cam_devq *devq);
+void             cam_simq_release(struct cam_devq *devq);
 
 struct cam_sim *  cam_sim_alloc(sim_action_func sim_action,
                                sim_poll_func sim_poll,
@@ -60,7 +60,11 @@ struct cam_sim *  cam_sim_alloc(sim_action_func sim_action,
                                int max_dev_transactions,
                                int max_tagged_dev_transactions,
                                struct cam_devq *queue);
-void             cam_sim_free(struct cam_sim *sim, int free_devq);
+void             cam_sim_free(struct cam_sim *sim);
+void             cam_sim_release(struct cam_sim *sim, int flags);
+
+#define CAM_SIM_DEVQ   0x0001
+#define CAM_SIM_SOFTC  0x0002
 
 /* Optional sim attributes may be set with these. */
 void   cam_sim_set_path(struct cam_sim *sim, u_int32_t path_id);
@@ -90,8 +94,8 @@ struct cam_sim {
        sim_action_func         sim_action;
        sim_poll_func           sim_poll;
        const char              *sim_name;
-       void                    *softc;
-       u_int32_t               path_id;/* The Boot device may set this to 0? */
+       void                    *softc;         /* might be NULL */
+       u_int32_t               path_id;        /* bootdev may set this to 0? */
        u_int32_t               unit_number;
        u_int32_t               bus_id;
        int                     max_tagged_dev_openings;
@@ -100,6 +104,7 @@ struct cam_sim {
 #define                CAM_SIM_REL_TIMEOUT_PENDING     0x01
        struct callout_handle   c_handle;
        struct cam_devq         *devq;  /* Device Queue to use for this SIM */
+       int                     refcount;       /* References to the sim */
 };
 
 static __inline u_int32_t
index f8d8c9e..29b2b78 100644 (file)
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/cam_xpt.c,v 1.80.2.18 2002/12/09 17:31:55 gibbs Exp $
- * $DragonFly: src/sys/bus/cam/cam_xpt.c,v 1.10 2004/03/12 03:23:13 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/cam_xpt.c,v 1.11 2004/03/15 01:10:30 dillon Exp $
  */
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -41,6 +41,8 @@
 #include <sys/devicestat.h>
 #include <sys/interrupt.h>
 #include <sys/bus.h>
+#include <sys/thread.h>
+#include <sys/thread2.h>
 
 #ifdef PC98
 #include <pc98/pc98/pc98_machdep.h>    /* geometry translation */
@@ -1333,6 +1335,7 @@ xpt_init(dummy)
                                /*max_dev_transactions*/0,
                                /*max_tagged_dev_transactions*/0,
                                devq);
+       cam_simq_release(devq);
        xpt_max_ccbs = 16;
                                
        xpt_bus_register(xpt_sim, /*bus #*/0);
@@ -4063,6 +4066,7 @@ xpt_bus_register(struct cam_sim *sim, u_int32_t bus)
        TAILQ_INIT(&new_bus->et_entries);
        new_bus->path_id = sim->path_id;
        new_bus->sim = sim;
+       ++sim->refcount;
        timevalclear(&new_bus->last_reset);
        new_bus->flags = 0;
        new_bus->refcount = 1;  /* Held until a bus_deregister event */
@@ -4337,7 +4341,10 @@ xpt_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
                }
                xpt_release_path(&newpath);
        } else if (async_code == AC_LOST_DEVICE) {
-               device->flags |= CAM_DEV_UNCONFIGURED;
+               if ((device->flags & CAM_DEV_UNCONFIGURED) == 0) {
+                       device->flags |= CAM_DEV_UNCONFIGURED;
+                       xpt_release_device(bus, target, device);
+               }
        } else if (async_code == AC_TRANSFER_NEG) {
                struct ccb_trans_settings *settings;
 
@@ -4585,21 +4592,22 @@ xpt_get_ccb(struct cam_ed *device)
 static void
 xpt_release_bus(struct cam_eb *bus)
 {
-       int s;
 
-       s = splcam();
-#ifdef XPT_DEBUG_RELEASE
-       printf("xpt_release_bus(%p): %d %p\n", 
-               bus, bus->refcount, TAILQ_FIRST(&bus->et_entries));
-#endif
-       if ((--bus->refcount == 0)
-        && (TAILQ_FIRST(&bus->et_entries) == NULL)) {
+       crit_enter();
+       if (bus->refcount == 1) {
+               KKASSERT(TAILQ_FIRST(&bus->et_entries) == NULL);
                TAILQ_REMOVE(&xpt_busses, bus, links);
+               if (bus->sim) {
+                       cam_sim_release(bus->sim, 0);
+                       bus->sim = NULL;
+               }
                bus_generation++;
-               splx(s);
+               KKASSERT(bus->refcount == 1);
                free(bus, M_DEVBUF);
-       } else
-               splx(s);
+       } else {
+               --bus->refcount;
+       }
+       crit_exit();
 }
 
 static struct cam_et *
@@ -4639,23 +4647,18 @@ xpt_alloc_target(struct cam_eb *bus, target_id_t target_id)
 static void
 xpt_release_target(struct cam_eb *bus, struct cam_et *target)
 {
-       int s;
-
-       s = splcam();
-#ifdef XPT_DEBUG_RELEASE
-       printf("xpt_release_target(%p,%p): %d %p\n", 
-               bus, target, 
-               target->refcount, TAILQ_FIRST(&target->ed_entries));
-#endif
-       if ((--target->refcount == 0)
-        && (TAILQ_FIRST(&target->ed_entries) == NULL)) {
+       crit_enter();
+       if (target->refcount == 1) {
+               KKASSERT(TAILQ_FIRST(&target->ed_entries) == NULL);
                TAILQ_REMOVE(&bus->et_entries, target, links);
                bus->generation++;
-               splx(s);
-               free(target, M_DEVBUF);
                xpt_release_bus(bus);
-       } else
-               splx(s);
+               KKASSERT(target->refcount == 1);
+               free(target, M_DEVBUF);
+       } else {
+               --target->refcount;
+       }
+       crit_exit();
 }
 
 static struct cam_ed *
@@ -4740,22 +4743,21 @@ xpt_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
        return (device);
 }
 
+static void
+xpt_reference_device(struct cam_ed *device)
+{
+       ++device->refcount;
+}
+
 static void
 xpt_release_device(struct cam_eb *bus, struct cam_et *target,
                   struct cam_ed *device)
 {
-       int s;
-
-       s = splcam();
-#ifdef XPT_DEBUG_RELEASE
-       printf("xpt_release_device(%p,%p,%p): %d %08x\n", 
-               bus, target, device,
-               device->refcount, device->flags);
-#endif
+       struct cam_devq *devq;
 
-       if ((--device->refcount == 0)
-        && ((device->flags & CAM_DEV_UNCONFIGURED) != 0)) {
-               struct cam_devq *devq;
+       crit_enter();
+       if (device->refcount == 1) {
+               KKASSERT(device->flags & CAM_DEV_UNCONFIGURED);
 
                if (device->alloc_ccb_entry.pinfo.index != CAM_UNQUEUED_INDEX
                 || device->send_ccb_entry.pinfo.index != CAM_UNQUEUED_INDEX)
@@ -4773,11 +4775,13 @@ xpt_release_device(struct cam_eb *bus, struct cam_et *target,
                /* Release our slot in the devq */
                devq = bus->sim->devq;
                cam_devq_resize(devq, devq->alloc_queue.array_size - 1);
-               splx(s);
-               free(device, M_DEVBUF);
                xpt_release_target(bus, target);
-       } else
-               splx(s);
+               KKASSERT(device->refcount == 1);
+               free(device, M_DEVBUF);
+       } else {
+               --device->refcount;
+       }
+       crit_exit();
 }
 
 static u_int32_t
@@ -5499,6 +5503,7 @@ probedone(struct cam_periph *periph, union ccb *done_ccb)
                                        softc->action = PROBE_SERIAL_NUM;
 
                                path->device->flags &= ~CAM_DEV_UNCONFIGURED;
+                               xpt_reference_device(path->device);
 
                                xpt_release_ccb(done_ccb);
                                xpt_schedule(periph, priority);
@@ -5528,9 +5533,10 @@ probedone(struct cam_periph *periph, union ccb *done_ccb)
                 * already marked unconfigured, notify the peripheral
                 * drivers that this device is no more.
                 */
-               if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
+               if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
                        /* Send the async notification. */
                        xpt_async(AC_LOST_DEVICE, path, NULL);
+               }
 
                xpt_release_ccb(done_ccb);
                break;
@@ -5678,6 +5684,7 @@ probedone(struct cam_periph *periph, union ccb *done_ccb)
                }
 
                path->device->flags &= ~CAM_DEV_UNCONFIGURED;
+               xpt_reference_device(path->device);
 
                if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) {
                        /* Inform the XPT that a new device has been found */
index 31df24e..363e7f8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * $FreeBSD: src/sys/cam/scsi/scsi_low.c,v 1.1.2.5 2003/08/09 06:18:30 non Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_low.c,v 1.8 2004/03/12 03:23:19 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_low.c,v 1.9 2004/03/15 01:10:31 dillon Exp $
  * $NetBSD: scsi_low.c,v 1.24.10.8 2001/06/26 07:39:44 honda Exp $
  */
 
@@ -1401,14 +1401,14 @@ scsi_low_attach_cam(slp)
                                DEVPORT_DEVNAME(slp->sl_dev), slp,
                                DEVPORT_DEVUNIT(slp->sl_dev), 
                                slp->sl_openings, tagged_openings, devq);
-
+       cam_simq_release(devq);
        if (slp->sl_si.sim == NULL) {
-               cam_simq_free(devq);
                return ENODEV;
        }
 
        if (xpt_bus_register(slp->sl_si.sim, 0) != CAM_SUCCESS) {
-               free(slp->sl_si.sim, M_DEVBUF);
+               cam_sim_free(slp->sl_si.sim);
+               slp->sl_si.sim = NULL;
                return ENODEV;
        }
        
@@ -1416,8 +1416,8 @@ scsi_low_attach_cam(slp)
                        cam_sim_path(slp->sl_si.sim), CAM_TARGET_WILDCARD,
                        CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                xpt_bus_deregister(cam_sim_path(slp->sl_si.sim));
-               cam_sim_free(slp->sl_si.sim, /*free_simq*/TRUE);
-               free(slp->sl_si.sim, M_DEVBUF);
+               cam_sim_free(slp->sl_si.sim);
+               slp->sl_si.sim = NULL;
                return ENODEV;
        }
 
@@ -1443,7 +1443,8 @@ scsi_low_dettach_cam(slp)
        xpt_async(AC_LOST_DEVICE, slp->sl_si.path, NULL);
        xpt_free_path(slp->sl_si.path);
        xpt_bus_deregister(cam_sim_path(slp->sl_si.sim));
-       cam_sim_free(slp->sl_si.sim, /* free_devq */ TRUE);
+       cam_sim_free(slp->sl_si.sim);
+       slp->sl_si.sim = NULL;
        return 0;
 }
 
index 850c478..9a69798 100644 (file)
@@ -33,7 +33,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/advansys/advansys.c,v 1.14.2.4 2002/01/06 21:21:42 dwmalone Exp $
- * $DragonFly: src/sys/dev/disk/advansys/advansys.c,v 1.3 2003/08/07 21:16:50 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/advansys/advansys.c,v 1.4 2004/03/15 01:10:33 dillon Exp $
  */
 /*
  * Ported from:
@@ -1300,11 +1300,7 @@ adv_attach(adv)
         * upper level SCSI transaction it represents.
         */
        adv->ccb_infos = malloc(sizeof(*adv->ccb_infos) * adv->max_openings,
-                               M_DEVBUF, M_NOWAIT);
-
-       if (adv->ccb_infos == NULL)
-               return (ENOMEM);
-
+                               M_DEVBUF, M_WAITOK);
        adv->init_level++;
                
        /*
@@ -1388,18 +1384,11 @@ adv_attach(adv)
                return (ENXIO);
        }
 
-       /*
-        * Create the device queue for our SIM.
-        */
-       devq = cam_simq_alloc(adv->max_openings);
-       if (devq == NULL)
-               return (ENOMEM);
-
        /*
         * Construct our SIM entry.
         */
        adv->sim = cam_sim_alloc(adv_action, adv_poll, "adv", adv, adv->unit,
-                                1, adv->max_openings, devq);
+                                1, adv->max_openings, NULL);
        if (adv->sim == NULL)
                return (ENOMEM);
 
@@ -1409,7 +1398,7 @@ adv_attach(adv)
         * XXX Twin Channel EISA Cards???
         */
        if (xpt_bus_register(adv->sim, 0) != CAM_SUCCESS) {
-               cam_sim_free(adv->sim, /*free devq*/TRUE);
+               cam_sim_free(adv->sim);
                return (ENXIO);
        }
 
@@ -1417,7 +1406,7 @@ adv_attach(adv)
                            CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD)
            != CAM_REQ_CMP) {
                xpt_bus_deregister(cam_sim_path(adv->sim));
-               cam_sim_free(adv->sim, /*free devq*/TRUE);
+               cam_sim_free(adv->sim);
                return (ENXIO);
        }
 
index ba88d2d..075f644 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/advansys/adwcam.c,v 1.7.2.2 2001/03/05 13:08:55 obrien Exp $
- * $DragonFly: src/sys/dev/disk/advansys/adwcam.c,v 1.4 2003/08/07 21:16:50 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/advansys/adwcam.c,v 1.5 2004/03/15 01:10:33 dillon Exp $
  */
 /*
  * Ported from:
@@ -163,10 +163,7 @@ adwallocsgmap(struct adw_softc *adw)
 {
        struct sg_map_node *sg_map;
 
-       sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_NOWAIT);
-
-       if (sg_map == NULL)
-               return (NULL);
+       sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_WAITOK);
 
        /* Allocate S/G space for the next batch of ACBS */
        if (bus_dmamem_alloc(adw->sg_dmat, (void **)&sg_map->sg_vaddr,
@@ -824,11 +821,7 @@ adw_alloc(device_t dev, struct resource *regs, int regs_type, int regs_id)
        /*
         * Allocate a storage area for us
         */
-       adw = malloc(sizeof(struct adw_softc), M_DEVBUF, M_NOWAIT | M_ZERO);
-       if (adw == NULL) {
-               printf("adw%d: cannot malloc!\n", device_get_unit(dev));
-               return NULL;
-       }
+       adw = malloc(sizeof(struct adw_softc), M_DEVBUF, M_WAITOK | M_ZERO);
        LIST_INIT(&adw->pending_ccbs);
        SLIST_INIT(&adw->sg_maps);
        adw->device = dev;
@@ -838,13 +831,9 @@ adw_alloc(device_t dev, struct resource *regs, int regs_type, int regs_id)
        adw->regs = regs;
        adw->tag = rman_get_bustag(regs);
        adw->bsh = rman_get_bushandle(regs);
+       KKASSERT(adw->unit >= 0 && adw->unit < 100);
        i = adw->unit / 10;
-       adw->name = malloc(sizeof("adw") + i + 1, M_DEVBUF, M_NOWAIT);
-       if (adw->name == NULL) {
-               printf("adw%d: cannot malloc name!\n", adw->unit);
-               free(adw, M_DEVBUF);
-               return NULL;
-       }
+       adw->name = malloc(sizeof("adw") + i + 1, M_DEVBUF, M_WAITOK);
        sprintf(adw->name, "adw%d", adw->unit);
        return(adw);
 }
@@ -1162,7 +1151,6 @@ int
 adw_attach(struct adw_softc *adw)
 {
        struct ccb_setasync csa;
-       struct cam_devq *devq;
        int s;
        int error;
 
@@ -1179,18 +1167,11 @@ adw_attach(struct adw_softc *adw)
        /* Start the Risc processor now that we are fully configured. */
        adw_outw(adw, ADW_RISC_CSR, ADW_RISC_CSR_RUN);
 
-       /*
-        * Create the device queue for our SIM.
-        */
-       devq = cam_simq_alloc(adw->max_acbs);
-       if (devq == NULL)
-               return (ENOMEM);
-
        /*
         * Construct our SIM entry.
         */
        adw->sim = cam_sim_alloc(adw_action, adw_poll, "adw", adw, adw->unit,
-                                1, adw->max_acbs, devq);
+                                1, adw->max_acbs, NULL);
        if (adw->sim == NULL) {
                error = ENOMEM;
                goto fail;
@@ -1200,7 +1181,7 @@ adw_attach(struct adw_softc *adw)
         * Register the bus.
         */
        if (xpt_bus_register(adw->sim, 0) != CAM_SUCCESS) {
-               cam_sim_free(adw->sim, /*free devq*/TRUE);
+               cam_sim_free(adw->sim);
                error = ENOMEM;
                goto fail;
        }
index 5b26443..11dbee1 100644 (file)
@@ -56,7 +56,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/aha/aha.c,v 1.34.2.1 2000/08/02 22:24:39 peter Exp $
- * $DragonFly: src/sys/dev/disk/aha/aha.c,v 1.5 2003/11/15 21:05:41 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/aha/aha.c,v 1.6 2004/03/15 01:10:35 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -222,12 +222,7 @@ aha_alloc(int unit, bus_space_tag_t tag, bus_space_handle_t bsh)
                }
        }
 
-       aha = malloc(sizeof(struct aha_softc), M_DEVBUF, M_NOWAIT);
-       if (!aha) {
-               printf("aha%d: cannot malloc!\n", unit);
-               return NULL;    
-       }
-       bzero(aha, sizeof(struct aha_softc));
+       aha = malloc(sizeof(struct aha_softc), M_DEVBUF, M_WAITOK | M_ZERO);
        SLIST_INIT(&aha->free_aha_ccbs);
        LIST_INIT(&aha->pending_ccbs);
        SLIST_INIT(&aha->sg_maps);
@@ -654,13 +649,13 @@ aha_attach(struct aha_softc *aha)
         */
        aha->sim = cam_sim_alloc(ahaaction, ahapoll, "aha", aha, aha->unit,
                                2, tagged_dev_openings, devq);
+       cam_simq_release(devq);
        if (aha->sim == NULL) {
-               cam_simq_free(devq);
                return (ENOMEM);
        }
        
        if (xpt_bus_register(aha->sim, 0) != CAM_SUCCESS) {
-               cam_sim_free(aha->sim, /*free_devq*/TRUE);
+               cam_sim_free(aha->sim);
                return (ENXIO);
        }
        
@@ -668,7 +663,7 @@ aha_attach(struct aha_softc *aha)
                            cam_sim_path(aha->sim), CAM_TARGET_WILDCARD,
                            CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                xpt_bus_deregister(cam_sim_path(aha->sim));
-               cam_sim_free(aha->sim, /*free_devq*/TRUE);
+               cam_sim_free(aha->sim);
                return (ENXIO);
        }
                
@@ -733,10 +728,7 @@ ahaallocccbs(struct aha_softc *aha)
 
        next_ccb = &aha->aha_ccb_array[aha->num_ccbs];
 
-       sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_NOWAIT);
-
-       if (sg_map == NULL)
-               return;
+       sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_WAITOK);
 
        /* Allocate S/G space for the next batch of CCBS */
        if (bus_dmamem_alloc(aha->sg_dmat, (void **)&sg_map->sg_vaddr,
@@ -1974,6 +1966,6 @@ aha_detach(struct aha_softc *aha)
        xpt_async(AC_LOST_DEVICE, aha->path, NULL);
        xpt_free_path(aha->path);
        xpt_bus_deregister(cam_sim_path(aha->sim));
-       cam_sim_free(aha->sim, /*free_devq*/TRUE);
+       cam_sim_free(aha->sim);
        return (0);
 }
index 14e2f27..66cc987 100644 (file)
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ahb/ahb.c,v 1.18.2.3 2001/03/05 13:08:55 obrien Exp $
- * $DragonFly: src/sys/dev/disk/ahb/ahb.c,v 1.4 2003/08/07 21:16:50 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/ahb/ahb.c,v 1.5 2004/03/15 01:10:38 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -393,11 +393,7 @@ ahballoc(u_long unit, struct resource *res)
        /*
         * Allocate a storage area for us
         */
-       ahb = malloc(sizeof(struct ahb_softc), M_DEVBUF, M_NOWAIT | M_ZERO);
-       if (!ahb) {
-               printf("ahb%ld: cannot malloc!\n", unit);
-               return (NULL);
-       }
+       ahb = malloc(sizeof(struct ahb_softc), M_DEVBUF, M_WAITOK | M_ZERO);
        SLIST_INIT(&ahb->free_ecbs);
        LIST_INIT(&ahb->pending_ccbs);
        ahb->unit = unit;
@@ -484,7 +480,6 @@ ahbmapecbs(void *arg, bus_dma_segment_t *segs, int nseg, int error)
 static int
 ahbxptattach(struct ahb_softc *ahb)
 {
-       struct cam_devq *devq;
        struct ecb *ecb;
        u_int  i;
 
@@ -527,25 +522,16 @@ ahbxptattach(struct ahb_softc *ahb)
 
        ahbecbfree(ahb, ecb);
 
-       /*
-        * Create the device queue for our SIM.
-        */
-       devq = cam_simq_alloc(ahb->num_ecbs);
-       if (devq == NULL)
-               return (ENOMEM);
-
        /*
         * Construct our SIM entry
         */
        ahb->sim = cam_sim_alloc(ahbaction, ahbpoll, "ahb", ahb, ahb->unit,
-                                2, ahb->num_ecbs, devq);
-       if (ahb->sim == NULL) {
-               cam_simq_free(devq);
+                                2, ahb->num_ecbs, NULL);
+       if (ahb->sim == NULL)
                return (ENOMEM);
-       }
 
        if (xpt_bus_register(ahb->sim, 0) != CAM_SUCCESS) {
-               cam_sim_free(ahb->sim, /*free_devq*/TRUE);
+               cam_sim_free(ahb->sim);
                return (ENXIO);
        }
        
@@ -553,7 +539,7 @@ ahbxptattach(struct ahb_softc *ahb)
                            cam_sim_path(ahb->sim), CAM_TARGET_WILDCARD,
                            CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                xpt_bus_deregister(cam_sim_path(ahb->sim));
-               cam_sim_free(ahb->sim, /*free_devq*/TRUE);
+               cam_sim_free(ahb->sim);
                return (ENXIO);
        }
                
index 454d72b..82f02f6 100644 (file)
@@ -24,7 +24,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/aic/aic.c,v 1.8 2000/01/14 23:42:35 imp Exp $
- * $DragonFly: src/sys/dev/disk/aic/aic.c,v 1.4 2003/08/27 10:35:16 rob Exp $
+ * $DragonFly: src/sys/dev/disk/aic/aic.c,v 1.5 2004/03/15 01:10:42 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -1478,27 +1478,16 @@ aic_probe(struct aic_softc *aic)
 int
 aic_attach(struct aic_softc *aic)
 {
-       struct cam_devq *devq;
-
-       /*
-        * Create the device queue for our SIM.
-        */
-       devq = cam_simq_alloc(256);
-       if (devq == NULL)
-               return (ENOMEM);
-
        /*
         * Construct our SIM entry
         */
        aic->sim = cam_sim_alloc(aic_action, aic_poll, "aic", aic,
-                                aic->unit, 2, 256, devq);
-       if (aic->sim == NULL) {
-               cam_simq_free(devq);
+                                aic->unit, 2, 256, NULL);
+       if (aic->sim == NULL)
                return (ENOMEM);
-       }
 
        if (xpt_bus_register(aic->sim, 0) != CAM_SUCCESS) {
-               cam_sim_free(aic->sim, /*free_devq*/TRUE);
+               cam_sim_free(aic->sim);
                return (ENXIO);
        }
 
@@ -1506,7 +1495,7 @@ aic_attach(struct aic_softc *aic)
                            cam_sim_path(aic->sim), CAM_TARGET_WILDCARD,
                            CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                xpt_bus_deregister(cam_sim_path(aic->sim));
-               cam_sim_free(aic->sim, /*free_devq*/TRUE);
+               cam_sim_free(aic->sim);
                return (ENXIO);
        }
 
@@ -1530,6 +1519,6 @@ aic_detach(struct aic_softc *aic)
        xpt_async(AC_LOST_DEVICE, aic->path, NULL);
        xpt_free_path(aic->path);
        xpt_bus_deregister(cam_sim_path(aic->sim));
-       cam_sim_free(aic->sim, /*free_devq*/TRUE);
+       cam_sim_free(aic->sim);
        return (0);
 }
index 87c4a8d..b491163 100644 (file)
@@ -29,7 +29,7 @@
  * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/ahc_eisa.c#11 $
  *
  * $FreeBSD: src/sys/dev/aic7xxx/ahc_eisa.c,v 1.15.2.11 2003/06/10 03:26:07 gibbs Exp $
- * $DragonFly: src/sys/dev/disk/aic7xxx/ahc_eisa.c,v 1.3 2003/08/07 21:16:51 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/aic7xxx/ahc_eisa.c,v 1.4 2004/03/15 01:10:42 dillon Exp $
  */
 
 #include "aic7xxx_osm.h"
@@ -120,9 +120,7 @@ aic7770_attach(device_t dev)
         * set it up for attachment by our
         * common detect routine.
         */
-       name = malloc(strlen(device_get_nameunit(dev)) + 1, M_DEVBUF, M_NOWAIT);
-       if (name == NULL)
-               return (ENOMEM);
+       name = malloc(strlen(device_get_nameunit(dev)) + 1, M_DEVBUF, M_WAITOK);
        strcpy(name, device_get_nameunit(dev));
        ahc = ahc_alloc(dev, name);
        if (ahc == NULL)
index f616aee..e52d8b2 100644 (file)
@@ -31,7 +31,7 @@
  * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/ahc_pci.c#13 $
  *
  * $FreeBSD: src/sys/dev/aic7xxx/ahc_pci.c,v 1.29.2.14 2003/06/10 03:26:07 gibbs Exp $
- * $DragonFly: src/sys/dev/disk/aic7xxx/ahc_pci.c,v 1.4 2003/11/15 21:05:41 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/aic7xxx/ahc_pci.c,v 1.5 2004/03/15 01:10:42 dillon Exp $
  */
 
 #include "aic7xxx_osm.h"
@@ -91,9 +91,7 @@ ahc_pci_attach(device_t dev)
         * set it up for attachment by our
         * common detect routine.
         */
-       name = malloc(strlen(device_get_nameunit(dev)) + 1, M_DEVBUF, M_NOWAIT);
-       if (name == NULL)
-               return (ENOMEM);
+       name = malloc(strlen(device_get_nameunit(dev)) + 1, M_DEVBUF, M_WAITOK);
        strcpy(name, device_get_nameunit(dev));
        ahc = ahc_alloc(dev, name);
        if (ahc == NULL)
index 159c211..023f281 100644 (file)
@@ -31,7 +31,7 @@
  * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/ahd_pci.c#13 $
  *
  * $FreeBSD: src/sys/dev/aic7xxx/ahd_pci.c,v 1.2.2.5 2003/06/10 03:26:07 gibbs Exp $
- * $DragonFly: src/sys/dev/disk/aic7xxx/ahd_pci.c,v 1.4 2003/11/15 21:05:41 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/aic7xxx/ahd_pci.c,v 1.5 2004/03/15 01:10:42 dillon Exp $
  */
 
 #include "aic79xx_osm.h"
@@ -94,9 +94,7 @@ ahd_pci_attach(device_t dev)
         * set it up for attachment by our
         * common detect routine.
         */
-       name = malloc(strlen(device_get_nameunit(dev)) + 1, M_DEVBUF, M_NOWAIT);
-       if (name == NULL)
-               return (ENOMEM);
+       name = malloc(strlen(device_get_nameunit(dev)) + 1, M_DEVBUF, M_WAITOK);
        strcpy(name, device_get_nameunit(dev));
        ahd = ahd_alloc(dev, name);
        if (ahd == NULL)
index e2414b8..56dc7de 100644 (file)
@@ -40,7 +40,7 @@
  * $Id: //depot/aic7xxx/aic7xxx/aic79xx.c#198 $
  *
  * $FreeBSD: src/sys/dev/aic7xxx/aic79xx.c,v 1.3.2.5 2003/06/10 03:26:07 gibbs Exp $
- * $DragonFly: src/sys/dev/disk/aic7xxx/aic79xx.c,v 1.4 2004/02/13 01:04:14 joerg Exp $
+ * $DragonFly: src/sys/dev/disk/aic7xxx/aic79xx.c,v 1.5 2004/03/15 01:10:42 dillon Exp $
  */
 
 #include "aic79xx_osm.h"
@@ -2348,9 +2348,7 @@ ahd_alloc_tstate(struct ahd_softc *ahd, u_int scsi_id, char channel)
         && ahd->enabled_targets[scsi_id] != master_tstate)
                panic("%s: ahd_alloc_tstate - Target already allocated",
                      ahd_name(ahd));
-       tstate = malloc(sizeof(*tstate), M_DEVBUF, M_NOWAIT);
-       if (tstate == NULL)
-               return (NULL);
+       tstate = malloc(sizeof(*tstate), M_DEVBUF, M_WAITOK);
 
        /*
         * If we have allocated a master tstate, copy user settings from
@@ -4780,25 +4778,12 @@ ahd_alloc(void *platform_arg, char *name)
        struct  ahd_softc *ahd;
 
 #if !defined(__DragonFly__) && !defined(__FreeBSD__)
-       ahd = malloc(sizeof(*ahd), M_DEVBUF, M_NOWAIT);
-       if (!ahd) {
-               printf("aic7xxx: cannot malloc softc!\n");
-               free(name, M_DEVBUF);
-               return NULL;
-       }
+       ahd = malloc(sizeof(*ahd), M_DEVBUF, M_WAITOK);
 #else
        ahd = device_get_softc((device_t)platform_arg);
 #endif
        memset(ahd, 0, sizeof(*ahd));
-       ahd->seep_config = malloc(sizeof(*ahd->seep_config),
-                                 M_DEVBUF, M_NOWAIT);
-       if (ahd->seep_config == NULL) {
-#if !defined(__DragonFly__) && !defined(__FreeBSD__)
-               free(ahd, M_DEVBUF);
-#endif
-               free(name, M_DEVBUF);
-               return (NULL);
-       }
+       ahd->seep_config = malloc(sizeof(*ahd->seep_config),M_DEVBUF,M_WAITOK);
        LIST_INIT(&ahd->pending_scbs);
        /* We don't know our unit number until the OSM sets it */
        ahd->name = name;
@@ -5605,10 +5590,7 @@ ahd_alloc_scbs(struct ahd_softc *ahd)
                hscb = &((struct hardware_scb *)hscb_map->vaddr)[offset];
                hscb_busaddr = hscb_map->physaddr + (offset * sizeof(*hscb));
        } else {
-               hscb_map = malloc(sizeof(*hscb_map), M_DEVBUF, M_NOWAIT);
-
-               if (hscb_map == NULL)
-                       return;
+               hscb_map = malloc(sizeof(*hscb_map), M_DEVBUF, M_WAITOK);
 
                /* Allocate the next batch of hardware SCBs */
                if (ahd_dmamem_alloc(ahd, scb_data->hscb_dmat,
@@ -5638,10 +5620,7 @@ ahd_alloc_scbs(struct ahd_softc *ahd)
                segs = sg_map->vaddr + offset;
                sg_busaddr = sg_map->physaddr + offset;
        } else {
-               sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_NOWAIT);
-
-               if (sg_map == NULL)
-                       return;
+               sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_WAITOK);
 
                /* Allocate the next batch of S/G lists */
                if (ahd_dmamem_alloc(ahd, scb_data->sg_dmat,
@@ -5675,10 +5654,7 @@ ahd_alloc_scbs(struct ahd_softc *ahd)
                sense_data = sense_map->vaddr + offset;
                sense_busaddr = sense_map->physaddr + offset;
        } else {
-               sense_map = malloc(sizeof(*sense_map), M_DEVBUF, M_NOWAIT);
-
-               if (sense_map == NULL)
-                       return;
+               sense_map = malloc(sizeof(*sense_map), M_DEVBUF, M_WAITOK);
 
                /* Allocate the next batch of sense buffers */
                if (ahd_dmamem_alloc(ahd, scb_data->sense_dmat,
@@ -5716,17 +5692,8 @@ ahd_alloc_scbs(struct ahd_softc *ahd)
 #ifndef __linux__
                int error;
 #endif
-               next_scb = (struct scb *)malloc(sizeof(*next_scb),
-                                               M_DEVBUF, M_NOWAIT);
-               if (next_scb == NULL)
-                       break;
-
-               pdata = (struct scb_platform_data *)malloc(sizeof(*pdata),
-                                                          M_DEVBUF, M_NOWAIT);
-               if (pdata == NULL) {
-                       free(next_scb, M_DEVBUF);
-                       break;
-               }
+               next_scb = malloc(sizeof(*next_scb), M_DEVBUF, M_WAITOK);
+               pdata = malloc(sizeof(*pdata), M_DEVBUF, M_WAITOK);
                next_scb->platform_data = pdata;
                next_scb->hscb_map = hscb_map;
                next_scb->sg_map = sg_map;
@@ -5833,9 +5800,7 @@ ahd_init(struct ahd_softc *ahd)
 
        ahd->stack_size = ahd_probe_stack_size(ahd);
        ahd->saved_stack = malloc(ahd->stack_size * sizeof(uint16_t),
-                                 M_DEVBUF, M_NOWAIT);
-       if (ahd->saved_stack == NULL)
-               return (ENOMEM);
+                                 M_DEVBUF, M_WAITOK);
 
        /*
         * Verify that the compiler hasn't over-agressively
@@ -8219,9 +8184,7 @@ ahd_loadseq(struct ahd_softc *ahd)
        if (cs_count != 0) {
 
                cs_count *= sizeof(struct cs);
-               ahd->critical_sections = malloc(cs_count, M_DEVBUF, M_NOWAIT);
-               if (ahd->critical_sections == NULL)
-                       panic("ahd_loadseq: Could not malloc");
+               ahd->critical_sections = malloc(cs_count, M_DEVBUF, M_WAITOK);
                memcpy(ahd->critical_sections, cs_table, cs_count);
        }
        ahd_outb(ahd, SEQCTL0, PERRORDIS|FAILDIS|FASTMODE);
@@ -9141,14 +9104,7 @@ ahd_handle_en_lun(struct ahd_softc *ahd, struct cam_sim *sim, union ccb *ccb)
                                return;
                        }
                }
-               lstate = malloc(sizeof(*lstate), M_DEVBUF, M_NOWAIT);
-               if (lstate == NULL) {
-                       xpt_print_path(ccb->ccb_h.path);
-                       printf("Couldn't allocate lstate\n");
-                       ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
-                       return;
-               }
-               memset(lstate, 0, sizeof(*lstate));
+               lstate = malloc(sizeof(*lstate), M_DEVBUF, M_WAITOK | M_ZERO);
                status = xpt_create_path(&lstate->path, /*periph*/NULL,
                                         xpt_path_path_id(ccb->ccb_h.path),
                                         xpt_path_target_id(ccb->ccb_h.path),
index f444b59..2a63a75 100644 (file)
@@ -32,7 +32,7 @@
  * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic79xx_osm.c#27 $
  *
  * $FreeBSD: src/sys/dev/aic7xxx/aic79xx_osm.c,v 1.3.2.4 2003/06/10 03:26:07 gibbs Exp $
- * $DragonFly: src/sys/dev/disk/aic7xxx/aic79xx_osm.c,v 1.3 2003/08/07 21:16:51 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/aic7xxx/aic79xx_osm.c,v 1.4 2004/03/15 01:10:42 dillon Exp $
  */
 
 #include "aic79xx_osm.h"
@@ -115,7 +115,6 @@ ahd_attach(struct ahd_softc *ahd)
 {
        char   ahd_info[256];
        struct ccb_setasync csa;
-       struct cam_devq *devq;
        struct cam_sim *sim;
        struct cam_path *path;
        long s;
@@ -128,26 +127,17 @@ ahd_attach(struct ahd_softc *ahd)
        printf("%s\n", ahd_info);
        ahd_lock(ahd, &s);
 
-       /*
-        * Create the device queue for our SIM(s).
-        */
-       devq = cam_simq_alloc(AHD_MAX_QUEUE);
-       if (devq == NULL)
-               goto fail;
-
        /*
         * Construct our SIM entry
         */
        sim = cam_sim_alloc(ahd_action, ahd_poll, "ahd", ahd,
                            device_get_unit(ahd->dev_softc),
-                           1, /*XXX*/256, devq);
-       if (sim == NULL) {
-               cam_simq_free(devq);
+                           1, AHD_MAX_QUEUE, NULL);
+       if (sim == NULL)
                goto fail;
-       }
 
        if (xpt_bus_register(sim, /*bus_id*/0) != CAM_SUCCESS) {
-               cam_sim_free(sim, /*free_devq*/TRUE);
+               cam_sim_free(sim);
                sim = NULL;
                goto fail;
        }
@@ -156,7 +146,7 @@ ahd_attach(struct ahd_softc *ahd)
                            cam_sim_path(sim), CAM_TARGET_WILDCARD,
                            CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                xpt_bus_deregister(cam_sim_path(sim));
-               cam_sim_free(sim, /*free_devq*/TRUE);
+               cam_sim_free(sim);
                sim = NULL;
                goto fail;
        }
@@ -1739,9 +1729,7 @@ int
 ahd_platform_alloc(struct ahd_softc *ahd, void *platform_arg)
 {
        ahd->platform_data = malloc(sizeof(struct ahd_platform_data), M_DEVBUF,
-           M_NOWAIT | M_ZERO);
-       if (ahd->platform_data == NULL)
-               return (ENOMEM);
+                                   M_WAITOK | M_ZERO);
        return (0);
 }
 
@@ -1773,13 +1761,13 @@ ahd_platform_free(struct ahd_softc *ahd)
                        xpt_async(AC_LOST_DEVICE, pdata->path_b, NULL);
                        xpt_free_path(pdata->path_b);
                        xpt_bus_deregister(cam_sim_path(pdata->sim_b));
-                       cam_sim_free(pdata->sim_b, /*free_devq*/TRUE);
+                       cam_sim_free(pdata->sim_b);
                }
                if (pdata->sim != NULL) {
                        xpt_async(AC_LOST_DEVICE, pdata->path, NULL);
                        xpt_free_path(pdata->path);
                        xpt_bus_deregister(cam_sim_path(pdata->sim));
-                       cam_sim_free(pdata->sim, /*free_devq*/TRUE);
+                       cam_sim_free(pdata->sim);
                }
                if (pdata->eh != NULL)
                        EVENTHANDLER_DEREGISTER(shutdown_final, pdata->eh);
index 4128593..852cc68 100644 (file)
@@ -40,7 +40,7 @@
  * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.c#134 $
  *
  * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx.c,v 1.41.2.27 2003/06/10 03:26:08 gibbs Exp $
- * $DragonFly: src/sys/dev/disk/aic7xxx/aic7xxx.c,v 1.4 2004/02/13 01:04:14 joerg Exp $
+ * $DragonFly: src/sys/dev/disk/aic7xxx/aic7xxx.c,v 1.5 2004/03/15 01:10:42 dillon Exp $
  */
 
 #include "aic7xxx_osm.h"
@@ -1562,10 +1562,7 @@ ahc_alloc_tstate(struct ahc_softc *ahc, u_int scsi_id, char channel)
         && ahc->enabled_targets[scsi_id] != master_tstate)
                panic("%s: ahc_alloc_tstate - Target already allocated",
                      ahc_name(ahc));
-       tstate = (struct ahc_tmode_tstate*)malloc(sizeof(*tstate),
-                                                  M_DEVBUF, M_NOWAIT);
-       if (tstate == NULL)
-               return (NULL);
+       tstate = malloc(sizeof(*tstate), M_DEVBUF, M_WAITOK);
 
        /*
         * If we have allocated a master tstate, copy user settings from
@@ -3805,25 +3802,13 @@ ahc_alloc(void *platform_arg, char *name)
        int     i;
 
 #if !defined(__DragonFly__) && !defined(__FreeBSD__)
-       ahc = malloc(sizeof(*ahc), M_DEVBUF, M_NOWAIT);
-       if (!ahc) {
-               printf("aic7xxx: cannot malloc softc!\n");
-               free(name, M_DEVBUF);
-               return NULL;
-       }
+       ahc = malloc(sizeof(*ahc), M_DEVBUF, M_WAITOK);
 #else
        ahc = device_get_softc((device_t)platform_arg);
 #endif
        memset(ahc, 0, sizeof(*ahc));
        ahc->seep_config = malloc(sizeof(*ahc->seep_config),
-                                 M_DEVBUF, M_NOWAIT);
-       if (ahc->seep_config == NULL) {
-#if !defined(__DragonFly__) && !defined(__FreeBSD__)
-               free(ahc, M_DEVBUF);
-#endif
-               free(name, M_DEVBUF);
-               return (NULL);
-       }
+                                 M_DEVBUF, M_WAITOK);
        LIST_INIT(&ahc->pending_scbs);
        /* We don't know our unit number until the OSM sets it */
        ahc->name = name;
@@ -3864,10 +3849,7 @@ ahc_softc_init(struct ahc_softc *ahc)
        /* XXX The shared scb data stuff should be deprecated */
        if (ahc->scb_data == NULL) {
                ahc->scb_data = malloc(sizeof(*ahc->scb_data),
-                                      M_DEVBUF, M_NOWAIT);
-               if (ahc->scb_data == NULL)
-                       return (ENOMEM);
-               memset(ahc->scb_data, 0, sizeof(*ahc->scb_data));
+                                      M_DEVBUF, M_WAITOK | M_ZERO);
        }
 
        return (0);
@@ -4261,12 +4243,8 @@ ahc_init_scbdata(struct ahc_softc *ahc)
        SLIST_INIT(&scb_data->sg_maps);
 
        /* Allocate SCB resources */
-       scb_data->scbarray =
-           (struct scb *)malloc(sizeof(struct scb) * AHC_SCB_MAX_ALLOC,
-                                M_DEVBUF, M_NOWAIT);
-       if (scb_data->scbarray == NULL)
-               return (ENOMEM);
-       memset(scb_data->scbarray, 0, sizeof(struct scb) * AHC_SCB_MAX_ALLOC);
+       scb_data->scbarray = malloc(sizeof(struct scb) * AHC_SCB_MAX_ALLOC,
+                                   M_DEVBUF, M_WAITOK | M_ZERO);
 
        /* Determine the number of hardware SCBs and initialize them */
 
@@ -4463,10 +4441,7 @@ ahc_alloc_scbs(struct ahc_softc *ahc)
 
        next_scb = &scb_data->scbarray[scb_data->numscbs];
 
-       sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_NOWAIT);
-
-       if (sg_map == NULL)
-               return;
+       sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_WAITOK);
 
        /* Allocate S/G space for the next batch of SCBS */
        if (ahc_dmamem_alloc(ahc, scb_data->sg_dmat,
@@ -4492,10 +4467,7 @@ ahc_alloc_scbs(struct ahc_softc *ahc)
 #ifndef __linux__
                int error;
 #endif
-               pdata = (struct scb_platform_data *)malloc(sizeof(*pdata),
-                                                          M_DEVBUF, M_NOWAIT);
-               if (pdata == NULL)
-                       break;
+               pdata = malloc(sizeof(*pdata), M_DEVBUF, M_WAITOK);
                next_scb->platform_data = pdata;
                next_scb->sg_map = sg_map;
                next_scb->sg_list = segs;
@@ -6413,11 +6385,8 @@ ahc_loadseq(struct ahc_softc *ahc)
 
        ahc->num_critical_sections = cs_count;
        if (cs_count != 0) {
-
                cs_count *= sizeof(struct cs);
-               ahc->critical_sections = malloc(cs_count, M_DEVBUF, M_NOWAIT);
-               if (ahc->critical_sections == NULL)
-                       panic("ahc_loadseq: Could not malloc");
+               ahc->critical_sections = malloc(cs_count, M_DEVBUF, M_WAITOK);
                memcpy(ahc->critical_sections, cs_table, cs_count);
        }
        ahc_outb(ahc, SEQCTL, PERRORDIS|FAILDIS|FASTMODE);
@@ -7032,14 +7001,7 @@ ahc_handle_en_lun(struct ahc_softc *ahc, struct cam_sim *sim, union ccb *ccb)
                                return;
                        }
                }
-               lstate = malloc(sizeof(*lstate), M_DEVBUF, M_NOWAIT);
-               if (lstate == NULL) {
-                       xpt_print_path(ccb->ccb_h.path);
-                       printf("Couldn't allocate lstate\n");
-                       ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
-                       return;
-               }
-               memset(lstate, 0, sizeof(*lstate));
+               lstate = malloc(sizeof(*lstate), M_DEVBUF, M_WAITOK | M_ZERO);
                status = xpt_create_path(&lstate->path, /*periph*/NULL,
                                         xpt_path_path_id(ccb->ccb_h.path),
                                         xpt_path_target_id(ccb->ccb_h.path),
index 4690dba..1861188 100644 (file)
@@ -31,7 +31,7 @@
  * $Id: //depot/aic7xxx/freebsd/dev/aic7xxx/aic7xxx_osm.c#13 $
  *
  * $FreeBSD: src/sys/dev/aic7xxx/aic7xxx_osm.c,v 1.27.2.6 2003/06/10 03:26:09 gibbs Exp $
- * $DragonFly: src/sys/dev/disk/aic7xxx/aic7xxx_osm.c,v 1.3 2003/08/07 21:16:51 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/aic7xxx/aic7xxx_osm.c,v 1.4 2004/03/15 01:10:42 dillon Exp $
  */
 
 #include "aic7xxx_osm.h"
@@ -107,7 +107,6 @@ ahc_attach(struct ahc_softc *ahc)
 {
        char   ahc_info[256];
        struct ccb_setasync csa;
-       struct cam_devq *devq;
        int bus_id;
        int bus_id2;
        struct cam_sim *sim;
@@ -137,26 +136,17 @@ ahc_attach(struct ahc_softc *ahc)
                bus_id2 = 1;
        }
 
-       /*
-        * Create the device queue for our SIM(s).
-        */
-       devq = cam_simq_alloc(AHC_MAX_QUEUE);
-       if (devq == NULL)
-               goto fail;
-
        /*
         * Construct our first channel SIM entry
         */
        sim = cam_sim_alloc(ahc_action, ahc_poll, "ahc", ahc,
                            device_get_unit(ahc->dev_softc),
-                           1, AHC_MAX_QUEUE, devq);
-       if (sim == NULL) {
-               cam_simq_free(devq);
+                           1, AHC_MAX_QUEUE, NULL);
+       if (sim == NULL)
                goto fail;
-       }
 
        if (xpt_bus_register(sim, bus_id) != CAM_SUCCESS) {
-               cam_sim_free(sim, /*free_devq*/TRUE);
+               cam_sim_free(sim);
                sim = NULL;
                goto fail;
        }
@@ -165,7 +155,7 @@ ahc_attach(struct ahc_softc *ahc)
                            cam_sim_path(sim), CAM_TARGET_WILDCARD,
                            CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                xpt_bus_deregister(cam_sim_path(sim));
-               cam_sim_free(sim, /*free_devq*/TRUE);
+               cam_sim_free(sim);
                sim = NULL;
                goto fail;
        }
@@ -181,7 +171,7 @@ ahc_attach(struct ahc_softc *ahc)
        if (ahc->features & AHC_TWIN) {
                sim2 = cam_sim_alloc(ahc_action, ahc_poll, "ahc",
                                    ahc, device_get_unit(ahc->dev_softc), 1,
-                                   AHC_MAX_QUEUE, devq);
+                                   AHC_MAX_QUEUE, NULL);
 
                if (sim2 == NULL) {
                        printf("ahc_attach: Unable to attach second "
@@ -196,7 +186,7 @@ ahc_attach(struct ahc_softc *ahc)
                         * We do not want to destroy the device queue
                         * because the first bus is using it.
                         */
-                       cam_sim_free(sim2, /*free_devq*/FALSE);
+                       cam_sim_free(sim2);
                        goto fail;
                }
 
@@ -205,7 +195,7 @@ ahc_attach(struct ahc_softc *ahc)
                                    CAM_TARGET_WILDCARD,
                                    CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                        xpt_bus_deregister(cam_sim_path(sim2));
-                       cam_sim_free(sim2, /*free_devq*/FALSE);
+                       cam_sim_free(sim2);
                        sim2 = NULL;
                        goto fail;
                }
@@ -1854,9 +1844,7 @@ int
 ahc_platform_alloc(struct ahc_softc *ahc, void *platform_arg)
 {
        ahc->platform_data = malloc(sizeof(struct ahc_platform_data), M_DEVBUF,
-           M_NOWAIT | M_ZERO);
-       if (ahc->platform_data == NULL)
-               return (ENOMEM);
+                                   M_WAITOK | M_ZERO);
        return (0);
 }
 
@@ -1882,13 +1870,13 @@ ahc_platform_free(struct ahc_softc *ahc)
                        xpt_async(AC_LOST_DEVICE, pdata->path_b, NULL);
                        xpt_free_path(pdata->path_b);
                        xpt_bus_deregister(cam_sim_path(pdata->sim_b));
-                       cam_sim_free(pdata->sim_b, /*free_devq*/TRUE);
+                       cam_sim_free(pdata->sim_b);
                }
                if (pdata->sim != NULL) {
                        xpt_async(AC_LOST_DEVICE, pdata->path, NULL);
                        xpt_free_path(pdata->path);
                        xpt_bus_deregister(cam_sim_path(pdata->sim));
-                       cam_sim_free(pdata->sim, /*free_devq*/TRUE);
+                       cam_sim_free(pdata->sim);
                }
                if (pdata->eh != NULL)
                        EVENTHANDLER_DEREGISTER(shutdown_final, pdata->eh);
index 5d4db57..6fa8129 100644 (file)
@@ -31,7 +31,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *********************************************************************
  * $FreeBSD: src/sys/pci/amd.c,v 1.3.2.2 2001/06/02 04:32:50 nyan Exp $
- * $DragonFly: src/sys/dev/disk/amd/amd.c,v 1.3 2003/08/07 21:16:51 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/amd/amd.c,v 1.4 2004/03/15 01:10:42 dillon Exp $
  */
 
 /*
@@ -2403,15 +2403,15 @@ amd_attach(device_t dev)
        amd->psim = cam_sim_alloc(amd_action, amd_poll, "amd",
                                  amd, amd->unit, 1, MAX_TAGS_CMD_QUEUE,
                                  devq);
+       cam_simq_release(devq);
        if (amd->psim == NULL) {
-               cam_simq_free(devq);
                if (bootverbose)
                        printf("amd_attach: cam_sim_alloc failure!\n");
                return ENXIO;
        }
 
        if (xpt_bus_register(amd->psim, 0) != CAM_SUCCESS) {
-               cam_sim_free(amd->psim, /*free_devq*/TRUE);
+               cam_sim_free(amd->psim);
                if (bootverbose)
                        printf("amd_attach: xpt_bus_register failure!\n");
                return ENXIO;
@@ -2421,7 +2421,7 @@ amd_attach(device_t dev)
                            cam_sim_path(amd->psim), CAM_TARGET_WILDCARD,
                            CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                xpt_bus_deregister(cam_sim_path(amd->psim));
-               cam_sim_free(amd->psim, /* free_simq */ TRUE);
+               cam_sim_free(amd->psim);
                if (bootverbose)
                        printf("amd_attach: xpt_create_path failure!\n");
                return ENXIO;
index 112d1b4..e7350de 100644 (file)
@@ -26,7 +26,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ata/ata-all.c,v 1.50.2.45 2003/03/12 14:47:12 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/ata-all.c,v 1.13 2004/02/18 02:01:37 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/ata/ata-all.c,v 1.14 2004/03/15 01:10:42 dillon Exp $
  */
 
 #include "opt_ata.h"
@@ -257,9 +257,8 @@ ata_detach(device_t dev)
        return ENXIO;
 
     /* make sure channel is not busy */
-    ATA_SLEEPLOCK_CH(ch, ATA_CONTROL);
-
     s = splbio();
+    ATA_SLEEPLOCK_CH(ch, ATA_CONTROL);
 #if NATADISK > 0
     if (ch->devices & ATA_ATA_MASTER && ch->device[MASTER].driver)
        ad_detach(&ch->device[MASTER], 1);
@@ -322,6 +321,7 @@ ataioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct thread *td)
     struct ata_channel *ch;
     device_t device = devclass_get_device(ata_devclass, iocmd->channel);
     int error;
+    int s;
 
     if (cmd != IOCATA)
        return ENOTTY;
@@ -345,9 +345,11 @@ ataioctl(dev_t dev, u_long cmd, caddr_t addr, int32_t flag, struct thread *td)
        case ATAREINIT:
            if (!device || !(ch = device_get_softc(device)))
                return ENXIO;
+           s = splbio();       /* interlock non-atomic channel lock */
            ATA_SLEEPLOCK_CH(ch, ATA_ACTIVE);
            if ((error = ata_reinit(ch)))
                ATA_UNLOCK_CH(ch);
+           splx(s);
            return error;
 
        case ATAGMODE:
@@ -684,10 +686,12 @@ ata_start(struct ata_channel *ch)
 #endif
     int s;
 
-    if (!ATA_LOCK_CH(ch, ATA_ACTIVE))
+    s = splbio();      /* interlock non-atomic channel lock */
+    if (!ATA_LOCK_CH(ch, ATA_ACTIVE)) {
+       splx(s);
        return;
+    }
 
-    s = splbio();
 #if NATADISK > 0
     /* find & call the responsible driver if anything on the ATA queue */
     if (TAILQ_EMPTY(&ch->ata_queue)) {
@@ -1355,6 +1359,7 @@ static void
 ata_change_mode(struct ata_device *atadev, int mode)
 {
     int umode, wmode, pmode;
+    int s;
 
     umode = ata_umode(atadev->param);
     wmode = ata_wmode(atadev->param);
@@ -1377,9 +1382,11 @@ ata_change_mode(struct ata_device *atadev, int mode)
        wmode = -1;
     }
 
+    s = splbio();      /* interlock non-atomic channel lock */
     ATA_SLEEPLOCK_CH(atadev->channel, ATA_ACTIVE);
     ata_dmainit(atadev, pmode, wmode, umode);
     ATA_UNLOCK_CH(atadev->channel);
+    splx(s);
     ata_start(atadev->channel); /* XXX SOS */
 }
 
index 2815e31..0bc8873 100644 (file)
@@ -26,7 +26,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ata/ata-disk.c,v 1.60.2.24 2003/01/30 07:19:59 sos Exp $
- * $DragonFly: src/sys/dev/disk/ata/ata-disk.c,v 1.13 2004/02/18 02:47:38 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/ata/ata-disk.c,v 1.14 2004/03/15 01:10:42 dillon Exp $
  */
 
 #include "opt_ata.h"
@@ -289,11 +289,14 @@ static int
 adclose(dev_t dev, int flags, int fmt, struct thread *td)
 {
     struct ad_softc *adp = dev->si_drv1;
+    int s;
 
+    s = splbio();      /* interlock non-atomic channel lock */
     ATA_SLEEPLOCK_CH(adp->device->channel, ATA_CONTROL);
     if (ata_command(adp->device, ATA_C_FLUSHCACHE, 0, 0, 0, ATA_WAIT_READY))
        ata_prtdev(adp->device, "flushing cache on close failed\n");
     ATA_UNLOCK_CH(adp->device->channel);
+    splx(s);
     return 0;
 }
 
index 1cfdf75..45f1e3d 100644 (file)
@@ -26,7 +26,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ata/atapi-all.c,v 1.46.2.18 2002/10/31 23:10:33 thomas Exp $
- * $DragonFly: src/sys/dev/disk/ata/atapi-all.c,v 1.9 2004/02/18 04:08:49 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/ata/atapi-all.c,v 1.10 2004/03/15 01:10:42 dillon Exp $
  */
 
 #include "opt_ata.h"
@@ -179,12 +179,7 @@ atapi_queue_cmd(struct ata_device *atadev, int8_t *ccb, caddr_t data,
     struct atapi_request *request;
     int error, s;
 
-    request = malloc(sizeof(struct atapi_request), M_ATAPI, M_NOWAIT|M_ZERO);
-    if (request == NULL) {
-       printf("WARNNIG: atapi_queue_cmd: malloc() would block\n");
-       request = malloc(sizeof(struct atapi_request), M_ATAPI, M_WAITOK|M_ZERO);
-    }
-
+    request = malloc(sizeof(struct atapi_request), M_ATAPI, M_WAITOK|M_ZERO);
     request->device = atadev;
     request->data = data;
     request->bytecount = count;
@@ -198,11 +193,8 @@ atapi_queue_cmd(struct ata_device *atadev, int8_t *ccb, caddr_t data,
        request->driver = driver;
     }
     if (atadev->mode >= ATA_DMA) {
-       if (ata_dmaalloc(atadev, M_NOWAIT) != 0) {
-           printf("WARNING: atapi_queue_cmd: ata_dmaalloc() would block\n");
-           error = ata_dmaalloc(atadev, M_WAITOK);
-           KKASSERT(error != 0);
-       }
+       error = ata_dmaalloc(atadev, M_WAITOK);
+       KKASSERT(error == 0);
     }
 
 #ifdef ATAPI_DEBUG
index a1119da..7d53425 100644 (file)
@@ -26,7 +26,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ata/atapi-cam.c,v 1.10.2.3 2003/05/21 09:24:55 thomas Exp $
- * $DragonFly: src/sys/dev/disk/ata/atapi-cam.c,v 1.5 2004/02/18 04:08:49 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/ata/atapi-cam.c,v 1.6 2004/03/15 01:10:42 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -127,14 +127,12 @@ atapi_cam_attach_bus(struct ata_channel *ata_ch)
     LIST_INSERT_HEAD(&all_buses, scp, chain);
     unit = device_get_unit(ata_ch->dev);
 
-    if ((devq = cam_simq_alloc(16)) == NULL)
+    devq = cam_simq_alloc(16);
+    sim = cam_sim_alloc(atapi_action, atapi_poll, "ata", (void *)scp, 
+                       unit, 1, 1, devq);
+    cam_simq_release(devq);
+    if (sim == NULL)
        goto error;
-
-    if ((sim = cam_sim_alloc(atapi_action, atapi_poll, "ata",
-                (void *)scp, unit, 1, 1, devq)) == NULL) {
-       cam_simq_free(devq);
-       goto error;
-    }
     scp->sim = sim;
 
     if (xpt_bus_register(sim, 0) != CAM_SUCCESS) {
@@ -699,7 +697,7 @@ free_softc(struct atapi_xpt_softc *scp)
        }
        if (scp->sim != NULL) {
            if ((scp->flags & BUS_REGISTERED) == 0)
-               cam_sim_free(scp->sim, /*free_devq*/TRUE);
+               cam_sim_free(scp->sim);
            else
                printf("Can't free %s SIM (still registered)\n",
                       cam_sim_name(scp->sim));
index f015846..48c079d 100644 (file)
@@ -31,7 +31,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/buslogic/bt.c,v 1.25.2.1 2000/08/02 22:32:26 peter Exp $
- * $DragonFly: src/sys/dev/disk/buslogic/bt.c,v 1.5 2004/01/25 15:43:24 joerg Exp $
+ * $DragonFly: src/sys/dev/disk/buslogic/bt.c,v 1.6 2004/03/15 01:10:43 dillon Exp $
  */
 
  /*
@@ -845,13 +845,12 @@ bt_attach(device_t dev)
         */
        bt->sim = cam_sim_alloc(btaction, btpoll, "bt", bt, bt->unit,
                                2, tagged_dev_openings, devq);
-       if (bt->sim == NULL) {
-               cam_simq_free(devq);
+       cam_simq_release(devq);
+       if (bt->sim == NULL)
                return (ENOMEM);
-       }
        
        if (xpt_bus_register(bt->sim, 0) != CAM_SUCCESS) {
-               cam_sim_free(bt->sim, /*free_devq*/TRUE);
+               cam_sim_free(bt->sim);
                return (ENXIO);
        }
        
@@ -859,7 +858,7 @@ bt_attach(device_t dev)
                            cam_sim_path(bt->sim), CAM_TARGET_WILDCARD,
                            CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                xpt_bus_deregister(cam_sim_path(bt->sim));
-               cam_sim_free(bt->sim, /*free_devq*/TRUE);
+               cam_sim_free(bt->sim);
                return (ENXIO);
        }
                
@@ -966,10 +965,7 @@ btallocccbs(struct bt_softc *bt)
 
        next_ccb = &bt->bt_ccb_array[bt->num_ccbs];
 
-       sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_NOWAIT);
-
-       if (sg_map == NULL)
-               goto error_exit;
+       sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_WAITOK);
 
        /* Allocate S/G space for the next batch of CCBS */
        if (bus_dmamem_alloc(bt->sg_dmat, (void **)&sg_map->sg_vaddr,
index f6caf64..b7288fa 100644 (file)
@@ -1,5 +1,5 @@
 /* $FreeBSD: src/sys/dev/ccd/ccd.c,v 1.73.2.1 2001/09/11 09:49:52 kris Exp $ */
-/* $DragonFly: src/sys/dev/disk/ccd/ccd.c,v 1.13 2004/03/01 06:33:13 dillon Exp $ */
+/* $DragonFly: src/sys/dev/disk/ccd/ccd.c,v 1.14 2004/03/15 01:10:43 dillon Exp $ */
 
 /*     $NetBSD: ccd.c,v 1.22 1995/12/08 19:13:26 thorpej Exp $ */
 
@@ -310,21 +310,11 @@ ccdattach()
        else
                printf("ccd0: Concatenated disk driver\n");
 
-       ccd_softc = (struct ccd_softc *)malloc(num * sizeof(struct ccd_softc),
-           M_DEVBUF, M_NOWAIT);
-       ccddevs = (struct ccddevice *)malloc(num * sizeof(struct ccddevice),
-           M_DEVBUF, M_NOWAIT);
-       if ((ccd_softc == NULL) || (ccddevs == NULL)) {
-               printf("WARNING: no memory for concatenated disks\n");
-               if (ccd_softc != NULL)
-                       free(ccd_softc, M_DEVBUF);
-               if (ccddevs != NULL)
-                       free(ccddevs, M_DEVBUF);
-               return;
-       }
+       ccd_softc = malloc(num * sizeof(struct ccd_softc), M_DEVBUF, 
+                           M_WAITOK | M_ZERO);
+       ccddevs = malloc(num * sizeof(struct ccddevice), M_DEVBUF,
+                           M_WAITOK | M_ZERO);
        numccd = num;
-       bzero(ccd_softc, num * sizeof(struct ccd_softc));
-       bzero(ccddevs, num * sizeof(struct ccddevice));
 
        cdevsw_add(&ccd_cdevsw);
        /* XXX: is this necessary? */
index 901cd5f..ac2f783 100644 (file)
@@ -51,7 +51,7 @@
  *
  *     from:   @(#)fd.c        7.4 (Berkeley) 5/25/91
  * $FreeBSD: src/sys/isa/fd.c,v 1.176.2.8 2002/05/15 21:56:14 joerg Exp $
- * $DragonFly: src/sys/dev/disk/fd/fd.c,v 1.13 2004/02/10 07:55:46 joerg Exp $
+ * $DragonFly: src/sys/dev/disk/fd/fd.c,v 1.14 2004/03/15 01:10:43 dillon Exp $
  *
  */
 
@@ -768,10 +768,7 @@ fdc_add_child(device_t dev, const char *name, int unit)
        struct fdc_ivars *ivar;
        device_t child;
 
-       ivar = malloc(sizeof *ivar, M_DEVBUF /* XXX */, M_NOWAIT);
-       if (ivar == NULL)
-               return;
-       bzero(ivar, sizeof *ivar);
+       ivar = malloc(sizeof *ivar, M_DEVBUF /* XXX */, M_WAITOK | M_ZERO);
        if (resource_int_value(name, unit, "drive", &ivar->fdunit) != 0)
                ivar->fdunit = 0;
        child = device_add_child(dev, name, unit);
@@ -2162,14 +2159,12 @@ fdformat(dev_t dev, struct fd_formb *finfo, struct thread *td)
        fdblk = 128 << fd->ft->secsize;
 
        /* set up a buffer header for fdstrategy() */
-       bp = (struct buf *)malloc(sizeof(struct buf), M_TEMP, M_NOWAIT);
-       if(bp == 0)
-               return ENOBUFS;
+       bp = malloc(sizeof(struct buf), M_TEMP, M_WAITOK | M_ZERO);
+
        /*
         * keep the process from being swapped
         */
        PHOLD(p);
-       bzero((void *)bp, sizeof(struct buf));
        BUF_LOCKINIT(bp);
        BUF_LOCK(bp, LK_EXCLUSIVE);
        bp->b_flags = B_PHYS | B_FORMAT;
index 8385959..5ede326 100644 (file)
@@ -1,7 +1,7 @@
 /*     $NecBSD: bsfunc.c,v 1.2 1997/10/31 17:43:37 honda Exp $ */
 /*     $NetBSD$        */
 /* $FreeBSD: src/sys/i386/isa/bs/bsfunc.c,v 1.7.2.2 2001/07/26 02:32:18 nyan Exp $ */
-/* $DragonFly: src/sys/dev/disk/i386/bs/Attic/bsfunc.c,v 1.5 2004/02/13 01:04:14 joerg Exp $ */
+/* $DragonFly: src/sys/dev/disk/i386/bs/Attic/bsfunc.c,v 1.6 2004/03/15 01:10:43 dillon Exp $ */
 /*
  * [NetBSD for NEC PC98 series]
  *  Copyright (c) 1994, 1995, 1996 NetBSD/pc98 porting staff.
@@ -683,15 +683,7 @@ bs_init_target_info(bsc, target)
 {
        struct targ_info *ti;
 
-       ti = malloc(sizeof(struct targ_info), M_DEVBUF, M_NOWAIT);
-       if (ti == NULL)
-       {
-               bs_printf(NULL, "bs_init_targ_info", "no target info memory");
-               return ti;
-       }
-
-       bzero(ti, sizeof(*ti));
-
+       ti = malloc(sizeof(struct targ_info), M_DEVBUF, M_WAITOK | M_ZERO);
        ti->ti_bsc = bsc;
        ti->ti_id = target;
        ti->sm_offset = 0;
index 2e53555..89c968b 100644 (file)
@@ -27,7 +27,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/i386/isa/bs/bsif.c,v 1.10.2.1 2000/08/24 08:06:08 kato Exp $
- * $DragonFly: src/sys/dev/disk/i386/bs/Attic/bsif.c,v 1.5 2004/02/13 01:04:14 joerg Exp $
+ * $DragonFly: src/sys/dev/disk/i386/bs/Attic/bsif.c,v 1.6 2004/03/15 01:10:43 dillon Exp $
  */
 
 #if    0
@@ -149,11 +149,7 @@ bsprobe(dev)
                printf("bs%d: memory already allocated\n", unit);
                return rv;
        }
-       if (!(bsc = malloc(sizeof(struct bs_softc), M_TEMP, M_NOWAIT))) {
-               printf("bs%d cannot malloc!\n", unit);
-               return rv;
-       }
-       bzero(bsc, sizeof(struct bs_softc));
+       bsc = malloc(sizeof(struct bs_softc), M_TEMP, M_WAITOK | M_ZERO);
        callout_handle_init(&bsc->timeout_ch);
        bscdata[unit] = bsc;
        bsc->unit = unit;
@@ -247,10 +243,9 @@ bsattach(dev)
 
        bsc->sim = cam_sim_alloc(bs_scsi_cmd, bs_poll, "bs",
                                 bsc, unit, 1, 32/*MAX_TAGS*/, devq);
-       if (bsc->sim == NULL) {
-               cam_simq_free(devq);
+       cam_simq_release(devq);
+       if (bsc->sim == NULL)
                return 0;
-       }
 
        if (xpt_bus_register(bsc->sim, 0) != CAM_SUCCESS) {
                free(bsc->sim, M_DEVBUF);
@@ -261,7 +256,7 @@ bsattach(dev)
                            cam_sim_path(bsc->sim), CAM_TARGET_WILDCARD,
                            CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                xpt_bus_deregister(cam_sim_path(bsc->sim));
-               cam_sim_free(bsc->sim, /*free_simq*/TRUE);
+               cam_sim_free(bsc->sim);
                free(bsc->sim, M_DEVBUF);
                return 0;
        }
index 7b8165c..ac100ab 100644 (file)
@@ -1,5 +1,5 @@
 /* $FreeBSD: src/sys/dev/isp/isp_freebsd.c,v 1.32.2.20 2002/10/11 18:49:25 mjacob Exp $ */
-/* $DragonFly: src/sys/dev/disk/isp/isp_freebsd.c,v 1.7 2003/11/09 02:22:34 dillon Exp $ */
+/* $DragonFly: src/sys/dev/disk/isp/isp_freebsd.c,v 1.8 2004/03/15 01:10:43 dillon Exp $ */
 /*
  * Platform (FreeBSD) dependent common attachment code for Qlogic adapters.
  *
@@ -96,8 +96,8 @@ isp_attach(struct ispsoftc *isp)
        ISPLOCK_2_CAMLOCK(isp);
        sim = cam_sim_alloc(isp_action, isp_poll, "isp", isp,
            device_get_unit(isp->isp_dev), 1, isp->isp_maxcmds, devq);
+       cam_simq_release(devq);         /* leaves 1 ref due to cam_sim_alloc */
        if (sim == NULL) {
-               cam_simq_free(devq);
                CAMLOCK_2_ISPLOCK(isp);
                return;
        }
@@ -107,7 +107,7 @@ isp_attach(struct ispsoftc *isp)
        isp->isp_osinfo.ehook.ich_arg = isp;
        ISPLOCK_2_CAMLOCK(isp);
        if (config_intrhook_establish(&isp->isp_osinfo.ehook) != 0) {
-               cam_sim_free(sim, TRUE);
+               cam_sim_free(sim);
                CAMLOCK_2_ISPLOCK(isp);
                isp_prt(isp, ISP_LOGERR,
                    "could not establish interrupt enable hook");
@@ -115,7 +115,7 @@ isp_attach(struct ispsoftc *isp)
        }
 
        if (xpt_bus_register(sim, primary) != CAM_SUCCESS) {
-               cam_sim_free(sim, TRUE);
+               cam_sim_free(sim);
                CAMLOCK_2_ISPLOCK(isp);
                return;
        }
@@ -123,7 +123,7 @@ isp_attach(struct ispsoftc *isp)
        if (xpt_create_path(&path, NULL, cam_sim_path(sim),
            CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                xpt_bus_deregister(cam_sim_path(sim));
-               cam_sim_free(sim, TRUE);
+               cam_sim_free(sim);
                config_intrhook_disestablish(&isp->isp_osinfo.ehook);
                CAMLOCK_2_ISPLOCK(isp);
                return;
@@ -147,7 +147,7 @@ isp_attach(struct ispsoftc *isp)
                if (kthread_create(isp_kthread, isp, &isp->isp_osinfo.kthread,
                    "%s: fc_thrd", device_get_nameunit(isp->isp_dev))) {
                        xpt_bus_deregister(cam_sim_path(sim));
-                       cam_sim_free(sim, TRUE);
+                       cam_sim_free(sim);
                        config_intrhook_disestablish(&isp->isp_osinfo.ehook);
                        CAMLOCK_2_ISPLOCK(isp);
                        isp_prt(isp, ISP_LOGERR, "could not create kthread");
@@ -167,14 +167,13 @@ isp_attach(struct ispsoftc *isp)
                if (sim == NULL) {
                        xpt_bus_deregister(cam_sim_path(isp->isp_sim));
                        xpt_free_path(isp->isp_path);
-                       cam_simq_free(devq);
                        config_intrhook_disestablish(&isp->isp_osinfo.ehook);
                        return;
                }
                if (xpt_bus_register(sim, secondary) != CAM_SUCCESS) {
                        xpt_bus_deregister(cam_sim_path(isp->isp_sim));
                        xpt_free_path(isp->isp_path);
-                       cam_sim_free(sim, TRUE);
+                       cam_sim_free(sim);
                        config_intrhook_disestablish(&isp->isp_osinfo.ehook);
                        CAMLOCK_2_ISPLOCK(isp);
                        return;
@@ -185,7 +184,7 @@ isp_attach(struct ispsoftc *isp)
                        xpt_bus_deregister(cam_sim_path(isp->isp_sim));
                        xpt_free_path(isp->isp_path);
                        xpt_bus_deregister(cam_sim_path(sim));
-                       cam_sim_free(sim, TRUE);
+                       cam_sim_free(sim);
                        config_intrhook_disestablish(&isp->isp_osinfo.ehook);
                        CAMLOCK_2_ISPLOCK(isp);
                        return;
@@ -668,11 +667,7 @@ create_lun_state(struct ispsoftc *isp, int bus,
        if (is_lun_enabled(isp, bus, lun)) {
                return (CAM_LUN_ALRDY_ENA);
        }
-       new = (tstate_t *) malloc(sizeof (tstate_t), M_DEVBUF, M_NOWAIT|M_ZERO);
-       if (new == NULL) {
-               return (CAM_RESRC_UNAVAIL);
-       }
-
+       new = malloc(sizeof (tstate_t), M_DEVBUF, M_WAITOK | M_ZERO);
        status = xpt_create_path(&new->owner, NULL, xpt_path_path_id(path),
            xpt_path_target_id(path), xpt_path_lun_id(path));
        if (status != CAM_REQ_CMP) {
index 1e4ac4c..c8001e2 100644 (file)
@@ -1,5 +1,5 @@
 /* $FreeBSD: src/sys/dev/isp/isp_pci.c,v 1.78.2.4 2002/10/11 18:50:53 mjacob Exp $ */
-/* $DragonFly: src/sys/dev/disk/isp/isp_pci.c,v 1.3 2003/08/07 21:16:53 dillon Exp $ */
+/* $DragonFly: src/sys/dev/disk/isp/isp_pci.c,v 1.4 2004/03/15 01:10:43 dillon Exp $ */
 /*
  * PCI specific probe and attach routines for Qlogic ISP SCSI adapters.
  * FreeBSD Version.
@@ -366,12 +366,7 @@ isp_pci_attach(device_t dev)
                }
        }
 
-       pcs = malloc(sizeof (struct isp_pcisoftc), M_DEVBUF, M_NOWAIT);
-       if (pcs == NULL) {
-               device_printf(dev, "cannot allocate softc\n");
-               return (ENOMEM);
-       }
-       bzero(pcs, sizeof (struct isp_pcisoftc));
+       pcs = malloc(sizeof (struct isp_pcisoftc), M_DEVBUF, M_WAITOK | M_ZERO);
 
        /*
         * Figure out which we should try first - memory mapping or i/o mapping?
@@ -513,12 +508,7 @@ isp_pci_attach(device_t dev)
                    PCI_MBOX_REGS2300_OFF;
        }
        isp = &pcs->pci_isp;
-       isp->isp_param = malloc(psize, M_DEVBUF, M_NOWAIT);
-       if (isp->isp_param == NULL) {
-               device_printf(dev, "cannot allocate parameter data\n");
-               goto bad;
-       }
-       bzero(isp->isp_param, psize);
+       isp->isp_param = malloc(psize, M_DEVBUF, M_WAITOK | M_ZERO);
        isp->isp_mdvec = mdvp;
        isp->isp_type = basetype;
        isp->isp_revision = pci_get_revid(dev);
index 4ca642b..0e7aee9 100644 (file)
@@ -1,5 +1,5 @@
 /* $FreeBSD: src/sys/dev/ispfw/ispfw.c,v 1.2.2.5 2002/10/12 00:13:09 mjacob Exp $ */
-/* $DragonFly: src/sys/dev/disk/ispfw/ispfw.c,v 1.4 2003/08/27 10:35:17 rob Exp $ */
+/* $DragonFly: src/sys/dev/disk/ispfw/ispfw.c,v 1.5 2004/03/15 01:10:43 dillon Exp $ */
 /*
  * ISP Firmware Helper Pseudo Device for FreeBSD
  *
@@ -74,10 +74,7 @@ addcaller(const u_int16_t **caller)
                        return (1);
        }
        newcallp = malloc((ncallers + 1) * sizeof (const u_int16_t ***),
-           M_DEVBUF, M_NOWAIT);
-       if (newcallp == NULL) {
-               return (0);
-       }
+           M_DEVBUF, M_WAITOK);
        for (i = 0; i < ncallers; i++) {
                newcallp[i] = callp[i];
        }
index a89ef27..e453089 100644 (file)
@@ -1,5 +1,5 @@
 /* $FreeBSD: src/sys/dev/mpt/mpt_freebsd.c,v 1.3.2.3 2002/09/24 21:37:25 mjacob Exp $ */
-/* $DragonFly: src/sys/dev/disk/mpt/mpt_freebsd.c,v 1.3 2003/08/07 21:16:53 dillon Exp $ */
+/* $DragonFly: src/sys/dev/disk/mpt/mpt_freebsd.c,v 1.4 2004/03/15 01:10:43 dillon Exp $ */
 /*
  * FreeBSD/CAM specific routines for LSI '909 FC  adapters.
  * FreeBSD Version.
@@ -43,7 +43,6 @@ static int mpt_setsync(mpt_softc_t *, int, int, int);
 void
 mpt_cam_attach(mpt_softc_t *mpt)
 {
-       struct cam_devq *devq;
        struct cam_sim *sim;
        int maxq;
 
@@ -52,38 +51,27 @@ mpt_cam_attach(mpt_softc_t *mpt)
            mpt->mpt_global_credits : MPT_MAX_REQUESTS(mpt);
 
 
-       /*
-        * Create the device queue for our SIM(s).
-        */
-       
-       devq = cam_simq_alloc(maxq);
-       if (devq == NULL) {
-               return;
-       }
-
        /*
         * Construct our SIM entry.
         */
        sim = cam_sim_alloc(mpt_action, mpt_poll, "mpt", mpt,
-           mpt->unit, 1, maxq, devq);
-       if (sim == NULL) {
-               cam_simq_free(devq);
+           mpt->unit, 1, maxq, NULL);
+       if (sim == NULL)
                return;
-       }
 
        /*
         * Register exactly the bus.
         */
 
        if (xpt_bus_register(sim, 0) != CAM_SUCCESS) {
-               cam_sim_free(sim, TRUE);
+               cam_sim_free(sim);
                return;
        }
 
        if (xpt_create_path(&mpt->path, NULL, cam_sim_path(sim),
            CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                xpt_bus_deregister(cam_sim_path(sim));
-               cam_sim_free(sim, TRUE);
+               cam_sim_free(sim);
                return;
        }
        mpt->sim = sim;
@@ -95,7 +83,7 @@ mpt_cam_detach(mpt_softc_t *mpt)
        if (mpt->sim != NULL) {
                xpt_free_path(mpt->path);
                xpt_bus_deregister(cam_sim_path(mpt->sim));
-               cam_sim_free(mpt->sim, TRUE);
+               cam_sim_free(mpt->sim);
                mpt->sim = NULL;
        }
 }
index a8261d6..4c40581 100644 (file)
@@ -1,7 +1,7 @@
 /**************************************************************************
 **
 ** $FreeBSD: src/sys/pci/ncr.c,v 1.155.2.3 2001/03/05 13:09:10 obrien Exp $
-** $DragonFly: src/sys/dev/disk/ncr/ncr.c,v 1.6 2004/02/13 01:04:15 joerg Exp $
+** $DragonFly: src/sys/dev/disk/ncr/ncr.c,v 1.7 2004/03/15 01:10:44 dillon Exp $
 **
 **  Device driver for the   NCR 53C8XX   PCI-SCSI-Controller Family.
 **
@@ -3790,14 +3790,13 @@ ncr_attach (device_t dev)
        */
        np->sim = cam_sim_alloc(ncr_action, ncr_poll, "ncr", np, np->unit,
                                1, MAX_TAGS, devq);
-       if (np->sim == NULL) {
-               cam_simq_free(devq);
+       cam_simq_release(devq);
+       if (np->sim == NULL)
                return ENOMEM;
-       }
 
        
        if (xpt_bus_register(np->sim, 0) != CAM_SUCCESS) {
-               cam_sim_free(np->sim, /*free_devq*/ TRUE);
+               cam_sim_free(np->sim);
                return ENOMEM;
        }
        
@@ -3805,7 +3804,7 @@ ncr_attach (device_t dev)
                            cam_sim_path(np->sim), CAM_TARGET_WILDCARD,
                            CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                xpt_bus_deregister(cam_sim_path(np->sim));
-               cam_sim_free(np->sim, /*free_devq*/TRUE);
+               cam_sim_free(np->sim);
                return ENOMEM;
        }
 
@@ -6535,13 +6534,11 @@ ncr_alloc_nccb (ncb_p np, u_long target, u_long lun)
                /*
                **      Allocate a lcb
                */
-               lp = (lcb_p) malloc (sizeof (struct lcb), M_DEVBUF, M_NOWAIT);
-               if (!lp) return(NULL);
+               lp = malloc (sizeof (struct lcb), M_DEVBUF, M_WAITOK | M_ZERO);
 
                /*
                **      Initialize it
                */
-               bzero (lp, sizeof (*lp));
                lp->jump_lcb.l_cmd   = (SCR_JUMP ^ IFFALSE (DATA (lun)));
                lp->jump_lcb.l_paddr = tp->jump_lcb.l_paddr;
 
@@ -6564,20 +6561,12 @@ ncr_alloc_nccb (ncb_p np, u_long target, u_long lun)
        /*
        **      Allocate a nccb
        */
-       cp = (nccb_p) malloc (sizeof (struct nccb), M_DEVBUF, M_NOWAIT);
-
-       if (!cp)
-               return (NULL);
+       cp = malloc (sizeof (struct nccb), M_DEVBUF, M_WAITOK | M_ZERO);
 
        if (DEBUG_FLAGS & DEBUG_ALLOC) { 
                printf ("new nccb @%p.\n", cp);
        }
 
-       /*
-       **      Initialize it
-       */
-       bzero (cp, sizeof (*cp));
-
        /*
        **      Fill in physical addresses
        */
index de2a954..87b3543 100644 (file)
@@ -32,7 +32,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  * 
  * $FreeBSD: src/sys/dev/firewire/sbp.c,v 1.74 2004/01/08 14:58:09 simokawa Exp $
- * $DragonFly: src/sys/dev/disk/sbp/sbp.c,v 1.9 2004/02/05 17:51:44 joerg Exp $
+ * $DragonFly: src/sys/dev/disk/sbp/sbp.c,v 1.10 2004/03/15 01:10:44 dillon Exp $
  *
  */
 
@@ -477,25 +477,19 @@ END_DEBUG
 
        /* Reallocate */
        if (maxlun != target->num_lun) {
-               newluns = (struct sbp_dev **) realloc(target->luns,
-                   sizeof(struct sbp_dev *) * maxlun,
-                   M_SBP, M_NOWAIT | M_ZERO);
-               
-               if (newluns == NULL) {
-                       printf("%s: realloc failed\n", __FUNCTION__);
-                       newluns = target->luns;
-                       maxlun = target->num_lun;
-               }
-
                /*
-                * We must zero the extended region for the case
-                * realloc() doesn't allocate new buffer.
+                * note: realloc() does not support M_ZERO.  We must zero
+                * the extended region manually.
                 */
-               if (maxlun > target->num_lun)
+               newluns = realloc(target->luns, 
+                               sizeof(struct sbp_dev *) * maxlun,
+                               M_SBP, M_WAITOK);
+
+               if (maxlun > target->num_lun) {
                        bzero(&newluns[target->num_lun],
                            sizeof(struct sbp_dev *) *
-                           (maxlun - target->num_lun));
-
+                            (maxlun - target->num_lun));
+               }
                target->luns = newluns;
                target->num_lun = maxlun;
        }
@@ -516,11 +510,7 @@ END_DEBUG
                sdev = target->luns[lun];
                if (sdev == NULL) {
                        sdev = malloc(sizeof(struct sbp_dev),
-                           M_SBP, M_NOWAIT | M_ZERO);
-                       if (sdev == NULL) {
-                               printf("%s: malloc failed\n", __FUNCTION__);
-                               goto next;
-                       }
+                           M_SBP, M_WAITOK | M_ZERO);
                        target->luns[lun] = sdev;
                        sdev->lun_id = lun;
                        sdev->target = target;
@@ -1013,11 +1003,7 @@ SBP_DEBUG(0)
        sbp_show_sdev_info(sdev, 2);
        printf("sbp_cam_scan_target\n");
 END_DEBUG
-       ccb = malloc(sizeof(union ccb), M_SBP, M_NOWAIT | M_ZERO);
-       if (ccb == NULL) {
-               printf("sbp_cam_scan_target: malloc failed\n");
-               return;
-       }
+       ccb = malloc(sizeof(union ccb), M_SBP, M_WAITOK | M_ZERO);
        xpt_setup_ccb(&ccb->ccb_h, sdev->path, SCAN_PRI);
        ccb->ccb_h.func_code = XPT_SCAN_LUN;
        ccb->ccb_h.cbfcnp = sbp_cam_scan_lun;
@@ -1933,12 +1919,9 @@ END_DEBUG
                                 /*untagged*/ 1,
                                 /*tagged*/ SBP_QUEUE_LEN - 1,
                                 devq);
-
-       if (sbp->sim == NULL) {
-               cam_simq_free(devq);
+       cam_simq_release(devq);
+       if (sbp->sim == NULL)
                return (ENXIO);
-       }
-
 
        if (xpt_bus_register(sbp->sim, /*bus*/0) != CAM_SUCCESS)
                goto fail;
@@ -1981,7 +1964,7 @@ END_DEBUG
 
        return (0);
 fail:
-       cam_sim_free(sbp->sim, /*free_devq*/TRUE);
+       cam_sim_free(sbp->sim);
        return (ENXIO);
 }
 
@@ -2079,7 +2062,7 @@ END_DEBUG
        xpt_async(AC_LOST_DEVICE, sbp->path, NULL);
        xpt_free_path(sbp->path);
        xpt_bus_deregister(cam_sim_path(sbp->sim));
-       cam_sim_free(sbp->sim, /*free_devq*/ TRUE),
+       cam_sim_free(sbp->sim);
 
        sbp_logout_all(sbp);
 
index 55bc7dd..c0adc60 100644 (file)
@@ -24,7 +24,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/pci/simos.c,v 1.7 1999/08/28 00:51:06 peter Exp $
- * $DragonFly: src/sys/dev/disk/simos/Attic/simos.c,v 1.4 2003/08/27 10:35:17 rob Exp $
+ * $DragonFly: src/sys/dev/disk/simos/Attic/simos.c,v 1.5 2004/03/15 01:10:44 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -117,13 +117,13 @@ simos_attach(pcici_t config_id, int unit)
 
        sc->sc_sim = cam_sim_alloc(simos_action, simos_poll, "simos", sc, unit,
                                   /*untagged*/1, /*tagged*/0, devq);
+       cam_simq_release(devq);
        if (sc->sc_sim == NULL) {
-               cam_simq_free(devq);
                return;
        }
 
        if (xpt_bus_register(sc->sc_sim, /*bus*/0) != CAM_SUCCESS) {
-               cam_sim_free(sc->sc_sim, /*free_devq*/TRUE);
+               cam_sim_free(sc->sc_sim);
                return;
        }
 
@@ -131,7 +131,7 @@ simos_attach(pcici_t config_id, int unit)
                            cam_sim_path(sc->sc_sim), CAM_TARGET_WILDCARD,
                            CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
                xpt_bus_deregister(cam_sim_path(sc->sc_sim));
-               cam_sim_free(sc->sc_sim, /*free_devq*/TRUE);
+               cam_sim_free(sc->sc_sim);
                return;
        }
 
index 9411aff..669b2eb 100644 (file)
@@ -56,7 +56,7 @@
  */
 
 /* $FreeBSD: src/sys/dev/sym/sym_hipd.c,v 1.6.2.12 2001/12/02 19:01:10 groudier Exp $ */
-/* $DragonFly: src/sys/dev/disk/sym/sym_hipd.c,v 1.5 2004/02/13 01:04:15 joerg Exp $ */
+/* $DragonFly: src/sys/dev/disk/sym/sym_hipd.c,v 1.6 2004/03/15 01:10:44 dillon Exp $ */
 
 #define SYM_DRIVER_NAME        "sym-1.6.5-20000902"
 
@@ -9648,17 +9648,18 @@ int sym_cam_attach(hcb_p np)
         *  Create the device queue for our sym SIM.
         */
        devq = cam_simq_alloc(SYM_CONF_MAX_START);
-       if (!devq)
+       if (devq == NULL) {
                goto fail;
+       }
 
        /*
         *  Construct our SIM entry.
         */
        sim = cam_sim_alloc(sym_action, sym_poll, "sym", np, np->unit,
                            1, SYM_SETUP_MAX_TAG, devq);
-       if (!sim)
+       cam_simq_release(devq);
+       if (sim == NULL)
                goto fail;
-       devq = 0;
 
        if (xpt_bus_register(sim, 0) != CAM_SUCCESS)
                goto fail;
@@ -9709,9 +9710,7 @@ int sym_cam_attach(hcb_p np)
        return 1;
 fail:
        if (sim)
-               cam_sim_free(sim, FALSE);
-       if (devq)
-               cam_simq_free(devq);
+               cam_sim_free(sim);
 
        sym_cam_free(np);
 
@@ -9733,7 +9732,7 @@ void sym_cam_free(hcb_p np)
        
        if (np->sim) {
                xpt_bus_deregister(cam_sim_path(np->sim));
-               cam_sim_free(np->sim, /*free_devq*/ TRUE);
+               cam_sim_free(np->sim);
        }
        if (np->path)
                xpt_free_path(np->path);
index befc663..acd93fc 100644 (file)
@@ -45,7 +45,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/trm/trm.c,v 1.2.2.2 2002/12/19 20:34:45 cognet Exp $
- * $DragonFly: src/sys/dev/disk/trm/trm.c,v 1.4 2004/02/13 01:04:15 joerg Exp $
+ * $DragonFly: src/sys/dev/disk/trm/trm.c,v 1.5 2004/03/15 01:10:44 dillon Exp $
  */
 
 /*
@@ -3307,9 +3307,9 @@ trm_attach(device_t pci_config_id)
            1,
            MAX_TAGS_CMD_QUEUE,
            device_Q);
+       cam_simq_release(device_Q);  /* SIM allocate fault*/
        if (pACB->psim == NULL) {
                printf("trm%d: SIM allocate fault !\n",unit);
-               cam_simq_free(device_Q);  /* SIM allocate fault*/
                goto bad;
        }
        if (xpt_bus_register(pACB->psim, 0) != CAM_SUCCESS)  {
@@ -3342,7 +3342,7 @@ bad:
        if (pACB->irq)
                bus_release_resource(pci_config_id, SYS_RES_IRQ, 0, pACB->irq);
        if (pACB->psim)
-               cam_sim_free(pACB->psim, TRUE);
+               cam_sim_free(pACB->psim);
        
        return (ENXIO);
        
@@ -3377,7 +3377,7 @@ trm_detach(device_t dev)
        xpt_async(AC_LOST_DEVICE, pACB->ppath, NULL);
        xpt_free_path(pACB->ppath);
        xpt_bus_deregister(cam_sim_path(pACB->psim));
-       cam_sim_free(pACB->psim, TRUE);
+       cam_sim_free(pACB->psim);
        return (0);
 }
 static device_method_t trm_methods[] = {
index 5cdf1af..2f7bea7 100644 (file)
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ppbus/immio.c,v 1.10.2.3 2001/10/02 05:27:20 nsouch Exp $
- * $DragonFly: src/sys/dev/disk/vpo/immio.c,v 1.4 2003/08/07 21:16:54 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/vpo/immio.c,v 1.5 2004/03/15 01:10:44 dillon Exp $
  *
  */
 
@@ -583,11 +583,8 @@ imm_attach(struct vpoio_data *vpo)
        /*
         * Initialize microsequence code
         */
-       vpo->vpo_nibble_inbyte_msq = (struct ppb_microseq *)malloc(
-               sizeof(nibble_inbyte_submicroseq), M_DEVBUF, M_NOWAIT);
-
-       if (!vpo->vpo_nibble_inbyte_msq)
-               return (ENXIO);
+       vpo->vpo_nibble_inbyte_msq = malloc(sizeof(nibble_inbyte_submicroseq),
+                                               M_DEVBUF, M_WAITOK);
 
        bcopy((void *)nibble_inbyte_submicroseq,
                (void *)vpo->vpo_nibble_inbyte_msq,
index 1d1b432..c5d9d83 100644 (file)
@@ -24,7 +24,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ppbus/vpo.c,v 1.20.2.1 2000/05/07 21:08:18 n_hibma Exp $
- * $DragonFly: src/sys/dev/disk/vpo/vpo.c,v 1.3 2003/08/07 21:16:54 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/vpo/vpo.c,v 1.4 2004/03/15 01:10:44 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -161,13 +161,13 @@ vpo_attach(device_t dev)
        vpo->sim = cam_sim_alloc(vpo_action, vpo_poll, "vpo", vpo,
                                 device_get_unit(dev),
                                 /*untagged*/1, /*tagged*/0, devq);
+       cam_simq_release(devq);
        if (vpo->sim == NULL) {
-               cam_simq_free(devq);
                return (ENXIO);
        }
 
        if (xpt_bus_register(vpo->sim, /*bus*/0) != CAM_SUCCESS) {
-               cam_sim_free(vpo->sim, /*free_devq*/TRUE);
+               cam_sim_free(vpo->sim);
                return (ENXIO);
        }
 
index 477b3bc..beb5618 100644 (file)
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/ppbus/vpoio.c,v 1.10.2.3 2001/10/02 05:27:20 nsouch Exp $
- * $DragonFly: src/sys/dev/disk/vpo/vpoio.c,v 1.4 2003/08/07 21:16:54 dillon Exp $
+ * $DragonFly: src/sys/dev/disk/vpo/vpoio.c,v 1.5 2004/03/15 01:10:44 dillon Exp $
  *
  */
 
@@ -593,11 +593,8 @@ vpoio_attach(struct vpoio_data *vpo)
        device_t ppbus = device_get_parent(vpo->vpo_dev);
        int error = 0;
 
-       vpo->vpo_nibble_inbyte_msq = (struct ppb_microseq *)malloc(
-               sizeof(nibble_inbyte_submicroseq), M_DEVBUF, M_NOWAIT);
-
-       if (!vpo->vpo_nibble_inbyte_msq)
-               return (ENXIO);
+       vpo->vpo_nibble_inbyte_msq = malloc(sizeof(nibble_inbyte_submicroseq),
+                                               M_DEVBUF, M_WAITOK);
 
        bcopy((void *)nibble_inbyte_submicroseq,
                (void *)vpo->vpo_nibble_inbyte_msq,
index c809dbb..668e969 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $NetBSD: uhid.c,v 1.46 2001/11/13 06:24:55 lukem Exp $
  * $FreeBSD: src/sys/dev/usb/uhid.c,v 1.65 2003/11/09 09:17:22 tanimura Exp $
- * $DragonFly: src/sys/dev/usbmisc/uhid/uhid.c,v 1.9 2004/02/11 15:13:05 joerg Exp $
+ * $DragonFly: src/sys/dev/usbmisc/uhid/uhid.c,v 1.10 2004/03/15 01:10:44 dillon Exp $
  */
 
 /* Also already merged from NetBSD:
@@ -252,13 +252,9 @@ USB_ATTACH(uhid)
            uaa->revision == 0x???? */) { /* XXX should use revision */
                /* The report descriptor for the Wacom Graphire is broken. */
                size = sizeof uhid_graphire_report_descr;
-               desc = malloc(size, M_USBDEV, M_NOWAIT);
-               if (desc == NULL)
-                       err = USBD_NOMEM;
-               else {
-                       err = USBD_NORMAL_COMPLETION;
-                       memcpy(desc, uhid_graphire_report_descr, size);
-               }
+               desc = malloc(size, M_USBDEV, M_WAITOK);
+               err = USBD_NORMAL_COMPLETION;
+               memcpy(desc, uhid_graphire_report_descr, size);
        } else {
                desc = NULL;
                err = usbd_read_report_desc(uaa->iface, &desc, &size,M_USBDEV);
index 8ed5262..34f3c91 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * $FreeBSD: src/sys/dev/usb/ukbd.c,v 1.45 2003/10/04 21:41:01 joe Exp $
- * $DragonFly: src/sys/dev/usbmisc/ukbd/ukbd.c,v 1.6 2004/02/11 15:13:06 joerg Exp $
+ * $DragonFly: src/sys/dev/usbmisc/ukbd/ukbd.c,v 1.7 2004/03/15 01:10:44 dillon Exp $
  */
 
 /*
@@ -522,14 +522,11 @@ ukbd_init(int unit, keyboard_t **kbdp, void *arg, int flags)
                fkeymap_size =
                        sizeof(default_fkeytab)/sizeof(default_fkeytab[0]);
        } else if (*kbdp == NULL) {
-               *kbdp = kbd = malloc(sizeof(*kbd), M_DEVBUF, M_NOWAIT);
-               if (kbd == NULL)
-                       return ENOMEM;
-               bzero(kbd, sizeof(*kbd));
-               state = malloc(sizeof(*state), M_DEVBUF, M_NOWAIT);
-               keymap = malloc(sizeof(key_map), M_DEVBUF, M_NOWAIT);
-               accmap = malloc(sizeof(accent_map), M_DEVBUF, M_NOWAIT);
-               fkeymap = malloc(sizeof(fkey_tab), M_DEVBUF, M_NOWAIT);
+               *kbdp = kbd = malloc(sizeof(*kbd), M_DEVBUF, M_WAITOK | M_ZERO);
+               state = malloc(sizeof(*state), M_DEVBUF, M_WAITOK);
+               keymap = malloc(sizeof(key_map), M_DEVBUF, M_WAITOK);
+               accmap = malloc(sizeof(accent_map), M_DEVBUF, M_WAITOK);
+               fkeymap = malloc(sizeof(fkey_tab), M_DEVBUF, M_WAITOK);
                fkeymap_size = sizeof(fkey_tab)/sizeof(fkey_tab[0]);
                if ((state == NULL) || (keymap == NULL) || (accmap == NULL)
                     || (fkeymap == NULL)) {
index 6543cb9..2210c04 100644 (file)
@@ -26,7 +26,7 @@
  *
  * $NetBSD: umass.c,v 1.28 2000/04/02 23:46:53 augustss Exp $
  * $FreeBSD: src/sys/dev/usb/umass.c,v 1.96 2003/12/19 12:19:11 sanpei Exp $
- * $DragonFly: src/sys/dev/usbmisc/umass/umass.c,v 1.8 2004/02/14 19:56:28 dillon Exp $
+ * $DragonFly: src/sys/dev/usbmisc/umass/umass.c,v 1.9 2004/03/15 01:10:45 dillon Exp $
  */
 
 /*
@@ -2110,14 +2110,21 @@ umass_cam_attach_sim(struct umass_softc *sc)
                                1 /*maximum device openings*/,
                                0 /*maximum tagged device openings*/,
                                devq);
-       if (sc->umass_sim == NULL) {
-               cam_simq_free(devq);
+       cam_simq_release(devq);
+       if (sc->umass_sim == NULL)
                return(ENOMEM);
-       }
 
-       if(xpt_bus_register(sc->umass_sim, USBDEVUNIT(sc->sc_dev)) !=
-           CAM_SUCCESS)
+       /*
+        * If we could not register the bus we must immediately free the
+        * sim so we do not attempt to deregister a bus later on that we
+        * had not registered.
+        */
+       if (xpt_bus_register(sc->umass_sim, USBDEVUNIT(sc->sc_dev)) !=
+           CAM_SUCCESS) {
+               cam_sim_free(sc->umass_sim);
+               sc->umass_sim = NULL;
                return(ENOMEM);
+       }
 
        return(0);
 }
@@ -2208,7 +2215,7 @@ umass_cam_detach_sim(struct umass_softc *sc)
        }
        if (sc->umass_sim) {
                if (xpt_bus_deregister(cam_sim_path(sc->umass_sim)))
-                       cam_sim_free(sc->umass_sim, /*free_devq*/TRUE);
+                       cam_sim_free(sc->umass_sim);
                else
                        return(EBUSY);
 
index eba26ac..a23246d 100644 (file)
@@ -24,7 +24,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/usb/umct.c,v 1.5 2003/11/16 12:13:39 akiyama Exp $
- * $DragonFly: src/sys/dev/usbmisc/umct/umct.c,v 1.1 2003/12/30 01:01:47 dillon Exp $
+ * $DragonFly: src/sys/dev/usbmisc/umct/umct.c,v 1.2 2004/03/15 01:10:45 dillon Exp $
  */
 
 /*
@@ -169,9 +169,7 @@ USB_ATTACH(umct)
        int i;
 
        dev = uaa->device;
-       devinfo = malloc(1024, M_USBDEV, M_NOWAIT | M_ZERO);
-       if (devinfo == NULL)
-               return (ENOMEM);
+       devinfo = malloc(1024, M_USBDEV, M_WAITOK | M_ZERO);
        bzero(sc, sizeof(struct umct_softc));
        ucom = &sc->sc_ucom;
        ucom->sc_dev = self;
index 07e0036..b04d676 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * $FreeBSD: src/sys/dev/usb/ums.c,v 1.64 2003/11/09 09:17:22 tanimura Exp $
- * $DragonFly: src/sys/dev/usbmisc/ums/ums.c,v 1.8 2004/02/11 15:13:06 joerg Exp $
+ * $DragonFly: src/sys/dev/usbmisc/ums/ums.c,v 1.9 2004/03/15 01:10:45 dillon Exp $
  */
 
 /*
@@ -293,11 +293,7 @@ USB_ATTACH(ums)
                        break;
        sc->nbuttons = i - 1;
        sc->sc_loc_btn = malloc(sizeof(struct hid_location)*sc->nbuttons,
-                               M_USBDEV, M_NOWAIT);
-       if (!sc->sc_loc_btn) {
-               printf("%s: no memory\n", USBDEVNAME(sc->sc_dev));
-               USB_ATTACH_ERROR_RETURN;
-       }
+                               M_USBDEV, M_WAITOK);
 
        printf("%s: %d buttons%s\n", USBDEVNAME(sc->sc_dev),
               sc->nbuttons, sc->flags & UMS_Z? " and Z dir." : "");
@@ -307,13 +303,7 @@ USB_ATTACH(ums)
                                hid_input, &sc->sc_loc_btn[i-1], 0);
 
        sc->sc_isize = hid_report_size(desc, size, hid_input, &sc->sc_iid);
-       sc->sc_ibuf = malloc(sc->sc_isize, M_USB, M_NOWAIT);
-       if (!sc->sc_ibuf) {
-               printf("%s: no memory\n", USBDEVNAME(sc->sc_dev));
-               free(sc->sc_loc_btn, M_USB);
-               USB_ATTACH_ERROR_RETURN;
-       }
-
+       sc->sc_ibuf = malloc(sc->sc_isize, M_USB, M_WAITOK);
        sc->sc_ep_addr = ed->bEndpointAddress;
        sc->sc_disconnected = 0;
        free(desc, M_TEMP);