Author: mav
Date: Tue Oct 23 15:25:19 2012
New Revision: 241941
URL: http://svn.freebsd.org/changeset/base/241941

Log:
  MFC r241456:
  Use separate malloc buckets for CAM devices, CCBs and paths. This will
  make it easier to track down the source of any use after free problems.

Modified:
  stable/9/sys/cam/cam_xpt.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/cam/cam_xpt.c
==============================================================================
--- stable/9/sys/cam/cam_xpt.c  Tue Oct 23 15:22:11 2012        (r241940)
+++ stable/9/sys/cam/cam_xpt.c  Tue Oct 23 15:25:19 2012        (r241941)
@@ -78,6 +78,9 @@ __FBSDID("$FreeBSD$");
 
 /* Datastructures internal to the xpt layer */
 MALLOC_DEFINE(M_CAMXPT, "CAM XPT", "CAM XPT buffers");
+MALLOC_DEFINE(M_CAMDEV, "CAM DEV", "CAM devices");
+MALLOC_DEFINE(M_CAMCCB, "CAM CCB", "CAM CCBs");
+MALLOC_DEFINE(M_CAMPATH, "CAM path", "CAM paths");
 
 /* Object for defering XPT actions to a taskqueue */
 struct xpt_task {
@@ -3397,7 +3400,7 @@ xpt_create_path(struct cam_path **new_pa
        struct     cam_path *path;
        cam_status status;
 
-       path = (struct cam_path *)malloc(sizeof(*path), M_CAMXPT, M_NOWAIT);
+       path = (struct cam_path *)malloc(sizeof(*path), M_CAMPATH, M_NOWAIT);
 
        if (path == NULL) {
                status = CAM_RESRC_UNAVAIL;
@@ -3405,7 +3408,7 @@ xpt_create_path(struct cam_path **new_pa
        }
        status = xpt_compile_path(path, perph, path_id, target_id, lun_id);
        if (status != CAM_REQ_CMP) {
-               free(path, M_CAMXPT);
+               free(path, M_CAMPATH);
                path = NULL;
        }
        *new_path_ptr = path;
@@ -3422,7 +3425,7 @@ xpt_create_path_unlocked(struct cam_path
        cam_status status;
        int        need_unlock = 0;
 
-       path = (struct cam_path *)malloc(sizeof(*path), M_CAMXPT, M_WAITOK);
+       path = (struct cam_path *)malloc(sizeof(*path), M_CAMPATH, M_WAITOK);
 
        if (path_id != CAM_BUS_WILDCARD) {
                bus = xpt_find_bus(path_id);
@@ -3437,7 +3440,7 @@ xpt_create_path_unlocked(struct cam_path
                xpt_release_bus(bus);
        }
        if (status != CAM_REQ_CMP) {
-               free(path, M_CAMXPT);
+               free(path, M_CAMPATH);
                path = NULL;
        }
        *new_path_ptr = path;
@@ -3540,7 +3543,7 @@ xpt_free_path(struct cam_path *path)
 
        CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_free_path\n"));
        xpt_release_path(path);
-       free(path, M_CAMXPT);
+       free(path, M_CAMPATH);
 }
 
 void
@@ -4376,7 +4379,7 @@ xpt_alloc_ccb()
 {
        union ccb *new_ccb;
 
-       new_ccb = malloc(sizeof(*new_ccb), M_CAMXPT, M_ZERO|M_WAITOK);
+       new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_WAITOK);
        return (new_ccb);
 }
 
@@ -4385,14 +4388,14 @@ xpt_alloc_ccb_nowait()
 {
        union ccb *new_ccb;
 
-       new_ccb = malloc(sizeof(*new_ccb), M_CAMXPT, M_ZERO|M_NOWAIT);
+       new_ccb = malloc(sizeof(*new_ccb), M_CAMCCB, M_ZERO|M_NOWAIT);
        return (new_ccb);
 }
 
 void
 xpt_free_ccb(union ccb *free_ccb)
 {
-       free(free_ccb, M_CAMXPT);
+       free(free_ccb, M_CAMCCB);
 }
 
 
@@ -4544,7 +4547,7 @@ xpt_alloc_device(struct cam_eb *bus, str
                device = NULL;
        } else {
                device = (struct cam_ed *)malloc(sizeof(*device),
-                                                M_CAMXPT, M_NOWAIT|M_ZERO);
+                                                M_CAMDEV, M_NOWAIT|M_ZERO);
        }
 
        if (device != NULL) {
@@ -4557,13 +4560,13 @@ xpt_alloc_device(struct cam_eb *bus, str
                device->sim = bus->sim;
                /* Initialize our queues */
                if (camq_init(&device->drvq, 0) != 0) {
-                       free(device, M_CAMXPT);
+                       free(device, M_CAMDEV);
                        return (NULL);
                }
                if (cam_ccbq_init(&device->ccbq,
                                  bus->sim->max_dev_openings) != 0) {
                        camq_fini(&device->drvq);
-                       free(device, M_CAMXPT);
+                       free(device, M_CAMDEV);
                        return (NULL);
                }
                SLIST_INIT(&device->asyncs);
@@ -4616,7 +4619,7 @@ xpt_release_device(struct cam_ed *device
                camq_fini(&device->drvq);
                cam_ccbq_fini(&device->ccbq);
                xpt_release_target(device->target);
-               free(device, M_CAMXPT);
+               free(device, M_CAMDEV);
        } else
                device->refcount--;
 }
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-stable-9
To unsubscribe, send any mail to "[email protected]"

Reply via email to