Change M_NOWAIT to M_INTWAIT or M_WAITOK. CAM does a mediocre job checking
authorMatthew Dillon <dillon@dragonflybsd.org>
Fri, 12 Mar 2004 03:24:43 +0000 (03:24 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Fri, 12 Mar 2004 03:24:43 +0000 (03:24 +0000)
for NULL returns from malloc() and even when it does it generally causes
the device operation to fail instead of retrying, resulting in unacceptable
behavior.  M_NOWAIT semantics allow NULL to be returned during normal system
operation.  This is especially true in DragonFly.

Also remove much of the code that previously checked for NULL.  By using
M_INTWAIT or M_WAITOK, malloc() will panic rather then return NULL.  Only
the addition of M_NULLOK allows a blocking malloc() to return NULL, and we
do not use that flag in CAM.

Add M_ZERO to a number of malloc()'s and remove subsequent bzero()'s, and
add M_ZERO to a few mallocs (primarily for the read capacity data structure)
that did not bother zeroing out the structure before.  While the data is
supposed to be overwritten read-capacity is often quite fragile due to the
SCSI simulation layer, so we do not take any chances.

17 files changed:
sys/bus/cam/cam_extend.c
sys/bus/cam/cam_periph.c
sys/bus/cam/cam_queue.c
sys/bus/cam/cam_sim.c
sys/bus/cam/cam_xpt.c
sys/bus/cam/scsi/scsi_cd.c
sys/bus/cam/scsi/scsi_ch.c
sys/bus/cam/scsi/scsi_da.c
sys/bus/cam/scsi/scsi_low.c
sys/bus/cam/scsi/scsi_pass.c
sys/bus/cam/scsi/scsi_pt.c
sys/bus/cam/scsi/scsi_sa.c
sys/bus/cam/scsi/scsi_ses.c
sys/bus/cam/scsi/scsi_targ_bh.c
sys/bus/cam/scsi/scsi_target.c
sys/bus/canbus/canbus.c
sys/bus/eisa/eisaconf.c

index f676240..0a3290d 100644 (file)
@@ -13,7 +13,7 @@
  * functioning of this software in any circumstances.
  *
  * $FreeBSD: src/sys/cam/cam_extend.c,v 1.3 1999/08/28 00:40:39 peter Exp $
- * $DragonFly: src/sys/bus/cam/cam_extend.c,v 1.3 2003/08/07 21:16:44 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/cam_extend.c,v 1.4 2004/03/12 03:23:13 dillon Exp $
  */
 /*
  * XXX XXX XXX XXX  We should get DEVFS working so that we
@@ -40,10 +40,7 @@ struct extend_array
 static void *
 cam_extend_alloc(size_t s)
 {
-       void *p = malloc(s, M_DEVBUF, M_NOWAIT);
-       if (!p)
-               panic("extend_alloc: malloc failed.");
-       return p;
+       return(malloc(s, M_DEVBUF, M_INTWAIT));
 }
 
 static void
index c37ee71..6d801b7 100644 (file)
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/cam_periph.c,v 1.24.2.3 2003/01/25 19:04:40 dillon Exp $
- * $DragonFly: src/sys/bus/cam/cam_periph.c,v 1.7 2004/01/30 05:42:09 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/cam_periph.c,v 1.8 2004/03/12 03:23:13 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -105,11 +105,7 @@ cam_periph_alloc(periph_ctor_t *periph_ctor,
                return (CAM_REQ_INVALID);
        }
        
-       periph = (struct cam_periph *)malloc(sizeof(*periph), M_DEVBUF,
-                                            M_NOWAIT);
-
-       if (periph == NULL)
-               return (CAM_RESRC_UNAVAIL);
+       periph = malloc(sizeof(*periph), M_DEVBUF, M_INTWAIT);
        
        init_level++;
 
index c3c7cd2..78ad59c 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.3 2003/08/07 21:16:44 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/cam_queue.c,v 1.4 2004/03/12 03:23:13 dillon Exp $
  */
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -51,13 +51,8 @@ camq_alloc(int size)
 {
        struct camq *camq;
 
-       camq = (struct camq *)malloc(sizeof(*camq), M_DEVBUF, M_NOWAIT);
-       if (camq != NULL) {
-               if (camq_init(camq, size) != 0) {
-                       free(camq, M_DEVBUF);
-                       camq = NULL;
-               }
-       }
+       camq = malloc(sizeof(*camq), M_DEVBUF, M_INTWAIT);
+       camq_init(camq, size);
        return (camq);
 }
        
@@ -67,15 +62,13 @@ camq_init(struct camq *camq, int size)
        bzero(camq, sizeof(*camq));
        camq->array_size = size;
        if (camq->array_size != 0) {
-               camq->queue_array = (cam_pinfo**)malloc(size*sizeof(cam_pinfo*),
-                                                       M_DEVBUF, M_NOWAIT);
-               if (camq->queue_array == NULL) {
-                       printf("camq_init: - cannot malloc array!\n");
-                       return (1);
-               }
+               camq->queue_array = malloc(size * sizeof(cam_pinfo *), 
+                                       M_DEVBUF, M_INTWAIT);
                /*
                 * Heap algorithms like everything numbered from 1, so
                 * offset our pointer into the heap array by one element.
+                *
+                * XXX this is a really dumb idea.
                 */
                camq->queue_array--;
        }
@@ -120,12 +113,8 @@ camq_resize(struct camq *queue, int new_size)
                panic("camq_resize: New queue size can't accomodate "
                      "queued entries.");
 #endif
-       new_array = (cam_pinfo **)malloc(new_size * sizeof(cam_pinfo *),
-                                        M_DEVBUF, M_NOWAIT);
-       if (new_array == NULL) {
-               /* Couldn't satisfy request */
-               return (CAM_RESRC_UNAVAIL);
-       }
+       new_array = malloc(new_size * sizeof(cam_pinfo *), M_DEVBUF, M_INTWAIT);
+
        /*
         * Heap algorithms like everything numbered from 1, so
         * remember that our pointer into the heap array is offset
@@ -209,16 +198,8 @@ cam_devq_alloc(int devices, int openings)
 {
        struct cam_devq *devq;
 
-       devq = (struct cam_devq *)malloc(sizeof(*devq), M_DEVBUF, M_NOWAIT);
-       if (devq == NULL) {
-               printf("cam_devq_alloc: - cannot malloc!\n");
-               return (NULL);
-       }
-       if (cam_devq_init(devq, devices, openings) != 0) {
-               free(devq, M_DEVBUF);
-               return (NULL);          
-       }
-       
+       devq = malloc(sizeof(*devq), M_DEVBUF, M_INTWAIT);
+       cam_devq_init(devq, devices, openings);
        return (devq);
 }
 
@@ -226,13 +207,8 @@ int
 cam_devq_init(struct cam_devq *devq, int devices, int openings)
 {
        bzero(devq, sizeof(*devq));
-       if (camq_init(&devq->alloc_queue, devices) != 0) {
-               return (1);
-       }
-       if (camq_init(&devq->send_queue, devices) != 0) {
-               camq_fini(&devq->alloc_queue);
-               return (1);
-       }
+       camq_init(&devq->alloc_queue, devices);
+       camq_init(&devq->send_queue, devices);
        devq->alloc_openings = openings;
        devq->alloc_active = 0;
        devq->send_openings = openings;
@@ -266,16 +242,8 @@ cam_ccbq_alloc(int openings)
 {
        struct cam_ccbq *ccbq;
 
-       ccbq = (struct cam_ccbq *)malloc(sizeof(*ccbq), M_DEVBUF, M_NOWAIT);
-       if (ccbq == NULL) {
-               printf("cam_ccbq_alloc: - cannot malloc!\n");
-               return (NULL);
-       }
-       if (cam_ccbq_init(ccbq, openings) != 0) {
-               free(ccbq, M_DEVBUF);
-               return (NULL);          
-       }
-       
+       ccbq = malloc(sizeof(*ccbq), M_DEVBUF, M_INTWAIT);
+       cam_ccbq_init(ccbq, openings);
        return (ccbq);
 }
 
@@ -323,9 +291,7 @@ int
 cam_ccbq_init(struct cam_ccbq *ccbq, int openings)
 {
        bzero(ccbq, sizeof(*ccbq));
-       if (camq_init(&ccbq->queue, openings) != 0) {
-               return (1);
-       }
+       camq_init(&ccbq->queue, openings);
        ccbq->devq_openings = openings;
        ccbq->dev_openings = openings;  
        TAILQ_INIT(&ccbq->active_ccbs);
index 2218591..26862fb 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.4 2003/08/07 21:16:44 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/cam_sim.c,v 1.5 2004/03/12 03:23:13 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -52,6 +52,11 @@ cam_simq_free(struct cam_devq *devq)
        cam_devq_free(devq);
 }
 
+/*
+ * cam_sim_alloc() may potentially be called from an interrupt (?) but
+ * unexpected things happen to the system if malloc() returns NULL so we
+ * use M_INTWAIT anyway.
+ */
 struct cam_sim *
 cam_sim_alloc(sim_action_func sim_action, sim_poll_func sim_poll,
              const char *sim_name, void *softc, u_int32_t unit,
@@ -60,33 +65,19 @@ cam_sim_alloc(sim_action_func sim_action, sim_poll_func sim_poll,
 {
        struct cam_sim *sim;
 
-       /*
-        * If this is the xpt layer creating a sim, then it's OK
-        * to wait for an allocation.
-        *
-        * XXX Should we pass in a flag to indicate that wait is OK?
-        */
-       if (strcmp(sim_name, "xpt") == 0)
-               sim = (struct cam_sim *)malloc(sizeof(struct cam_sim),
-                                              M_DEVBUF, M_WAITOK);
-       else
-               sim = (struct cam_sim *)malloc(sizeof(struct cam_sim),
-                                              M_DEVBUF, M_NOWAIT);
-
-       if (sim != NULL) {
-               sim->sim_action = sim_action;
-               sim->sim_poll = sim_poll;
-               sim->sim_name = sim_name;
-               sim->softc = softc;
-               sim->path_id = CAM_PATH_ANY;
-               sim->unit_number = unit;
-               sim->bus_id = 0;        /* set in xpt_bus_register */
-               sim->max_tagged_dev_openings = max_tagged_dev_transactions;
-               sim->max_dev_openings = max_dev_transactions;
-               sim->flags = 0;
-               callout_handle_init(&sim->c_handle);
-               sim->devq = queue;
-       }
+       sim = malloc(sizeof(struct cam_sim), M_DEVBUF, M_INTWAIT);
+       sim->sim_action = sim_action;
+       sim->sim_poll = sim_poll;
+       sim->sim_name = sim_name;
+       sim->softc = softc;
+       sim->path_id = CAM_PATH_ANY;
+       sim->unit_number = unit;
+       sim->bus_id = 0;        /* set in xpt_bus_register */
+       sim->max_tagged_dev_openings = max_tagged_dev_transactions;
+       sim->max_dev_openings = max_dev_transactions;
+       sim->flags = 0;
+       callout_handle_init(&sim->c_handle);
+       sim->devq = queue;
 
        return (sim);
 }
index b1d9d25..f8d8c9e 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.9 2004/01/30 05:42:09 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/cam_xpt.c,v 1.10 2004/03/12 03:23:13 dillon Exp $
  */
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1359,15 +1359,8 @@ xpt_init(dummy)
        /*
         * Register a callback for when interrupts are enabled.
         */
-       xpt_config_hook =
-           (struct intr_config_hook *)malloc(sizeof(struct intr_config_hook),
-                                             M_TEMP, M_NOWAIT | M_ZERO);
-       if (xpt_config_hook == NULL) {
-               printf("xpt_init: Cannot malloc config hook "
-                      "- failing attach\n");
-               return;
-       }
-
+       xpt_config_hook = malloc(sizeof(struct intr_config_hook),
+                                 M_TEMP, M_INTWAIT | M_ZERO);
        xpt_config_hook->ich_func = xpt_config;
        if (config_intrhook_establish(xpt_config_hook) != 0) {
                free (xpt_config_hook, M_TEMP);
@@ -3190,13 +3183,8 @@ xpt_action(union ccb *start_ccb)
                                cur_entry->event_enable = csa->event_enable;
                        }
                } else {
-                       cur_entry = malloc(sizeof(*cur_entry), M_DEVBUF,
-                                          M_NOWAIT);
-                       if (cur_entry == NULL) {
-                               splx(s);
-                               csa->ccb_h.status = CAM_RESRC_UNAVAIL;
-                               break;
-                       }
+                       cur_entry = malloc(sizeof(*cur_entry), 
+                                           M_DEVBUF, M_INTWAIT);
                        cur_entry->event_enable = csa->event_enable;
                        cur_entry->callback_arg = csa->callback_arg;
                        cur_entry->callback = csa->callback;
@@ -3791,12 +3779,7 @@ xpt_create_path(struct cam_path **new_path_ptr, struct cam_periph *perph,
        struct     cam_path *path;
        cam_status status;
 
-       path = (struct cam_path *)malloc(sizeof(*path), M_DEVBUF, M_NOWAIT);
-
-       if (path == NULL) {
-               status = CAM_RESRC_UNAVAIL;
-               return(status);
-       }
+       path = malloc(sizeof(*path), M_DEVBUF, M_INTWAIT);
        status = xpt_compile_path(path, perph, path_id, target_id, lun_id);
        if (status != CAM_REQ_CMP) {
                free(path, M_DEVBUF);
@@ -4070,15 +4053,9 @@ xpt_bus_register(struct cam_sim *sim, u_int32_t bus)
        int s;
 
        sim->bus_id = bus;
-       new_bus = (struct cam_eb *)malloc(sizeof(*new_bus),
-                                         M_DEVBUF, M_NOWAIT);
-       if (new_bus == NULL) {
-               /* Couldn't satisfy request */
-               return (CAM_RESRC_UNAVAIL);
-       }
+       new_bus = malloc(sizeof(*new_bus), M_DEVBUF, M_INTWAIT);
 
        if (strcmp(sim->sim_name, "xpt") != 0) {
-
                sim->path_id =
                    xptpathid(sim->sim_name, sim->unit_number, sim->bus_id);
        }
@@ -4564,7 +4541,7 @@ xpt_alloc_ccb()
 {
        union ccb *new_ccb;
 
-       new_ccb = malloc(sizeof(*new_ccb), M_DEVBUF, M_WAITOK);
+       new_ccb = malloc(sizeof(*new_ccb), M_DEVBUF, M_INTWAIT);
        return (new_ccb);
 }
 
@@ -4593,11 +4570,7 @@ xpt_get_ccb(struct cam_ed *device)
 
        s = splsoftcam();
        if ((new_ccb = (union ccb *)ccb_freeq.slh_first) == NULL) {
-               new_ccb = malloc(sizeof(*new_ccb), M_DEVBUF, M_NOWAIT);
-                if (new_ccb == NULL) {
-                       splx(s);
-                       return (NULL);
-               }
+               new_ccb = malloc(sizeof(*new_ccb), M_DEVBUF, M_INTWAIT);
                callout_handle_init(&new_ccb->ccb_h.timeout_ch);
                SLIST_INSERT_HEAD(&ccb_freeq, &new_ccb->ccb_h,
                                  xpt_links.sle);
@@ -4615,6 +4588,10 @@ 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)) {
                TAILQ_REMOVE(&xpt_busses, bus, links);
@@ -4629,35 +4606,33 @@ static struct cam_et *
 xpt_alloc_target(struct cam_eb *bus, target_id_t target_id)
 {
        struct cam_et *target;
+       struct cam_et *cur_target;
 
-       target = (struct cam_et *)malloc(sizeof(*target), M_DEVBUF, M_NOWAIT);
-       if (target != NULL) {
-               struct cam_et *cur_target;
+       target = malloc(sizeof(*target), M_DEVBUF, M_INTWAIT);
 
-               TAILQ_INIT(&target->ed_entries);
-               target->bus = bus;
-               target->target_id = target_id;
-               target->refcount = 1;
-               target->generation = 0;
-               timevalclear(&target->last_reset);
-               /*
-                * Hold a reference to our parent bus so it
-                * will not go away before we do.
-                */
-               bus->refcount++;
+       TAILQ_INIT(&target->ed_entries);
+       target->bus = bus;
+       target->target_id = target_id;
+       target->refcount = 1;
+       target->generation = 0;
+       timevalclear(&target->last_reset);
+       /*
+        * Hold a reference to our parent bus so it
+        * will not go away before we do.
+        */
+       bus->refcount++;
 
-               /* Insertion sort into our bus's target list */
-               cur_target = TAILQ_FIRST(&bus->et_entries);
-               while (cur_target != NULL && cur_target->target_id < target_id)
-                       cur_target = TAILQ_NEXT(cur_target, links);
+       /* Insertion sort into our bus's target list */
+       cur_target = TAILQ_FIRST(&bus->et_entries);
+       while (cur_target != NULL && cur_target->target_id < target_id)
+               cur_target = TAILQ_NEXT(cur_target, links);
 
-               if (cur_target != NULL) {
-                       TAILQ_INSERT_BEFORE(cur_target, target, links);
-               } else {
-                       TAILQ_INSERT_TAIL(&bus->et_entries, target, links);
-               }
-               bus->generation++;
+       if (cur_target != NULL) {
+               TAILQ_INSERT_BEFORE(cur_target, target, links);
+       } else {
+               TAILQ_INSERT_TAIL(&bus->et_entries, target, links);
        }
+       bus->generation++;
        return (target);
 }
 
@@ -4667,6 +4642,11 @@ 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)) {
                TAILQ_REMOVE(&bus->et_entries, target, links);
@@ -4692,8 +4672,7 @@ xpt_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
        if (status != CAM_REQ_CMP) {
                device = NULL;
        } else {
-               device = (struct cam_ed *)malloc(sizeof(*device),
-                                                M_DEVBUF, M_NOWAIT);
+               device = malloc(sizeof(*device), M_DEVBUF, M_INTWAIT);
        }
 
        if (device != NULL) {
@@ -4768,6 +4747,12 @@ xpt_release_device(struct cam_eb *bus, struct cam_et *target,
        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
+
        if ((--device->refcount == 0)
         && ((device->flags & CAM_DEV_UNCONFIGURED) != 0)) {
                struct cam_devq *devq;
@@ -4776,9 +4761,11 @@ xpt_release_device(struct cam_eb *bus, struct cam_et *target,
                 || device->send_ccb_entry.pinfo.index != CAM_UNQUEUED_INDEX)
                        panic("Removing device while still queued for ccbs");
 
-               if ((device->flags & CAM_DEV_REL_TIMEOUT_PENDING) != 0)
-                               untimeout(xpt_release_devq_timeout, device,
-                                         device->c_handle);
+               if ((device->flags & CAM_DEV_REL_TIMEOUT_PENDING) != 0) {
+                       device->flags &= ~CAM_DEV_REL_TIMEOUT_PENDING;
+                       untimeout(xpt_release_devq_timeout, device,
+                                 device->c_handle);
+               }
 
                TAILQ_REMOVE(&target->ed_entries, device,links);
                target->generation++;
@@ -4915,7 +4902,7 @@ xpt_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
 
                /* Save some state for use while we probe for devices */
                scan_info = (xpt_scan_bus_info *)
-                   malloc(sizeof(xpt_scan_bus_info), M_TEMP, M_WAITOK);
+                   malloc(sizeof(xpt_scan_bus_info), M_TEMP, M_INTWAIT);
                scan_info->request_ccb = request_ccb;
                scan_info->cpi = &work_ccb->cpi;
 
@@ -5150,21 +5137,8 @@ xpt_scan_lun(struct cam_periph *periph, struct cam_path *path,
        }
 
        if (request_ccb == NULL) {
-               request_ccb = malloc(sizeof(union ccb), M_TEMP, M_NOWAIT);
-               if (request_ccb == NULL) {
-                       xpt_print_path(path);
-                       printf("xpt_scan_lun: can't allocate CCB, can't "
-                              "continue\n");
-                       return;
-               }
-               new_path = malloc(sizeof(*new_path), M_TEMP, M_NOWAIT);
-               if (new_path == NULL) {
-                       xpt_print_path(path);
-                       printf("xpt_scan_lun: can't allocate path, can't "
-                              "continue\n");
-                       free(request_ccb, M_TEMP);
-                       return;
-               }
+               request_ccb = malloc(sizeof(union ccb), M_TEMP, M_INTWAIT);
+               new_path = malloc(sizeof(*new_path), M_TEMP, M_INTWAIT);
                status = xpt_compile_path(new_path, xpt_periph,
                                          path->bus->path_id,
                                          path->target->target_id,
@@ -5235,13 +5209,7 @@ proberegister(struct cam_periph *periph, void *arg)
                return(CAM_REQ_CMP_ERR);
        }
 
-       softc = (probe_softc *)malloc(sizeof(*softc), M_TEMP, M_NOWAIT);
-
-       if (softc == NULL) {
-               printf("proberegister: Unable to probe new device. "
-                      "Unable to allocate softc\n");                           
-               return(CAM_REQ_CMP_ERR);
-       }
+       softc = malloc(sizeof(*softc), M_TEMP, M_WAITOK | M_ZERO);
        TAILQ_INIT(&softc->request_ccbs);
        TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
                          periph_links.tqe);
@@ -5389,25 +5357,19 @@ probestart(struct cam_periph *periph, union ccb *start_ccb)
                mode_buf_len = sizeof(struct scsi_mode_header_6)
                             + sizeof(struct scsi_mode_blk_desc)
                             + sizeof(struct scsi_control_page);
-               mode_buf = malloc(mode_buf_len, M_TEMP, M_NOWAIT);
-               if (mode_buf != NULL) {
-                       scsi_mode_sense(csio,
-                                       /*retries*/4,
-                                       probedone,
-                                       MSG_SIMPLE_Q_TAG,
-                                       /*dbd*/FALSE,
-                                       SMS_PAGE_CTRL_CURRENT,
-                                       SMS_CONTROL_MODE_PAGE,
-                                       mode_buf,
-                                       mode_buf_len,
-                                       SSD_FULL_SIZE,
-                                       /*timeout*/60000);
-                       break;
-               }
-               xpt_print_path(periph->path);
-               printf("Unable to mode sense control page - malloc failure\n");
-               softc->action = PROBE_SERIAL_NUM;
-               /* FALLTHROUGH */
+               mode_buf = malloc(mode_buf_len, M_TEMP, M_INTWAIT);
+               scsi_mode_sense(csio,
+                               /*retries*/4,
+                               probedone,
+                               MSG_SIMPLE_Q_TAG,
+                               /*dbd*/FALSE,
+                               SMS_PAGE_CTRL_CURRENT,
+                               SMS_CONTROL_MODE_PAGE,
+                               mode_buf,
+                               mode_buf_len,
+                               SSD_FULL_SIZE,
+                               /*timeout*/60000);
+               break;
        }
        case PROBE_SERIAL_NUM:
        {
@@ -5419,12 +5381,9 @@ probestart(struct cam_periph *periph, union ccb *start_ccb)
                device->serial_num = NULL;
                device->serial_num_len = 0;
 
-               if ((device->quirk->quirks & CAM_QUIRK_NOSERIAL) == 0)
-                       serial_buf = (struct scsi_vpd_unit_serial_number *)
-                               malloc(sizeof(*serial_buf), M_TEMP,
-                                       M_NOWAIT | M_ZERO);
-
-               if (serial_buf != NULL) {
+               if ((device->quirk->quirks & CAM_QUIRK_NOSERIAL) == 0) {
+                       serial_buf = malloc(sizeof(*serial_buf), M_TEMP,
+                                           M_INTWAIT | M_ZERO);
                        scsi_inquiry(csio,
                                     /*retries*/4,
                                     probedone,
@@ -5637,17 +5596,13 @@ probedone(struct cam_periph *periph, union ccb *done_ccb)
 
                        have_serialnum = 1;
                        path->device->serial_num =
-                               (u_int8_t *)malloc((serial_buf->length + 1),
-                                                  M_DEVBUF, M_NOWAIT);
-                       if (path->device->serial_num != NULL) {
-                               bcopy(serial_buf->serial_num,
-                                     path->device->serial_num,
-                                     serial_buf->length);
-                               path->device->serial_num_len =
-                                   serial_buf->length;
-                               path->device->serial_num[serial_buf->length]
-                                   = '\0';
-                       }
+                               malloc((serial_buf->length + 1),
+                                      M_DEVBUF, M_INTWAIT);
+                       bcopy(serial_buf->serial_num,
+                             path->device->serial_num,
+                             serial_buf->length);
+                       path->device->serial_num_len = serial_buf->length;
+                       path->device->serial_num[serial_buf->length] = '\0';
                } else if (cam_periph_error(done_ccb, 0,
                                            SF_RETRY_UA|SF_NO_PRINT,
                                            &softc->saved_ccb) == ERESTART) {
index 810367b..6cab810 100644 (file)
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_cd.c,v 1.31.2.16 2003/10/21 22:26:11 thomas Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_cd.c,v 1.11 2004/02/16 19:43:28 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_cd.c,v 1.12 2004/03/12 03:23:19 dillon Exp $
  */
 /*
  * Portions of this driver taken from the original FreeBSD cd driver.
@@ -706,15 +706,7 @@ cdregister(struct cam_periph *periph, void *arg)
                return(CAM_REQ_CMP_ERR);
        }
 
-       softc = (struct cd_softc *)malloc(sizeof(*softc),M_DEVBUF,M_NOWAIT);
-
-       if (softc == NULL) {
-               printf("cdregister: Unable to probe new device. "
-                      "Unable to allocate softc\n");                           
-               return(CAM_REQ_CMP_ERR);
-       }
-
-       bzero(softc, sizeof(*softc));
+       softc = malloc(sizeof(*softc), M_DEVBUF, M_WAITOK | M_ZERO);
        LIST_INIT(&softc->pending_ccbs);
        STAILQ_INIT(&softc->mode_queue);
        softc->state = CD_STATE_PROBE;
@@ -920,23 +912,7 @@ cdregister(struct cam_periph *periph, void *arg)
                 */
                else {
                        nchanger = malloc(sizeof(struct cdchanger),
-                               M_DEVBUF, M_NOWAIT);
-
-                       if (nchanger == NULL) {
-                               softc->flags &= ~CD_FLAG_CHANGER;
-                               printf("cdregister: unable to malloc "
-                                      "changer structure\ncdregister: "
-                                      "changer support disabled\n");
-
-                               /*
-                                * Yes, gotos can be gross but in this case
-                                * I think it's justified..
-                                */
-                               goto cdregisterexit;
-                       }
-
-                       /* zero the structure */
-                       bzero(nchanger, sizeof(struct cdchanger));
+                               M_DEVBUF, M_INTWAIT | M_ZERO);
 
                        if (camq_init(&nchanger->devq, 1) != 0) {
                                softc->flags &= ~CD_FLAG_CHANGER;
@@ -1630,15 +1606,7 @@ cdstart(struct cam_periph *periph, union ccb *start_ccb)
        case CD_STATE_PROBE:
        {
 
-               rcap = (struct scsi_read_capacity_data *)malloc(sizeof(*rcap),
-                                                               M_TEMP,
-                                                               M_NOWAIT);
-               if (rcap == NULL) {
-                       xpt_print_path(periph->path);
-                       printf("cdstart: Couldn't malloc read_capacity data\n");
-                       /* cd_free_periph??? */
-                       break;
-               }
+               rcap = malloc(sizeof(*rcap), M_TEMP, M_INTWAIT);
                csio = &start_ccb->csio;
                scsi_read_capacity(csio,
                                   /*retries*/1,
@@ -2019,7 +1987,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
 
                        params.alloc_len = sizeof(union cd_mode_data_6_10);
                        params.mode_buf = malloc(params.alloc_len, M_TEMP,
-                                                M_WAITOK | M_ZERO);
+                                                M_INTWAIT | M_ZERO);
 
                        CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE, 
                                  ("trying to do CDIOCPLAYTRACKS\n"));
@@ -2109,7 +2077,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
 
                        params.alloc_len = sizeof(union cd_mode_data_6_10);
                        params.mode_buf = malloc(params.alloc_len, M_TEMP,
-                                                M_WAITOK | M_ZERO);
+                                                M_INTWAIT | M_ZERO);
 
                        CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE, 
                                  ("trying to do CDIOCPLAYMSF\n"));
@@ -2148,7 +2116,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
 
                        params.alloc_len = sizeof(union cd_mode_data_6_10);
                        params.mode_buf = malloc(params.alloc_len, M_TEMP,
-                                                M_WAITOK | M_ZERO);
+                                                M_INTWAIT | M_ZERO);
 
                        error = cdgetmode(periph, &params, AUDIO_PAGE);
                        if (error) {
@@ -2177,7 +2145,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
                                  ("trying to do CDIOCREADSUBCHANNEL\n"));
 
                        data = malloc(sizeof(struct cd_sub_channel_info), 
-                                     M_TEMP, M_WAITOK);
+                                     M_TEMP, M_INTWAIT);
 
                        if ((len > sizeof(struct cd_sub_channel_info)) ||
                            (len < sizeof(struct cd_sub_channel_header))) {
@@ -2221,7 +2189,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
                                  ("trying to do CDIOREADTOCHEADER\n"));
 
                        th = malloc(sizeof(struct ioc_toc_header), M_TEMP,
-                                   M_WAITOK);
+                                   M_INTWAIT);
                        error = cdreadtoc(periph, 0, 0, (u_int8_t *)th, 
                                          sizeof (*th), /*sense_flags*/0);
                        if (error) {
@@ -2254,8 +2222,8 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
                        CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE, 
                                  ("trying to do CDIOREADTOCENTRYS\n"));
 
-                       data = malloc(sizeof(*data), M_TEMP, M_WAITOK);
-                       lead = malloc(sizeof(*lead), M_TEMP, M_WAITOK);
+                       data = malloc(sizeof(*data), M_TEMP, M_INTWAIT);
+                       lead = malloc(sizeof(*lead), M_TEMP, M_INTWAIT);
 
                        if (te->data_len < sizeof(struct cd_toc_entry)
                         || (te->data_len % sizeof(struct cd_toc_entry)) != 0
@@ -2375,7 +2343,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
                        CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE, 
                                  ("trying to do CDIOREADTOCENTRY\n"));
 
-                       data = malloc(sizeof(*data), M_TEMP, M_WAITOK);
+                       data = malloc(sizeof(*data), M_TEMP, M_INTWAIT);
 
                        if (te->address_format != CD_MSF_FORMAT
                            && te->address_format != CD_LBA_FORMAT) {
@@ -2442,7 +2410,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
 
                        params.alloc_len = sizeof(union cd_mode_data_6_10);
                        params.mode_buf = malloc(params.alloc_len, M_TEMP, 
-                                                M_WAITOK | M_ZERO);
+                                                M_INTWAIT | M_ZERO);
                        error = cdgetmode(periph, &params, AUDIO_PAGE);
                        if (error) {
                                free(params.mode_buf, M_TEMP);
@@ -2471,7 +2439,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
 
                        params.alloc_len = sizeof(union cd_mode_data_6_10);
                        params.mode_buf = malloc(params.alloc_len, M_TEMP, 
-                                                M_WAITOK | M_ZERO);
+                                                M_INTWAIT | M_ZERO);
                        error = cdgetmode(periph, &params, AUDIO_PAGE);
                        if (error) {
                                free(params.mode_buf, M_TEMP);
@@ -2499,7 +2467,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
 
                        params.alloc_len = sizeof(union cd_mode_data_6_10);
                        params.mode_buf = malloc(params.alloc_len, M_TEMP, 
-                                                M_WAITOK | M_ZERO);
+                                                M_INTWAIT | M_ZERO);
                        error = cdgetmode(periph, &params, AUDIO_PAGE);
                        if (error) {
                                free(params.mode_buf, M_TEMP);
@@ -2529,7 +2497,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
 
                        params.alloc_len = sizeof(union cd_mode_data_6_10);
                        params.mode_buf = malloc(params.alloc_len, M_TEMP,
-                                                M_WAITOK | M_ZERO);
+                                                M_INTWAIT | M_ZERO);
                        error = cdgetmode(periph, &params, AUDIO_PAGE);
                        if (error) {
                                free(params.mode_buf, M_TEMP);
@@ -2557,7 +2525,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
 
                        params.alloc_len = sizeof(union cd_mode_data_6_10);
                        params.mode_buf = malloc(params.alloc_len, M_TEMP,
-                                                M_WAITOK | M_ZERO);
+                                                M_INTWAIT | M_ZERO);
                        error = cdgetmode(periph, &params, AUDIO_PAGE);
                        if (error) {
                                free(params.mode_buf, M_TEMP);
@@ -2585,7 +2553,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
 
                        params.alloc_len = sizeof(union cd_mode_data_6_10);
                        params.mode_buf = malloc(params.alloc_len, M_TEMP,
-                                                M_WAITOK | M_ZERO);
+                                                M_INTWAIT | M_ZERO);
                        error = cdgetmode(periph, &params, AUDIO_PAGE);
                        if (error) {
                                free(&params, M_TEMP);
@@ -2611,7 +2579,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
 
                        params.alloc_len = sizeof(union cd_mode_data_6_10);
                        params.mode_buf = malloc(params.alloc_len, M_TEMP,
-                                                M_WAITOK | M_ZERO);
+                                                M_INTWAIT | M_ZERO);
                        
                        error = cdgetmode(periph, &params, AUDIO_PAGE);
                        if (error) {
@@ -2638,7 +2606,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *td)
 
                        params.alloc_len = sizeof(union cd_mode_data_6_10);
                        params.mode_buf = malloc(params.alloc_len, M_TEMP,
-                                                M_WAITOK | M_ZERO);
+                                                M_INTWAIT | M_ZERO);
 
                        error = cdgetmode(periph, &params, AUDIO_PAGE);
                        if (error) {
@@ -3091,7 +3059,7 @@ cdsize(struct cam_periph *periph, u_int32_t *size)
        ccb = cdgetccb(periph, /* priority */ 1);
 
        rcap_buf = malloc(sizeof(struct scsi_read_capacity_data), 
-                         M_TEMP, M_WAITOK);
+                         M_TEMP, M_INTWAIT | M_ZERO);
 
        scsi_read_capacity(&ccb->csio, 
                           /*retries*/ 1,
@@ -3949,9 +3917,10 @@ cdreportkey(struct cam_periph *periph, struct dvd_authinfo *authinfo)
        }
 
        if (length != 0) {
-               databuf = malloc(length, M_DEVBUF, M_WAITOK | M_ZERO);
-       } else
+               databuf = malloc(length, M_DEVBUF, M_INTWAIT | M_ZERO);
+       } else {
                databuf = NULL;
+       }
 
 
        scsi_report_key(&ccb->csio,
@@ -4082,7 +4051,7 @@ cdsendkey(struct cam_periph *periph, struct dvd_authinfo *authinfo)
 
                length = sizeof(*challenge_data);
 
-               challenge_data = malloc(length, M_DEVBUF, M_WAITOK | M_ZERO);
+               challenge_data = malloc(length, M_DEVBUF, M_INTWAIT | M_ZERO);
 
                databuf = (u_int8_t *)challenge_data;
 
@@ -4099,7 +4068,7 @@ cdsendkey(struct cam_periph *periph, struct dvd_authinfo *authinfo)
 
                length = sizeof(*key2_data);
 
-               key2_data = malloc(length, M_DEVBUF, M_WAITOK | M_ZERO);
+               key2_data = malloc(length, M_DEVBUF, M_INTWAIT | M_ZERO);
 
                databuf = (u_int8_t *)key2_data;
 
@@ -4116,7 +4085,7 @@ cdsendkey(struct cam_periph *periph, struct dvd_authinfo *authinfo)
 
                length = sizeof(*rpc_data);
 
-               rpc_data = malloc(length, M_DEVBUF, M_WAITOK | M_ZERO);
+               rpc_data = malloc(length, M_DEVBUF, M_INTWAIT | M_ZERO);
 
                databuf = (u_int8_t *)rpc_data;
 
@@ -4258,9 +4227,10 @@ cdreaddvdstructure(struct cam_periph *periph, struct dvd_struct *dvdstruct)
        }
 
        if (length != 0) {
-               databuf = malloc(length, M_DEVBUF, M_WAITOK | M_ZERO);
-       } else
+               databuf = malloc(length, M_DEVBUF, M_INTWAIT | M_ZERO);
+       } else {
                databuf = NULL;
+       }
 
        scsi_read_dvd_structure(&ccb->csio,
                                /* retries */ 1,
index 4f28d10..7fdbacd 100644 (file)
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_ch.c,v 1.20.2.2 2000/10/31 08:09:49 dwmalone Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_ch.c,v 1.6 2003/08/07 21:16:44 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_ch.c,v 1.7 2004/03/12 03:23:19 dillon Exp $
  */
 /*
  * Derived from the NetBSD SCSI changer driver.
@@ -378,15 +378,7 @@ chregister(struct cam_periph *periph, void *arg)
                return(CAM_REQ_CMP_ERR);
        }
 
-       softc = (struct ch_softc *)malloc(sizeof(*softc),M_DEVBUF,M_NOWAIT);
-
-       if (softc == NULL) {
-               printf("chregister: Unable to probe new device. "
-                      "Unable to allocate softc\n");                           
-               return(CAM_REQ_CMP_ERR);
-       }
-
-       bzero(softc, sizeof(*softc));
+       softc = malloc(sizeof(*softc), M_DEVBUF, M_WAITOK | M_ZERO);
        softc->state = CH_STATE_PROBE;
        periph->softc = softc;
        cam_extend_set(chperiphs, periph->unit_number, periph);
@@ -542,14 +534,7 @@ chstart(struct cam_periph *periph, union ccb *start_ccb)
                                  sizeof(struct scsi_mode_blk_desc) +
                                 sizeof(struct page_element_address_assignment);
 
-               mode_buffer = malloc(mode_buffer_len, M_TEMP, M_NOWAIT);
-
-               if (mode_buffer == NULL) {
-                       printf("chstart: couldn't malloc mode sense data\n");
-                       break;
-               }
-               bzero(mode_buffer, mode_buffer_len);
-
+               mode_buffer = malloc(mode_buffer_len, M_TEMP, M_INTWAIT | M_ZERO);
                /*
                 * Get the element address assignment page.
                 */
@@ -1124,7 +1109,7 @@ chgetelemstatus(struct cam_periph *periph,
         * we can allocate enough storage for all of them.  We assume
         * that the first one can fit into 1k.
         */
-       data = (caddr_t)malloc(1024, M_DEVBUF, M_WAITOK);
+       data = (caddr_t)malloc(1024, M_DEVBUF, M_INTWAIT);
 
        ccb = cam_periph_getccb(periph, /*priority*/ 1);
 
@@ -1161,7 +1146,7 @@ chgetelemstatus(struct cam_periph *periph,
         * device.
         */
        free(data, M_DEVBUF);
-       data = (caddr_t)malloc(size, M_DEVBUF, M_WAITOK);
+       data = (caddr_t)malloc(size, M_DEVBUF, M_INTWAIT);
 
        scsi_read_element_status(&ccb->csio,
                                 /* retries */ 1,
@@ -1196,7 +1181,7 @@ chgetelemstatus(struct cam_periph *periph,
 
        user_data = (struct changer_element_status *)
                malloc(avail * sizeof(struct changer_element_status),
-                      M_DEVBUF, M_WAITOK | M_ZERO);
+                      M_DEVBUF, M_INTWAIT | M_ZERO);
 
        desc = (struct read_element_status_descriptor *)((uintptr_t)data +
                sizeof(struct read_element_status_header) +
@@ -1377,14 +1362,7 @@ chgetparams(struct cam_periph *periph)
         */
        mode_buffer_len = sizeof(struct scsi_mode_sense_data);
 
-       mode_buffer = malloc(mode_buffer_len, M_TEMP, M_NOWAIT);
-
-       if (mode_buffer == NULL) {
-               printf("chgetparams: couldn't malloc mode sense data\n");
-               return(ENOSPC);
-       }
-
-       bzero(mode_buffer, mode_buffer_len);
+       mode_buffer = malloc(mode_buffer_len, M_TEMP, M_INTWAIT | M_ZERO);
 
        if (softc->quirks & CH_Q_NO_DBD)
                dbd = FALSE;
index 6fed871..bf8d273 100644 (file)
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_da.c,v 1.42.2.46 2003/10/21 22:18:19 thomas Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_da.c,v 1.13 2004/02/16 19:43:28 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_da.c,v 1.14 2004/03/12 03:23:19 dillon Exp $
  */
 
 #ifdef _KERNEL
@@ -537,9 +537,7 @@ daopen(dev_t dev, int flags, int fmt, struct thread *td)
                struct scsi_read_capacity_data *rcap;
                union  ccb *ccb;
 
-               rcap = (struct scsi_read_capacity_data *)malloc(sizeof(*rcap),
-                                                               M_TEMP,
-                                                               M_WAITOK);
+               rcap = malloc(sizeof(*rcap), M_TEMP, M_INTWAIT | M_ZERO);
                
                ccb = cam_periph_getccb(periph, /*priority*/1);
                scsi_read_capacity(&ccb->csio,
@@ -1218,15 +1216,7 @@ daregister(struct cam_periph *periph, void *arg)
                return(CAM_REQ_CMP_ERR);
        }
 
-       softc = (struct da_softc *)malloc(sizeof(*softc),M_DEVBUF,M_NOWAIT);
-
-       if (softc == NULL) {
-               printf("daregister: Unable to probe new device. "
-                      "Unable to allocate softc\n");                           
-               return(CAM_REQ_CMP_ERR);
-       }
-
-       bzero(softc, sizeof(*softc));
+       softc = malloc(sizeof(*softc), M_DEVBUF, M_WAITOK | M_ZERO);
        LIST_INIT(&softc->pending_ccbs);
        softc->state = DA_STATE_PROBE;
        bufq_init(&softc->buf_queue);
@@ -1434,14 +1424,7 @@ dastart(struct cam_periph *periph, union ccb *start_ccb)
                struct ccb_scsiio *csio;
                struct scsi_read_capacity_data *rcap;
 
-               rcap = (struct scsi_read_capacity_data *)malloc(sizeof(*rcap),
-                                                               M_TEMP,
-                                                               M_NOWAIT);
-               if (rcap == NULL) {
-                       printf("dastart: Couldn't malloc read_capacity data\n");
-                       /* da_free_periph??? */
-                       break;
-               }
+               rcap = malloc(sizeof(*rcap), M_TEMP, M_INTWAIT | M_ZERO);
                csio = &start_ccb->csio;
                scsi_read_capacity(csio,
                                   /*retries*/4,
index 82c02eb..31df24e 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.7 2004/02/11 17:46:33 joerg Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_low.c,v 1.8 2004/03/12 03:23:19 dillon Exp $
  * $NetBSD: scsi_low.c,v 1.24.10.8 2001/06/26 07:39:44 honda Exp $
  */
 
@@ -390,7 +390,7 @@ scsi_low_translate_error_code(cb, tp)
  * SCSI INTERFACE (XS)
  **************************************************************/
 #define        SCSI_LOW_MINPHYS                0x10000
-#define        SCSI_LOW_MALLOC(size)           malloc((size), M_DEVBUF, M_NOWAIT)
+#define        SCSI_LOW_MALLOC(size)           malloc((size), M_DEVBUF, M_INTWAIT)
 #define        SCSI_LOW_FREE(pt)               free((pt), M_DEVBUF)
 #define        SCSI_LOW_ALLOC_CCB(flags)       scsi_low_get_ccb((flags))
 #define        SCSI_LOW_XS_POLL_HZ             1000
@@ -880,7 +880,7 @@ scsi_low_target_open(link, cf)
 /**************************************************************
  * SCSI INTERFACE (CAM)
  **************************************************************/
-#define        SCSI_LOW_MALLOC(size)           malloc((size), M_DEVBUF, M_NOWAIT)
+#define        SCSI_LOW_MALLOC(size)           malloc((size), M_DEVBUF, M_INTWAIT)
 #define        SCSI_LOW_FREE(pt)               free((pt), M_DEVBUF)
 #define        SCSI_LOW_ALLOC_CCB(flags)       scsi_low_get_ccb()
 
@@ -959,7 +959,7 @@ scsi_low_rescan_bus_cam(slp)
        struct scsi_low_softc *slp;
 {
        struct cam_path *path;
-       union ccb *ccb = malloc(sizeof(union ccb), M_DEVBUF, M_WAITOK);
+       union ccb *ccb = malloc(sizeof(union ccb), M_DEVBUF, M_INTWAIT);
        cam_status status;
 
        bzero(ccb, sizeof(union ccb));
index 25fe822..0b19d21 100644 (file)
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_pass.c,v 1.19 2000/01/17 06:27:37 mjacob Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_pass.c,v 1.8 2003/08/07 21:16:45 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_pass.c,v 1.9 2004/03/12 03:23:19 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -304,16 +304,7 @@ passregister(struct cam_periph *periph, void *arg)
                return(CAM_REQ_CMP_ERR);
        }
 
-       softc = (struct pass_softc *)malloc(sizeof(*softc),
-                                           M_DEVBUF, M_NOWAIT);
-
-       if (softc == NULL) {
-               printf("passregister: Unable to probe new device. "
-                      "Unable to allocate softc\n");                           
-               return(CAM_REQ_CMP_ERR);
-       }
-
-       bzero(softc, sizeof(*softc));
+       softc = malloc(sizeof(*softc), M_DEVBUF, M_WAITOK | M_ZERO);
        softc->state = PASS_STATE_NORMAL;
        softc->pd_type = SID_TYPE(&cgd->inq_data);
        bufq_init(&softc->buf_queue);
index aa9149d..3e7d8ab 100644 (file)
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_pt.c,v 1.17 2000/01/17 06:27:37 mjacob Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_pt.c,v 1.7 2003/08/07 21:16:45 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_pt.c,v 1.8 2004/03/12 03:23:19 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -332,15 +332,7 @@ ptctor(struct cam_periph *periph, void *arg)
                return(CAM_REQ_CMP_ERR);
        }
 
-       softc = (struct pt_softc *)malloc(sizeof(*softc),M_DEVBUF,M_NOWAIT);
-
-       if (softc == NULL) {
-               printf("daregister: Unable to probe new device. "
-                      "Unable to allocate softc\n");                           
-               return(CAM_REQ_CMP_ERR);
-       }
-
-       bzero(softc, sizeof(*softc));
+       softc = malloc(sizeof(*softc), M_DEVBUF, M_WAITOK | M_ZERO);
        LIST_INIT(&softc->pending_ccbs);
        softc->state = PT_STATE_NORMAL;
        bufq_init(&softc->buf_queue);
index 4a789fd..7e5f3fb 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * $FreeBSD: src/sys/cam/scsi/scsi_sa.c,v 1.45.2.13 2002/12/17 17:08:50 trhodes Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_sa.c,v 1.8 2003/11/21 22:46:13 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_sa.c,v 1.9 2004/03/12 03:23:19 dillon Exp $
  *
  * Implementation of SCSI Sequential Access Peripheral driver for CAM.
  *
@@ -1450,14 +1450,7 @@ saregister(struct cam_periph *periph, void *arg)
                return (CAM_REQ_CMP_ERR);
        }
 
-       softc = (struct sa_softc *)malloc(sizeof (*softc), M_DEVBUF, M_NOWAIT);
-       if (softc == NULL) {
-               printf("saregister: Unable to probe new device. "
-                      "Unable to allocate softc\n");                           
-               return (CAM_REQ_CMP_ERR);
-       }
-
-       bzero(softc, sizeof(*softc));
+       softc = malloc(sizeof (*softc), M_DEVBUF, M_WAITOK | M_ZERO);
        softc->scsi_rev = SID_ANSI_REV(&cgd->inq_data);
        softc->state = SA_STATE_NORMAL;
        softc->fileno = (daddr_t) -1;
@@ -1928,15 +1921,7 @@ samount(struct cam_periph *periph, int oflags, dev_t dev)
                 * blocksize on tape is and don't expect to really
                 * read a full record.
                 */
-               rblim = (struct  scsi_read_block_limits_data *)
-                   malloc(8192, M_TEMP, M_WAITOK);
-               if (rblim == NULL) {
-                       xpt_print_path(ccb->ccb_h.path);
-                       printf("no memory for test read\n");
-                       xpt_release_ccb(ccb);
-                       error = ENOMEM;
-                       goto exit;
-               }
+               rblim = malloc(8192, M_TEMP, M_INTWAIT);
 
                if ((softc->quirks & SA_QUIRK_NODREAD) == 0) {
                        scsi_sa_read_write(&ccb->csio, 0, sadone,
@@ -2554,8 +2539,7 @@ retry:
                        mode_buffer_len += sizeof (sa_comp_t);
        }
 
-       mode_buffer = malloc(mode_buffer_len, M_TEMP, M_WAITOK);
-       bzero(mode_buffer, mode_buffer_len);
+       mode_buffer = malloc(mode_buffer_len, M_TEMP, M_INTWAIT | M_ZERO);
        mode_hdr = (struct scsi_mode_header_6 *)mode_buffer;
        mode_blk = (struct scsi_mode_blk_desc *)&mode_hdr[1];
 
@@ -2735,7 +2719,7 @@ sasetparams(struct cam_periph *periph, sa_params params_to_set,
 
        softc = (struct sa_softc *)periph->softc;
 
-       ccomp = malloc(sizeof (sa_comp_t), M_TEMP, M_WAITOK);
+       ccomp = malloc(sizeof (sa_comp_t), M_TEMP, M_INTWAIT);
 
        /*
         * Since it doesn't make sense to set the number of blocks, or
@@ -2758,8 +2742,7 @@ sasetparams(struct cam_periph *periph, sa_params params_to_set,
        if (params_to_set & SA_PARAM_COMPRESSION)
                mode_buffer_len += sizeof (sa_comp_t);
 
-       mode_buffer = malloc(mode_buffer_len, M_TEMP, M_WAITOK);
-       bzero(mode_buffer, mode_buffer_len);
+       mode_buffer = malloc(mode_buffer_len, M_TEMP, M_INTWAIT | M_ZERO);
 
        mode_hdr = (struct scsi_mode_header_6 *)mode_buffer;
        mode_blk = (struct scsi_mode_blk_desc *)&mode_hdr[1];
index 3cbe414..93dc0af 100644 (file)
@@ -1,5 +1,5 @@
 /* $FreeBSD: src/sys/cam/scsi/scsi_ses.c,v 1.8.2.2 2000/08/08 23:19:21 mjacob Exp $ */
-/* $DragonFly: src/sys/bus/cam/scsi/scsi_ses.c,v 1.7 2003/11/09 02:22:33 dillon Exp $ */
+/* $DragonFly: src/sys/bus/cam/scsi/scsi_ses.c,v 1.8 2004/03/12 03:23:19 dillon Exp $ */
 /*
  * Copyright (c) 2000 Matthew Jacob
  * All rights reserved.
@@ -124,7 +124,7 @@ static int safte_set_objstat(ses_softc_t *, ses_objstat *, int);
 #define        SES_DLOG                if (0) ses_log
 #endif
 #define        SES_VLOG                if (bootverbose) ses_log
-#define        SES_MALLOC(amt)         malloc(amt, M_DEVBUF, M_NOWAIT)
+#define        SES_MALLOC(amt)         malloc(amt, M_DEVBUF, M_INTWAIT)
 #define        SES_FREE(ptr, amt)      free(ptr, M_DEVBUF)
 #define        MEMZERO                 bzero
 #define        MEMCPY(dest, src, amt)  bcopy(src, dest, amt)
@@ -344,13 +344,7 @@ sesregister(struct cam_periph *periph, void *arg)
                return (CAM_REQ_CMP_ERR);
        }
 
-       softc = malloc(sizeof (struct ses_softc), M_DEVBUF, M_NOWAIT);
-       if (softc == NULL) {
-               printf("sesregister: Unable to probe new device. "
-                      "Unable to allocate softc\n");                           
-               return (CAM_REQ_CMP_ERR);
-       }
-       bzero(softc, sizeof (struct ses_softc));
+       softc = malloc(sizeof (struct ses_softc), M_DEVBUF, M_WAITOK | M_ZERO);
        periph->softc = softc;
        softc->periph = periph;
 
index 71e2860..b186ca1 100644 (file)
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_targ_bh.c,v 1.4.2.6 2003/11/14 11:31:25 simokawa Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_targ_bh.c,v 1.6 2004/03/02 20:55:10 drhodus Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_targ_bh.c,v 1.7 2004/03/12 03:23:19 dillon Exp $
  */
 #include <sys/param.h>
 #include <sys/queue.h>
@@ -276,21 +276,10 @@ targbhenlun(struct cam_periph *periph)
        for (i = 0; i < MAX_ACCEPT; i++) {
                struct ccb_accept_tio *atio;
 
-               atio = (struct ccb_accept_tio*)malloc(sizeof(*atio), M_DEVBUF,
-                                                     M_NOWAIT);
-               if (atio == NULL) {
-                       status = CAM_RESRC_UNAVAIL;
-                       break;
-               }
+               atio = malloc(sizeof(*atio), M_DEVBUF, M_INTWAIT);
 
                atio->ccb_h.ccb_descr = targbhallocdescr();
 
-               if (atio->ccb_h.ccb_descr == NULL) {
-                       free(atio, M_DEVBUF);
-                       status = CAM_RESRC_UNAVAIL;
-                       break;
-               }
-
                xpt_setup_ccb(&atio->ccb_h, periph->path, /*priority*/1);
                atio->ccb_h.func_code = XPT_ACCEPT_TARGET_IO;
                atio->ccb_h.cbfcnp = targbhdone;
@@ -321,13 +310,7 @@ targbhenlun(struct cam_periph *periph)
        for (i = 0; i < MAX_ACCEPT; i++) {
                struct ccb_immed_notify *inot;
 
-               inot = (struct ccb_immed_notify*)malloc(sizeof(*inot), M_DEVBUF,
-                                                       M_NOWAIT);
-
-               if (inot == NULL) {
-                       status = CAM_RESRC_UNAVAIL;
-                       break;
-               }
+               inot = malloc(sizeof(*inot), M_DEVBUF, M_INTWAIT);
 
                xpt_setup_ccb(&inot->ccb_h, periph->path, /*priority*/1);
                inot->ccb_h.func_code = XPT_IMMED_NOTIFY;
@@ -411,14 +394,7 @@ targbhctor(struct cam_periph *periph, void *arg)
        cpi = (struct ccb_pathinq *)arg;
 
        /* Allocate our per-instance private storage */
-       softc = (struct targbh_softc *)malloc(sizeof(*softc),
-                                             M_DEVBUF, M_NOWAIT);
-       if (softc == NULL) {
-               printf("targctor: unable to malloc softc\n");
-               return (CAM_REQ_CMP_ERR);
-       }
-
-       bzero(softc, sizeof(*softc));
+       softc = malloc(sizeof(*softc), M_DEVBUF, M_WAITOK | M_ZERO);
        TAILQ_INIT(&softc->pending_queue);
        TAILQ_INIT(&softc->work_queue);
        softc->accept_tio_list = NULL;
@@ -724,19 +700,10 @@ targbhallocdescr()
        struct targbh_cmd_desc* descr;
 
        /* Allocate the targbh_descr structure */
-       descr = (struct targbh_cmd_desc *)malloc(sizeof(*descr),
-                                              M_DEVBUF, M_NOWAIT);
-       if (descr == NULL)
-               return (NULL);
-
-       bzero(descr, sizeof(*descr));
+       descr = malloc(sizeof(*descr), M_DEVBUF, M_INTWAIT | M_ZERO);
 
        /* Allocate buffer backing store */
-       descr->backing_store = malloc(MAX_BUF_SIZE, M_DEVBUF, M_NOWAIT);
-       if (descr->backing_store == NULL) {
-               free(descr, M_DEVBUF);
-               return (NULL);
-       }
+       descr->backing_store = malloc(MAX_BUF_SIZE, M_DEVBUF, M_INTWAIT);
        descr->max_size = MAX_BUF_SIZE;
        return (descr);
 }
index 959c1fe..373b2ff 100644 (file)
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/cam/scsi/scsi_target.c,v 1.22.2.7 2003/02/18 22:07:10 njl Exp $
- * $DragonFly: src/sys/bus/cam/scsi/scsi_target.c,v 1.5 2003/08/07 21:16:45 dillon Exp $
+ * $DragonFly: src/sys/bus/cam/scsi/scsi_target.c,v 1.6 2004/03/12 03:23:19 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -954,7 +954,7 @@ targgetccb(struct targ_softc *softc, xpt_opcode type, int priority)
        int ccb_len;
 
        ccb_len = targccblen(type);
-       MALLOC(ccb, union ccb *, ccb_len, M_TARG, M_WAITOK);
+       MALLOC(ccb, union ccb *, ccb_len, M_TARG, M_INTWAIT);
        CAM_DEBUG(softc->path, CAM_DEBUG_PERIPH, ("getccb %p\n", ccb));
 
        xpt_setup_ccb(&ccb->ccb_h, softc->path, priority);
@@ -997,8 +997,8 @@ targgetdescr(struct targ_softc *softc)
 {
        struct targ_cmd_descr *descr;
 
-       MALLOC(descr, struct targ_cmd_descr *, sizeof(*descr), M_TARG,
-              M_WAITOK);
+       MALLOC(descr, struct targ_cmd_descr *, sizeof(*descr),
+               M_TARG, M_INTWAIT);
        descr->mapinfo.num_bufs_used = 0;
        return (descr);
 }
index f5ddf07..be456cc 100644 (file)
@@ -25,7 +25,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/pc98/pc98/canbus.c,v 1.3.2.1 2003/02/10 13:11:51 nyan Exp $
- * $DragonFly: src/sys/bus/canbus/Attic/canbus.c,v 1.3 2003/08/07 21:16:45 dillon Exp $
+ * $DragonFly: src/sys/bus/canbus/Attic/canbus.c,v 1.4 2004/03/12 03:23:53 dillon Exp $
  */
 
 #include <sys/param.h>
@@ -245,9 +245,7 @@ canbus_add_child(device_t bus, int order, const char *name, int unit)
        child = device_add_child_ordered(bus, order, name, unit);
 
        cbdev = malloc(
-           sizeof(struct canbus_device), M_CANBUSDEV, M_NOWAIT | M_ZERO);
-       if (!cbdev)
-               return (0);
+           sizeof(struct canbus_device), M_CANBUSDEV, M_INTWAIT | M_ZERO);
 
        resource_list_init(&cbdev->cbdev_resources);
        device_set_ivars(child, cbdev);
index 85a23f7..8dac366 100644 (file)
@@ -29,7 +29,7 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/eisa/eisaconf.c,v 1.55 2000/01/14 07:13:57 peter Exp $
- * $DragonFly: src/sys/bus/eisa/eisaconf.c,v 1.3 2003/08/07 21:16:45 dillon Exp $
+ * $DragonFly: src/sys/bus/eisa/eisaconf.c,v 1.4 2004/03/12 03:24:43 dillon Exp $
  */
 
 #include "opt_eisa.h"
@@ -105,11 +105,8 @@ mainboard_probe(device_t dev)
        if (eisa_get_slot(dev) != 0)
                return (ENXIO);
 
-       idstring = (char *)malloc(8 + sizeof(" (System Board)") + 1,
-                                 M_DEVBUF, M_NOWAIT);
-       if (idstring == NULL) {
-               panic("Eisa probe unable to malloc");
-       }
+       idstring = malloc(8 + sizeof(" (System Board)") + 1,
+                           M_DEVBUF, M_INTWAIT);
        sprintf(idstring, "%c%c%c%03x%01x (System Board)",
                EISA_MFCTR_CHAR0(id),
                EISA_MFCTR_CHAR1(id),
@@ -173,16 +170,9 @@ eisa_probe(device_t dev)
                devices_found++;
 
                /* Prepare an eisa_device_node for this slot */
-               e_dev = (struct eisa_device *)malloc(sizeof(*e_dev),
-                                                    M_DEVBUF, M_NOWAIT);
-               if (!e_dev) {
-                       device_printf(dev, "cannot malloc eisa_device");
-                       break; /* Try to attach what we have already */
-               }
-               bzero(e_dev, sizeof(*e_dev));
+               e_dev = malloc(sizeof(*e_dev), M_DEVBUF, M_INTWAIT | M_ZERO);
 
                e_dev->id = eisa_id;
-
                e_dev->ioconf.slot = slot; 
 
                /* Initialize our lists of reserved addresses */
@@ -514,11 +504,7 @@ eisa_add_intr(device_t dev, int irq, int trigger)
        struct eisa_device *e_dev = device_get_ivars(dev);
        struct irq_node *irq_info;
  
-       irq_info = (struct irq_node *)malloc(sizeof(*irq_info), M_DEVBUF,
-                                            M_NOWAIT);
-       if (irq_info == NULL)
-               return (1);
-
+       irq_info = malloc(sizeof(*irq_info), M_DEVBUF, M_INTWAIT);
        irq_info->irq_no = irq;
        irq_info->irq_trigger = trigger;
        irq_info->idesc = NULL;
@@ -532,11 +518,7 @@ eisa_add_resvaddr(struct eisa_device *e_dev, struct resvlist *head, u_long base,
 {
        resvaddr_t *reservation;
 
-       reservation = (resvaddr_t *)malloc(sizeof(resvaddr_t),
-                                          M_DEVBUF, M_NOWAIT);
-       if(!reservation)
-               return (ENOMEM);
-
+       reservation = malloc(sizeof(resvaddr_t), M_DEVBUF, M_INTWAIT);
        reservation->addr = base;
        reservation->size = size;
        reservation->flags = flags;