[Midnightbsd-cvs] src [8751] trunk/sys/cam/ctl: Use M_ZERO instead of memset/bzero

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Sep 25 22:36:09 EDT 2016


Revision: 8751
          http://svnweb.midnightbsd.org/src/?rev=8751
Author:   laffer1
Date:     2016-09-25 22:36:09 -0400 (Sun, 25 Sep 2016)
Log Message:
-----------
Use M_ZERO instead of memset/bzero

Modified Paths:
--------------
    trunk/sys/cam/ctl/ctl.c
    trunk/sys/cam/ctl/ctl_backend_block.c

Modified: trunk/sys/cam/ctl/ctl.c
===================================================================
--- trunk/sys/cam/ctl/ctl.c	2016-09-26 02:35:36 UTC (rev 8750)
+++ trunk/sys/cam/ctl/ctl.c	2016-09-26 02:36:09 UTC (rev 8751)
@@ -957,11 +957,10 @@
 	if (ctl_disable != 0)
 		return;
 
-	control_softc = malloc(sizeof(*control_softc), M_DEVBUF, M_WAITOK);
+	control_softc = malloc(sizeof(*control_softc), M_DEVBUF,
+			       M_WAITOK | M_ZERO);
 	softc = control_softc;
 
-	memset(softc, 0, sizeof(*softc));
-
 	softc->dev = make_dev(&ctl_cdevsw, 0, UID_ROOT, GID_OPERATOR, 0600,
 			      "cam/ctl");
 
@@ -3271,14 +3270,13 @@
 
 	retval = 0;
 
-	pool = (struct ctl_io_pool *)malloc(sizeof(*pool), M_CTL, M_NOWAIT);
+	pool = (struct ctl_io_pool *)malloc(sizeof(*pool), M_CTL,
+					    M_NOWAIT | M_ZERO);
 	if (pool == NULL) {
 		retval = -ENOMEM;
 		goto bailout;
 	}
 
-	memset(pool, 0, sizeof(*pool));
-
 	pool->type = pool_type;
 	pool->ctl_softc = ctl_softc;
 
@@ -6561,7 +6559,7 @@
 	       header_len, page_len, total_len);
 #endif
 
-	ctsio->kern_data_ptr = malloc(total_len, M_CTL, M_WAITOK);
+	ctsio->kern_data_ptr = malloc(total_len, M_CTL, M_WAITOK | M_ZERO);
 	ctsio->kern_sg_entries = 0;
 	ctsio->kern_data_resid = 0;
 	ctsio->kern_rel_offset = 0;
@@ -6574,7 +6572,6 @@
 		ctsio->kern_data_len = alloc_len;
 		ctsio->kern_total_len = alloc_len;
 	}
