Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Nov 2016 20:23:19 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r308352 - stable/11/sys/cam
Message-ID:  <201611052023.uA5KNJTP072395@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Sat Nov  5 20:23:18 2016
New Revision: 308352
URL: https://svnweb.freebsd.org/changeset/base/308352

Log:
  MFC r306710:
  CAM ccbq sanity: checks on insert and remove

Modified:
  stable/11/sys/cam/cam_queue.c
  stable/11/sys/cam/cam_queue.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/cam/cam_queue.c
==============================================================================
--- stable/11/sys/cam/cam_queue.c	Sat Nov  5 20:22:12 2016	(r308351)
+++ stable/11/sys/cam/cam_queue.c	Sat Nov  5 20:23:18 2016	(r308352)
@@ -176,8 +176,11 @@ camq_remove(struct camq *queue, int inde
 {
 	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];

Modified: stable/11/sys/cam/cam_queue.h
==============================================================================
--- stable/11/sys/cam/cam_queue.h	Sat Nov  5 20:22:12 2016	(r308351)
+++ stable/11/sys/cam/cam_queue.h	Sat Nov  5 20:23:18 2016	(r308352)
@@ -197,6 +197,11 @@ cam_ccbq_insert_ccb(struct cam_ccbq *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 *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 *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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201611052023.uA5KNJTP072395>