summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormarkj <markj@FreeBSD.org>2016-11-05 20:23:18 +0000
committermarkj <markj@FreeBSD.org>2016-11-05 20:23:18 +0000
commit749516a2fdd51c6614bc663e4c154b41f5234e00 (patch)
tree333dbd48cb4fbb0ace572be5a003fa28da8afba1
parent6fd3dc36f273bab3ad80c02d4e2ebe2665262b3e (diff)
downloadFreeBSD-src-749516a2fdd51c6614bc663e4c154b41f5234e00.zip
FreeBSD-src-749516a2fdd51c6614bc663e4c154b41f5234e00.tar.gz
MFC r306710:
CAM ccbq sanity: checks on insert and remove
-rw-r--r--sys/cam/cam_queue.c7
-rw-r--r--sys/cam/cam_queue.h11
2 files changed, 15 insertions, 3 deletions
diff --git a/sys/cam/cam_queue.c b/sys/cam/cam_queue.c
index 3959c3d..059dd63 100644
--- a/sys/cam/cam_queue.c
+++ b/sys/cam/cam_queue.c
@@ -176,8 +176,11 @@ camq_remove(struct camq *queue, int index)
{
cam_pinfo *removed_entry;
- if (index == 0 || index > queue->entries)
- return (NULL);
+ if (index <= 0 || index > queue->entries)
+ panic("%s: Attempt to remove out-of-bounds index %d "
+ "from queue %p of size %d", __func__, index, queue,
+ queue->entries);
+
removed_entry = queue->queue_array[index];
if (queue->entries != index) {
queue->queue_array[index] = queue->queue_array[queue->entries];
diff --git a/sys/cam/cam_queue.h b/sys/cam/cam_queue.h
index 33f6b1d..b15998b 100644
--- a/sys/cam/cam_queue.h
+++ b/sys/cam/cam_queue.h
@@ -197,6 +197,11 @@ cam_ccbq_insert_ccb(struct cam_ccbq *ccbq, union ccb *new_ccb)
struct ccb_hdr *old_ccb;
struct camq *queue = &ccbq->queue;
+ KASSERT((new_ccb->ccb_h.func_code & XPT_FC_QUEUED) != 0 &&
+ (new_ccb->ccb_h.func_code & XPT_FC_USER_CCB) == 0,
+ ("%s: Cannot queue ccb %p func_code %#x", __func__, new_ccb,
+ new_ccb->ccb_h.func_code));
+
/*
* If queue is already full, try to resize.
* If resize fail, push CCB with lowest priority out to the TAILQ.
@@ -218,6 +223,7 @@ cam_ccbq_remove_ccb(struct cam_ccbq *ccbq, union ccb *ccb)
{
struct ccb_hdr *cccb, *bccb;
struct camq *queue = &ccbq->queue;
+ cam_pinfo *removed_entry __unused;
/* If the CCB is on the TAILQ, remove it from there. */
if (ccb->ccb_h.pinfo.index == CAM_EXTRAQ_INDEX) {
@@ -228,7 +234,10 @@ cam_ccbq_remove_ccb(struct cam_ccbq *ccbq, union ccb *ccb)
return;
}
- camq_remove(queue, ccb->ccb_h.pinfo.index);
+ removed_entry = camq_remove(queue, ccb->ccb_h.pinfo.index);
+ KASSERT(removed_entry == &ccb->ccb_h.pinfo,
+ ("%s: Removed wrong entry from queue (%p != %p)", __func__,
+ removed_entry, &ccb->ccb_h.pinfo));
/*
* If there are some CCBs on TAILQ, find the best one and move it
OpenPOWER on IntegriCloud