-	memset(ctsio->kern_data_ptr, 0, total_len);
 
 	switch (ctsio->cdb[0]) {
 	case MODE_SENSE_6: {
@@ -6742,7 +6739,7 @@
 
 	lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
 
-	ctsio->kern_data_ptr = malloc(sizeof(*data), M_CTL, M_WAITOK);
+	ctsio->kern_data_ptr = malloc(sizeof(*data), M_CTL, M_WAITOK | M_ZERO);
 	data = (struct scsi_read_capacity_data *)ctsio->kern_data_ptr;
 	ctsio->residual = 0;
 	ctsio->kern_data_len = sizeof(*data);
@@ -6751,8 +6748,6 @@
 	ctsio->kern_rel_offset = 0;
 	ctsio->kern_sg_entries = 0;
 
-	memset(data, 0, sizeof(*data));
-
 	/*
 	 * If the maximum LBA is greater than 0xfffffffe, the user must
 	 * issue a SERVICE ACTION IN (16) command, with the read capacity
@@ -6806,7 +6801,7 @@
 
 	lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
 
-	ctsio->kern_data_ptr = malloc(sizeof(*data), M_CTL, M_WAITOK);
+	ctsio->kern_data_ptr = malloc(sizeof(*data), M_CTL, M_WAITOK | M_ZERO);
 	data = (struct scsi_read_capacity_data_long *)ctsio->kern_data_ptr;
 
 	if (sizeof(*data) < alloc_len) {
@@ -6822,8 +6817,6 @@
 	ctsio->kern_rel_offset = 0;
 	ctsio->kern_sg_entries = 0;
 
-	memset(data, 0, sizeof(*data));
-
 	scsi_u64to8b(lun->be_lun->maxlba, data->addr);
 	/* XXX KDM this may not be 512 bytes... */
 	scsi_ulto4b(lun->be_lun->blocksize, data->length);
@@ -6913,8 +6906,7 @@
 
 	alloc_len = scsi_4btoul(cdb->length);
 
-	ctsio->kern_data_ptr = malloc(total_len, M_CTL, M_WAITOK);
-	memset(ctsio->kern_data_ptr, 0, total_len);
+	ctsio->kern_data_ptr = malloc(total_len, M_CTL, M_WAITOK | M_ZERO);
 
 	ctsio->kern_sg_entries = 0;
 
@@ -7068,7 +7060,7 @@
 	}
 	mtx_unlock(&softc->ctl_lock);
 
-	ctsio->kern_data_ptr = malloc(total_len, M_CTL, M_WAITOK);
+	ctsio->kern_data_ptr = malloc(total_len, M_CTL, M_WAITOK | M_ZERO);
 
 	if (total_len < alloc_len) {
 		ctsio->residual = alloc_len - total_len;
@@ -7084,8 +7076,6 @@
 	ctsio->kern_rel_offset = 0;
 	ctsio->kern_sg_entries = 0;
 
-	memset(ctsio->kern_data_ptr, 0, total_len);
-
 	mtx_lock(&softc->ctl_lock);
 	switch (cdb->action) {
 	case SPRI_RK: { // read keys
@@ -8611,7 +8601,7 @@
 	lun_datalen = sizeof(*lun_data) +
 		(num_luns * sizeof(struct scsi_report_luns_lundata));
 
-	ctsio->kern_data_ptr = malloc(lun_datalen, M_CTL, M_WAITOK);
+	ctsio->kern_data_ptr = malloc(lun_datalen, M_CTL, M_WAITOK | M_ZERO);
 	lun_data = (struct scsi_report_luns_data *)ctsio->kern_data_ptr;
 	ctsio->kern_sg_entries = 0;
 
@@ -8630,8 +8620,6 @@
 
 	initidx = ctl_get_initindex(&ctsio->io_hdr.nexus);
 
-	memset(lun_data, 0, lun_datalen);
-
 	/*
 	 * We set this to the actual data length, regardless of how much
 	 * space we actually have to return results.  If the user looks at
@@ -8907,7 +8895,7 @@
 	 * XXX KDM GFP_???  We probably don't want to wait here,
 	 * unless we end up having a process/thread context.
 	 */
-	ctsio->kern_data_ptr = malloc(sup_page_size, M_CTL, M_WAITOK);
+	ctsio->kern_data_ptr = malloc(sup_page_size, M_CTL, M_WAITOK | M_ZERO);
 	if (ctsio->kern_data_ptr == NULL) {
 		ctsio->io_hdr.status = CTL_SCSI_ERROR;
 		ctsio->scsi_status = SCSI_STATUS_BUSY;
@@ -8930,8 +8918,6 @@
 	ctsio->kern_rel_offset = 0;
 	ctsio->kern_sg_entries = 0;
 
-	memset(pages, 0, sup_page_size);
-
 	/*
 	 * The control device is always connected.  The disk device, on the
 	 * other hand, may not be online all the time.  Need to change this
@@ -8971,7 +8957,7 @@
 	lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr;
 
 	/* XXX KDM which malloc flags here?? */
-	ctsio->kern_data_ptr = malloc(sizeof(*sn_ptr), M_CTL, M_WAITOK);
+	ctsio->kern_data_ptr = malloc(sizeof(*sn_ptr), M_CTL, M_WAITOK | M_ZERO);
 	if (ctsio->kern_data_ptr == NULL) {
 		ctsio->io_hdr.status = CTL_SCSI_ERROR;
 		ctsio->scsi_status = SCSI_STATUS_BUSY;
@@ -8994,8 +8980,6 @@
 	ctsio->kern_rel_offset = 0;
 	ctsio->kern_sg_entries = 0;
 
-	memset(sn_ptr, 0, sizeof(*sn_ptr));
-
 	/*
 	 * The control device is always connected.  The disk device, on the
 	 * other hand, may not be online all the time.  Need to change this
@@ -9065,7 +9049,7 @@
 		sizeof(struct scsi_vpd_id_trgt_port_grp_id);
 
 	/* XXX KDM which malloc flags here ?? */
-	ctsio->kern_data_ptr = malloc(devid_len, M_CTL, M_WAITOK);
+	ctsio->kern_data_ptr = malloc(devid_len, M_CTL, M_WAITOK | M_ZERO);
 	if (ctsio->kern_data_ptr == NULL) {
 		ctsio->io_hdr.status = CTL_SCSI_ERROR;
 		ctsio->scsi_status = SCSI_STATUS_BUSY;
@@ -9096,7 +9080,6 @@
 	          CTL_WWPN_LEN);
 	desc3 = (struct scsi_vpd_id_descriptor *)(&desc2->identifier[0] +
 	         sizeof(struct scsi_vpd_id_rel_trgt_port_id));
-	memset(devid_ptr, 0, devid_len);
 
 	/*
 	 * The control device is always connected.  The disk device, on the
@@ -9296,7 +9279,7 @@
 	 * that much.
 	 */
 	/* XXX KDM what malloc flags should we use here?? */
-	ctsio->kern_data_ptr = malloc(sizeof(*inq_ptr), M_CTL, M_WAITOK);
+	ctsio->kern_data_ptr = malloc(sizeof(*inq_ptr), M_CTL, M_WAITOK | M_ZERO);
 	if (ctsio->kern_data_ptr == NULL) {
 		ctsio->io_hdr.status = CTL_SCSI_ERROR;
 		ctsio->scsi_status = SCSI_STATUS_BUSY;
@@ -9318,8 +9301,6 @@
 		ctsio->kern_total_len = alloc_len;
 	}
 
-	memset(inq_ptr, 0, sizeof(*inq_ptr));
-
 	/*
 	 * If we have a LUN configured, report it as connected.  Otherwise,
 	 * report that it is offline or no device is supported, depending 

Modified: trunk/sys/cam/ctl/ctl_backend_block.c
===================================================================
--- trunk/sys/cam/ctl/ctl_backend_block.c	2016-09-26 02:35:36 UTC (rev 8750)
+++ trunk/sys/cam/ctl/ctl_backend_block.c	2016-09-26 02:36:09 UTC (rev 8751)
@@ -376,7 +376,6 @@
 		beio = (struct ctl_be_block_io *)malloc(sizeof(*beio),
 							   M_CTLBLK,
 							   M_WAITOK | M_ZERO);
-		bzero(beio, sizeof(*beio));
 		beio->softc = softc;
 		mtx_lock(&softc->lock);
 		STAILQ_INSERT_TAIL(&softc->beio_free_queue, beio, links);



More information about the Midnightbsd-cvs mailing list