summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortruckman <truckman@FreeBSD.org>2016-07-06 17:45:38 +0000
committertruckman <truckman@FreeBSD.org>2016-07-06 17:45:38 +0000
commit4199bec9b4f66720daa3225f22555919a48e7182 (patch)
treeb8508db7b6ec491d1307c6f0630f0e57962c6183
parent15fb55aa670314e87deb319e02abdf4bcbac078b (diff)
downloadFreeBSD-src-4199bec9b4f66720daa3225f22555919a48e7182.zip
FreeBSD-src-4199bec9b4f66720daa3225f22555919a48e7182.tar.gz
MFC r300547
Fix multiple Coverity Out-of-bounds access false postive issues in CAM The currently used idiom for clearing the part of a ccb after its header generates one or two Coverity errors for each time it is used. All instances generate an Out-of-bounds access (ARRAY_VS_SINGLETON) error because of the treatment of the header as a two element array, with a pointer to the non-existent second element being passed as the starting address to bzero(). Some instances also alsp generate Out-of-bounds access (OVERRUN) errors, probably because the space being cleared is larger than the sizeofstruct ccb_hdr). In addition, this idiom is difficult for humans to understand and it is error prone. The user has to chose the proper struct ccb_* type (which does not appear in the surrounding code) for the sizeof() in the length calculation. I found several instances where the length was incorrect, which could cause either an actual out of bounds write, or incompletely clear the ccb. A better way is to write the code to clear the ccb itself starting at sizeof(ccb_hdr) bytes from the start of the ccb, and calculate the length based on the specific type of struct ccb_* being cleared as specified by the union ccb member being used. The latter can normally be seen in the nearby code. This is friendlier for Coverity and other static analysis tools because they will see that the intent is to clear the trailing part of the ccb. Wrap all of the boilerplate code in a convenient macro that only requires a pointer to the desired union ccb member (or a pointer to the union ccb itself) as an argument. Reported by: Coverity CID: 1007578, 1008684, 1009724, 1009773, 1011304, 1011306 CID: 1011307, 1011308, 1011309, 1011310, 1011311, 1011312 CID: 1011313, 1011314, 1011315, 1011316, 1011317, 1011318 CID: 1011319, 1011320, 1011321, 1011322, 1011324, 1011325 CID: 1011326, 1011327, 1011328, 1011329, 1011330, 1011374 CID: 1011390, 1011391, 1011392, 1011393, 1011394, 1011395 CID: 1011396, 1011397, 1011398, 1011399, 1011400, 1011401 CID: 1011402, 1011403, 1011404, 1011405, 1011406, 1011408 CID: 1011409, 1011410, 1011411, 1011412, 1011413, 1011414 CID: 1017461, 1018387, 1086860, 1086874, 1194257, 1229897 CID: 1229968, 1306229, 1306234, 1331282, 1331283, 1331294 CID: 1331295, 1331535, 1331536, 1331539, 1331540, 1341623 CID: 1341624, 1341637, 1341638, 1355264, 1355324 Reviewed by: scottl, ken, delphij, imp MFH: 1 month Differential Revision: https://reviews.freebsd.org/D6496
-rw-r--r--lib/libcam/camlib.c2
-rw-r--r--sbin/camcontrol/attrib.c3
-rw-r--r--sbin/camcontrol/camcontrol.c105
-rw-r--r--sbin/camcontrol/fwdownload.c12
-rw-r--r--sbin/camcontrol/persist.c3
-rw-r--r--sbin/iscontrol/fsm.c2
-rw-r--r--sys/cam/cam_ccb.h4
-rw-r--r--usr.sbin/camdd/camdd.c9
-rw-r--r--usr.sbin/mptutil/mpt_cam.c9
9 files changed, 53 insertions, 96 deletions
diff --git a/lib/libcam/camlib.c b/lib/libcam/camlib.c
index 8986230..7aac240 100644
--- a/lib/libcam/camlib.c
+++ b/lib/libcam/camlib.c
@@ -619,7 +619,7 @@ cam_real_open_device(const char *path, int flags, struct cam_device *device,
/*
* Zero the payload, the kernel does look at the flags.
*/
- bzero(&(&ccb.ccb_h)[1], sizeof(struct ccb_trans_settings));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb.cts);
/*
* Get transfer settings for this device.
diff --git a/sbin/camcontrol/attrib.c b/sbin/camcontrol/attrib.c
index 62d4b1e..7ff2c42 100644
--- a/sbin/camcontrol/attrib.c
+++ b/sbin/camcontrol/attrib.c
@@ -137,8 +137,7 @@ scsiattrib(struct cam_device *device, int argc, char **argv, char *combinedopt,
goto bailout;
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(union ccb) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
STAILQ_INIT(&write_attr_list);
diff --git a/sbin/camcontrol/camcontrol.c b/sbin/camcontrol/camcontrol.c
index 91d849f..440480f 100644
--- a/sbin/camcontrol/camcontrol.c
+++ b/sbin/camcontrol/camcontrol.c
@@ -838,8 +838,7 @@ scsiinquiry(struct cam_device *device, int retry_count, int timeout)
}
/* cam_getccb cleans up the header, caller has to zero the payload */
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
inq_buf = (struct scsi_inquiry_data *)malloc(
sizeof(struct scsi_inquiry_data));
@@ -954,8 +953,7 @@ scsiserial(struct cam_device *device, int retry_count, int timeout)
}
/* cam_getccb cleans up the header, caller has to zero the payload */
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
serial_buf = (struct scsi_vpd_unit_serial_number *)
malloc(sizeof(*serial_buf));
@@ -1047,8 +1045,7 @@ camxferrate(struct cam_device *device)
return(1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_trans_settings) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cts);
ccb->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
ccb->cts.type = CTS_TYPE_CURRENT_SETTINGS;
@@ -1601,8 +1598,7 @@ ata_do_pass_16(struct cam_device *device, union ccb *ccb, int retries,
ata_flags |= AP_FLAG_TLEN_NO_DATA;
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
scsi_ata_pass_16(&ccb->csio,
retries,
@@ -1663,8 +1659,7 @@ ata_do_28bit_cmd(struct cam_device *device, union ccb *ccb, int retries,
timeout, quiet);
}
- bzero(&(&ccb->ccb_h)[1], sizeof(struct ccb_ataio) -
- sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->ataio);
cam_fill_ataio(&ccb->ataio,
retries,
NULL,
@@ -1733,8 +1728,7 @@ ata_do_cmd(struct cam_device *device, union ccb *ccb, int retries,
return (error);
}
- bzero(&(&ccb->ccb_h)[1], sizeof(struct ccb_ataio) -
- sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->ataio);
cam_fill_ataio(&ccb->ataio,
retries,
NULL,
@@ -3184,8 +3178,7 @@ rescan_or_reset_bus(path_id_t bus, int rescan)
* no-op, sending a rescan to the xpt bus would result in a status of
* CAM_REQ_INVALID.
*/
- bzero(&(&matchccb.ccb_h)[1],
- sizeof(struct ccb_dev_match) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&matchccb.cdm);
matchccb.ccb_h.func_code = XPT_DEV_MATCH;
matchccb.ccb_h.path_id = CAM_BUS_WILDCARD;
bufsize = sizeof(struct dev_match_result) * 20;
@@ -3533,8 +3526,7 @@ next_batch:
* cam_getccb() zeros the CCB header only. So we need to zero the
* payload portion of the ccb.
*/
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
scsi_read_defects(&ccb->csio,
/*retries*/ retry_count,
@@ -3987,8 +3979,7 @@ mode_sense(struct cam_device *device, int mode_page, int page_control,
if (ccb == NULL)
errx(1, "mode_sense: couldn't allocate CCB");
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
scsi_mode_sense(&ccb->csio,
/* retries */ retry_count,
@@ -4037,8 +4028,7 @@ mode_select(struct cam_device *device, int save_pages, int retry_count,
if (ccb == NULL)
errx(1, "mode_select: couldn't allocate CCB");
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
scsi_mode_select(&ccb->csio,
/* retries */ retry_count,
@@ -4155,8 +4145,7 @@ scsicmd(struct cam_device *device, int argc, char **argv, char *combinedopt,
return(1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(union ccb) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(ccb);
while ((c = getopt(argc, argv, combinedopt)) != -1) {
switch(c) {
@@ -4657,8 +4646,7 @@ tagcontrol(struct cam_device *device, int argc, char **argv,
cam_path_string(device, pathstr, sizeof(pathstr));
if (numtags >= 0) {
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_relsim) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->crs);
ccb->ccb_h.func_code = XPT_REL_SIMQ;
ccb->ccb_h.flags = CAM_DEV_QFREEZE;
ccb->crs.release_flags = RELSIM_ADJUST_OPENINGS;
@@ -4685,8 +4673,7 @@ tagcontrol(struct cam_device *device, int argc, char **argv,
pathstr, ccb->crs.openings);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_getdevstats) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cgds);
ccb->ccb_h.func_code = XPT_GDEV_STATS;
@@ -4886,8 +4873,7 @@ get_cpi(struct cam_device *device, struct ccb_pathinq *cpi)
warnx("get_cpi: couldn't allocate CCB");
return(1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_pathinq) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cpi);
ccb->ccb_h.func_code = XPT_PATH_INQ;
if (cam_send_ccb(device, ccb) < 0) {
warn("get_cpi: error sending Path Inquiry CCB");
@@ -4925,8 +4911,7 @@ get_cgd(struct cam_device *device, struct ccb_getdev *cgd)
warnx("get_cgd: couldn't allocate CCB");
return(1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_pathinq) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cgd);
ccb->ccb_h.func_code = XPT_GDEV_TYPE;
if (cam_send_ccb(device, ccb) < 0) {
warn("get_cgd: error sending Path Inquiry CCB");
@@ -4971,8 +4956,7 @@ dev_has_vpd_page(struct cam_device *dev, uint8_t page_id, int retry_count,
}
/* cam_getccb cleans up the header, caller has to zero the payload */
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
bzero(&sup_pages, sizeof(sup_pages));
@@ -5286,8 +5270,7 @@ get_print_cts(struct cam_device *device, int user_settings, int quiet,
return(1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_trans_settings) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cts);
ccb->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
@@ -5427,8 +5410,7 @@ ratecontrol(struct cam_device *device, int retry_count, int timeout,
break;
}
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_pathinq) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cpi);
/*
* Grab path inquiry information, so we can determine whether
* or not the initiator is capable of the things that the user
@@ -5454,8 +5436,7 @@ ratecontrol(struct cam_device *device, int retry_count, int timeout,
goto ratecontrol_bailout;
}
bcopy(&ccb->cpi, &cpi, sizeof(struct ccb_pathinq));
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_trans_settings) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cts);
if (quiet == 0) {
fprintf(stdout, "%s parameters:\n",
user_settings ? "User" : "Current");
@@ -5708,8 +5689,7 @@ scsiformat(struct cam_device *device, int argc, char **argv,
return(1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
while ((c = getopt(argc, argv, combinedopt)) != -1) {
switch(c) {
@@ -5857,8 +5837,7 @@ doreport:
do {
cam_status status;
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
/*
* There's really no need to do error recovery or
@@ -6005,8 +5984,7 @@ scsisanitize(struct cam_device *device, int argc, char **argv,
return(1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
while ((c = getopt(argc, argv, combinedopt)) != -1) {
switch(c) {
@@ -6267,8 +6245,7 @@ doreport:
do {
cam_status status;
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
/*
* There's really no need to do error recovery or
@@ -6410,8 +6387,7 @@ scsireportluns(struct cam_device *device, int argc, char **argv,
return (1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
countonly = 0;
lunsonly = 0;
@@ -6659,8 +6635,7 @@ scsireadcapacity(struct cam_device *device, int argc, char **argv,
return (1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
while ((c = getopt(argc, argv, combinedopt)) != -1) {
switch (c) {
@@ -6864,8 +6839,7 @@ smpcmd(struct cam_device *device, int argc, char **argv, char *combinedopt,
return (1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(union ccb) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->smpio);
while ((c = getopt(argc, argv, combinedopt)) != -1) {
switch (c) {
@@ -7058,8 +7032,7 @@ smpreportgeneral(struct cam_device *device, int argc, char **argv,
return (1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(union ccb) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->smpio);
while ((c = getopt(argc, argv, combinedopt)) != -1) {
switch (c) {
@@ -7121,8 +7094,7 @@ try_long:
if ((response->long_response & SMP_RG_LONG_RESPONSE)
&& (long_response == 0)) {
ccb->ccb_h.status = CAM_REQ_INPROG;
- bzero(&(&ccb->ccb_h)[1],
- sizeof(union ccb) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->smpio);
long_response = 1;
goto try_long;
}
@@ -7204,8 +7176,7 @@ smpphycontrol(struct cam_device *device, int argc, char **argv,
return (1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(union ccb) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->smpio);
while ((c = getopt(argc, argv, combinedopt)) != -1) {
switch (c) {
@@ -7462,8 +7433,7 @@ smpmaninfo(struct cam_device *device, int argc, char **argv,
return (1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(union ccb) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->smpio);
while ((c = getopt(argc, argv, combinedopt)) != -1) {
switch (c) {
@@ -7557,8 +7527,7 @@ getdevid(struct cam_devitem *item)
goto bailout;
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(union ccb) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cdai);
/*
* On the first try, we just probe for the size of the data, and
@@ -7843,8 +7812,7 @@ smpphylist(struct cam_device *device, int argc, char **argv,
return (1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(union ccb) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->smpio);
STAILQ_INIT(&devlist.dev_queue);
rgrequest = malloc(sizeof(*rgrequest));
@@ -7948,8 +7916,7 @@ smpphylist(struct cam_device *device, int argc, char **argv,
char tmpstr[256];
int j;
- bzero(&(&ccb->ccb_h)[1],
- sizeof(union ccb) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->smpio);
ccb->ccb_h.status = CAM_REQ_INPROG;
ccb->ccb_h.flags |= CAM_DEV_QFRZDIS;
@@ -8238,8 +8205,7 @@ scsigetopcodes(struct cam_device *device, int opcode_set, int opcode,
}
/* cam_getccb cleans up the header, caller has to zero the payload */
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
if (opcode_set != 0) {
options |= RSO_OPTIONS_OC;
@@ -8678,8 +8644,7 @@ scsireprobe(struct cam_device *device)
return (1);
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
ccb->ccb_h.func_code = XPT_REPROBE_LUN;
diff --git a/sbin/camcontrol/fwdownload.c b/sbin/camcontrol/fwdownload.c
index 8049606..205cfd3 100644
--- a/sbin/camcontrol/fwdownload.c
+++ b/sbin/camcontrol/fwdownload.c
@@ -459,8 +459,7 @@ fw_validate_ibm(struct cam_device *dev, int retry_count, int timeout, int fd,
}
/* cam_getccb cleans up the header, caller has to zero the payload */
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
bzero(&vpd_page, sizeof(vpd_page));
@@ -666,8 +665,7 @@ fw_check_device_ready(struct cam_device *dev, camcontrol_devtype devtype,
goto bailout;
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(union ccb) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(ccb);
if (devtype != CC_DT_SCSI) {
dxfer_len = sizeof(struct ata_params);
@@ -789,8 +787,7 @@ fw_download_img(struct cam_device *cam_dev, struct fw_vendor *vp,
goto bailout;
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(union ccb) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(ccb);
max_pkt_size = vp->max_pkt_size;
if (max_pkt_size == 0)
@@ -821,8 +818,7 @@ fw_download_img(struct cam_device *cam_dev, struct fw_vendor *vp,
vp->cdb_byte2;
cdb.buffer_id = vp->inc_cdb_buffer_id ? pkt_count : 0;
/* Zero out payload of ccb union after ccb header. */
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
/*
* Copy previously constructed cdb into ccb_scsiio
* struct.
diff --git a/sbin/camcontrol/persist.c b/sbin/camcontrol/persist.c
index bcc1073..089216f 100644
--- a/sbin/camcontrol/persist.c
+++ b/sbin/camcontrol/persist.c
@@ -450,8 +450,7 @@ scsipersist(struct cam_device *device, int argc, char **argv, char *combinedopt,
goto bailout;
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(union ccb) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
while ((c = getopt(argc, argv, combinedopt)) != -1) {
switch (c) {
diff --git a/sbin/iscontrol/fsm.c b/sbin/iscontrol/fsm.c
index a4660bb..de27d36 100644
--- a/sbin/iscontrol/fsm.c
+++ b/sbin/iscontrol/fsm.c
@@ -371,7 +371,7 @@ doCAM(isess_t *sess)
debug(2, "pathstr=%s", pathstr);
ccb = cam_getccb(sess->camdev);
- bzero(&(&ccb->ccb_h)[1], sizeof(struct ccb_relsim) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->crs);
ccb->ccb_h.func_code = XPT_REL_SIMQ;
ccb->crs.release_flags = RELSIM_ADJUST_OPENINGS;
ccb->crs.openings = sess->op->tags;
diff --git a/sys/cam/cam_ccb.h b/sys/cam/cam_ccb.h
index c350526..251d62d 100644
--- a/sys/cam/cam_ccb.h
+++ b/sys/cam/cam_ccb.h
@@ -1217,6 +1217,10 @@ union ccb {
struct ccb_async casync;
};
+#define CCB_CLEAR_ALL_EXCEPT_HDR(ccbp) \
+ bzero((char *)(ccbp) + sizeof((ccbp)->ccb_h), \
+ sizeof(*(ccbp)) - sizeof((ccbp)->ccb_h))
+
__BEGIN_DECLS
static __inline void
cam_fill_csio(struct ccb_scsiio *csio, u_int32_t retries,
diff --git a/usr.sbin/camdd/camdd.c b/usr.sbin/camdd/camdd.c
index 095affd..4e76ff0 100644
--- a/usr.sbin/camdd/camdd.c
+++ b/usr.sbin/camdd/camdd.c
@@ -1305,8 +1305,7 @@ camdd_probe_pass(struct cam_device *cam_dev, struct camdd_io_opts *io_opts,
goto bailout;
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
scsi_read_capacity(&ccb->csio,
/*retries*/ probe_retry_count,
@@ -1387,8 +1386,7 @@ rcap_done:
goto bailout_error;
}
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->cpi);
ccb->ccb_h.func_code = XPT_PATH_INQ;
ccb->ccb_h.flags = CAM_DIR_NONE;
@@ -2439,8 +2437,7 @@ camdd_pass_run(struct camdd_dev *dev)
data = &buf->buf_type_spec.data;
ccb = &data->ccb;
- bzero(&(&ccb->ccb_h)[1],
- sizeof(struct ccb_scsiio) - sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
/*
* In almost every case the number of blocks should be the device
diff --git a/usr.sbin/mptutil/mpt_cam.c b/usr.sbin/mptutil/mpt_cam.c
index a00e228..264cb47 100644
--- a/usr.sbin/mptutil/mpt_cam.c
+++ b/usr.sbin/mptutil/mpt_cam.c
@@ -241,8 +241,7 @@ fetch_scsi_capacity(struct cam_device *dev, struct mpt_standalone_disk *disk)
return (ENOMEM);
/* Zero the rest of the ccb. */
- bzero(&(&ccb->ccb_h)[1], sizeof(struct ccb_scsiio) -
- sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
scsi_read_capacity(&ccb->csio, 1, NULL, MSG_SIMPLE_Q_TAG, &rcap,
SSD_FULL_SIZE, 5000);
@@ -273,8 +272,7 @@ fetch_scsi_capacity(struct cam_device *dev, struct mpt_standalone_disk *disk)
}
/* Zero the rest of the ccb. */
- bzero(&(&ccb->ccb_h)[1], sizeof(struct ccb_scsiio) -
- sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
scsi_read_capacity_16(&ccb->csio, 1, NULL, MSG_SIMPLE_Q_TAG, 0, 0, 0,
(uint8_t *)&rcaplong, sizeof(rcaplong), SSD_FULL_SIZE, 5000);
@@ -355,8 +353,7 @@ fetch_scsi_inquiry(struct cam_device *dev, struct mpt_standalone_disk *disk)
return (ENOMEM);
/* Zero the rest of the ccb. */
- bzero(&(&ccb->ccb_h)[1], sizeof(struct ccb_scsiio) -
- sizeof(struct ccb_hdr));
+ CCB_CLEAR_ALL_EXCEPT_HDR(&ccb->csio);
inq_buf = calloc(1, sizeof(*inq_buf));
if (inq_buf == NULL) {
OpenPOWER on IntegriCloud