diff options
author | trasz <trasz@FreeBSD.org> | 2012-09-27 10:51:38 +0000 |
---|---|---|
committer | trasz <trasz@FreeBSD.org> | 2012-09-27 10:51:38 +0000 |
commit | cec93f2f0fd32287db02b1dd801bf4b271535e5c (patch) | |
tree | 81fc970941fb82a9396e8991d3f4fef7c67f2273 /sys/cam | |
parent | f6854895af161d1c346ba04f83ff26ab6d15ccbc (diff) | |
download | FreeBSD-src-cec93f2f0fd32287db02b1dd801bf4b271535e5c.zip FreeBSD-src-cec93f2f0fd32287db02b1dd801bf4b271535e5c.tar.gz |
Remove useless NULL checks after M_WAITOK allocations.
Diffstat (limited to 'sys/cam')
-rw-r--r-- | sys/cam/ctl/ctl.c | 93 | ||||
-rw-r--r-- | sys/cam/ctl/ctl_backend_block.c | 25 | ||||
-rw-r--r-- | sys/cam/ctl/ctl_backend_ramdisk.c | 20 | ||||
-rw-r--r-- | sys/cam/ctl/scsi_ctl.c | 11 |
4 files changed, 2 insertions, 147 deletions
diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c index 718164f..8bc1c16 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -1520,12 +1520,6 @@ ctl_ioctl_do_datamove(struct ctl_scsiio *ctsio) ext_sglist = (struct ctl_sg_entry *)malloc(ext_sglen, M_CTL, M_WAITOK); - if (ext_sglist == NULL) { - ctl_set_internal_failure(ctsio, - /*sks_valid*/ 0, - /*retry_count*/ 0); - return (CTL_RETVAL_COMPLETE); - } ext_sglist_malloced = 1; if (copyin(ctsio->ext_data_ptr, ext_sglist, ext_sglen) != 0) { @@ -2028,11 +2022,6 @@ ctl_copyin_alloc(void *user_addr, int len, char *error_str, void *kptr; kptr = malloc(len, M_CTL, M_WAITOK | M_ZERO); - if (kptr == NULL) { - snprintf(error_str, error_str_len, "Cannot allocate %d bytes", - len); - return (NULL); - } if (copyin(user_addr, kptr, len) != 0) { snprintf(error_str, error_str_len, "Error copying %d bytes " @@ -2764,12 +2753,6 @@ ctl_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, new_err_desc = malloc(sizeof(*new_err_desc), M_CTL, M_WAITOK | M_ZERO); - if (new_err_desc == NULL) { - printf("%s: CTL_ERROR_INJECT: error allocating %zu " - "bytes\n", __func__, sizeof(*new_err_desc)); - retval = ENOMEM; - break; - } bcopy(err_desc, new_err_desc, sizeof(*new_err_desc)); mtx_lock(&softc->ctl_lock); @@ -4203,11 +4186,6 @@ ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *ctl_lun, } if (ctl_lun == NULL) { lun = malloc(sizeof(*lun), M_CTL, M_WAITOK); - if (lun == NULL) { - be_lun->lun_config_status(lun->be_lun->be_lun, - CTL_LUN_CONFIG_FAILURE); - return (-ENOMEM); - } lun->flags = CTL_LUN_MALLOCED; } else lun = ctl_lun; @@ -5061,12 +5039,6 @@ ctl_scsi_release(struct ctl_scsiio *ctsio) if (((ctsio->io_hdr.flags & CTL_FLAG_ALLOCATED) == 0) && (length > 0)) { ctsio->kern_data_ptr = malloc(length, M_CTL, M_WAITOK); - if (ctsio->kern_data_ptr == NULL) { - ctsio->io_hdr.status = CTL_SCSI_ERROR; - ctsio->io_hdr.status = SCSI_STATUS_BUSY; - ctl_done((union ctl_io *)ctsio); - return (CTL_RETVAL_COMPLETE); - } ctsio->kern_data_len = length; ctsio->kern_total_len = length; ctsio->kern_data_resid = 0; @@ -5202,12 +5174,6 @@ ctl_scsi_reserve(struct ctl_scsiio *ctsio) if (((ctsio->io_hdr.flags & CTL_FLAG_ALLOCATED) == 0) && (length > 0)) { ctsio->kern_data_ptr = malloc(length, M_CTL, M_WAITOK); - if (ctsio->kern_data_ptr == NULL) { - ctsio->io_hdr.status = CTL_SCSI_ERROR; - ctsio->io_hdr.status = SCSI_STATUS_BUSY; - ctl_done((union ctl_io *)ctsio); - return (CTL_RETVAL_COMPLETE); - } ctsio->kern_data_len = length; ctsio->kern_total_len = length; ctsio->kern_data_resid = 0; @@ -5573,12 +5539,6 @@ ctl_format(struct ctl_scsiio *ctsio) if (((ctsio->io_hdr.flags & CTL_FLAG_ALLOCATED) == 0) && (length > 0)) { ctsio->kern_data_ptr = malloc(length, M_CTL, M_WAITOK); - if (ctsio->kern_data_ptr == NULL) { - ctsio->io_hdr.status = CTL_SCSI_ERROR; - ctsio->io_hdr.status = SCSI_STATUS_BUSY; - ctl_done((union ctl_io *)ctsio); - return (CTL_RETVAL_COMPLETE); - } ctsio->kern_data_len = length; ctsio->kern_total_len = length; ctsio->kern_data_resid = 0; @@ -6368,11 +6328,6 @@ ctl_mode_select(struct ctl_scsiio *ctsio) */ if ((ctsio->io_hdr.flags & CTL_FLAG_ALLOCATED) == 0) { ctsio->kern_data_ptr = malloc(param_len, M_CTL, M_WAITOK); - if (ctsio->kern_data_ptr == NULL) { - ctl_set_busy(ctsio); - ctl_done((union ctl_io *)ctsio); - return (CTL_RETVAL_COMPLETE); - } ctsio->kern_data_len = param_len; ctsio->kern_total_len = param_len; ctsio->kern_data_resid = 0; @@ -6607,12 +6562,6 @@ ctl_mode_sense(struct ctl_scsiio *ctsio) #endif ctsio->kern_data_ptr = malloc(total_len, M_CTL, M_WAITOK); - if (ctsio->kern_data_ptr == NULL) { - ctsio->io_hdr.status = CTL_SCSI_ERROR; - ctsio->scsi_status = SCSI_STATUS_BUSY; - ctl_done((union ctl_io *)ctsio); - return (CTL_RETVAL_COMPLETE); - } ctsio->kern_sg_entries = 0; ctsio->kern_data_resid = 0; ctsio->kern_rel_offset = 0; @@ -6794,12 +6743,6 @@ ctl_read_capacity(struct ctl_scsiio *ctsio) lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; ctsio->kern_data_ptr = malloc(sizeof(*data), M_CTL, M_WAITOK); - if (ctsio->kern_data_ptr == NULL) { - ctsio->io_hdr.status = CTL_SCSI_ERROR; - ctsio->scsi_status = SCSI_STATUS_BUSY; - ctl_done((union ctl_io *)ctsio); - return (CTL_RETVAL_COMPLETE); - } data = (struct scsi_read_capacity_data *)ctsio->kern_data_ptr; ctsio->residual = 0; ctsio->kern_data_len = sizeof(*data); @@ -6864,12 +6807,6 @@ ctl_read_capacity_16(struct ctl_scsiio *ctsio) lun = (struct ctl_lun *)ctsio->io_hdr.ctl_private[CTL_PRIV_LUN].ptr; ctsio->kern_data_ptr = malloc(sizeof(*data), M_CTL, M_WAITOK); - if (ctsio->kern_data_ptr == NULL) { - ctsio->io_hdr.status = CTL_SCSI_ERROR; - ctsio->scsi_status = SCSI_STATUS_BUSY; - ctl_done((union ctl_io *)ctsio); - return (CTL_RETVAL_COMPLETE); - } data = (struct scsi_read_capacity_data_long *)ctsio->kern_data_ptr; if (sizeof(*data) < alloc_len) { @@ -6977,12 +6914,6 @@ ctl_maintenance_in(struct ctl_scsiio *ctsio) alloc_len = scsi_4btoul(cdb->length); ctsio->kern_data_ptr = malloc(total_len, M_CTL, M_WAITOK); - if (ctsio->kern_data_ptr == NULL) { - ctsio->io_hdr.status = CTL_SCSI_ERROR; - ctsio->scsi_status = SCSI_STATUS_BUSY; - ctl_done((union ctl_io *)ctsio); - return (CTL_RETVAL_COMPLETE); - } memset(ctsio->kern_data_ptr, 0, total_len); ctsio->kern_sg_entries = 0; @@ -7138,12 +7069,6 @@ retry: mtx_unlock(&softc->ctl_lock); ctsio->kern_data_ptr = malloc(total_len, M_CTL, M_WAITOK); - if (ctsio->kern_data_ptr == NULL) { - ctsio->io_hdr.status = CTL_SCSI_ERROR; - ctsio->scsi_status = SCSI_STATUS_BUSY; - ctl_done((union ctl_io *)ctsio); - return (CTL_RETVAL_COMPLETE); - } if (total_len < alloc_len) { ctsio->residual = alloc_len - total_len; @@ -7876,11 +7801,6 @@ ctl_persistent_reserve_out(struct ctl_scsiio *ctsio) if ((ctsio->io_hdr.flags & CTL_FLAG_ALLOCATED) == 0) { ctsio->kern_data_ptr = malloc(param_len, M_CTL, M_WAITOK); - if (ctsio->kern_data_ptr == NULL) { - ctl_set_busy(ctsio); - ctl_done((union ctl_io *)ctsio); - return (CTL_RETVAL_COMPLETE); - } ctsio->kern_data_len = param_len; ctsio->kern_total_len = param_len; ctsio->kern_data_resid = 0; @@ -8692,13 +8612,6 @@ ctl_report_luns(struct ctl_scsiio *ctsio) (num_luns * sizeof(struct scsi_report_luns_lundata)); ctsio->kern_data_ptr = malloc(lun_datalen, M_CTL, M_WAITOK); - if (ctsio->kern_data_ptr == NULL) { - ctsio->io_hdr.status = CTL_SCSI_ERROR; - ctsio->scsi_status = SCSI_STATUS_BUSY; - ctl_done((union ctl_io *)ctsio); - return (CTL_RETVAL_COMPLETE); - } - lun_data = (struct scsi_report_luns_data *)ctsio->kern_data_ptr; ctsio->kern_sg_entries = 0; @@ -8821,12 +8734,6 @@ ctl_request_sense(struct ctl_scsiio *ctsio) sense_format = SSD_TYPE_FIXED; ctsio->kern_data_ptr = malloc(sizeof(*sense_ptr), M_CTL, M_WAITOK); - if (ctsio->kern_data_ptr == NULL) { - ctsio->io_hdr.status = CTL_SCSI_ERROR; - ctsio->scsi_status = SCSI_STATUS_BUSY; - ctl_done((union ctl_io *)ctsio); - return (CTL_RETVAL_COMPLETE); - } sense_ptr = (struct scsi_sense_data *)ctsio->kern_data_ptr; ctsio->kern_sg_entries = 0; diff --git a/sys/cam/ctl/ctl_backend_block.c b/sys/cam/ctl/ctl_backend_block.c index cbd3c33..34ca213 100644 --- a/sys/cam/ctl/ctl_backend_block.c +++ b/sys/cam/ctl/ctl_backend_block.c @@ -376,9 +376,6 @@ ctl_grow_beio(struct ctl_be_block_softc *softc, int count) beio = (struct ctl_be_block_io *)malloc(sizeof(*beio), M_CTLBLK, M_WAITOK | M_ZERO); - if (beio == NULL) - break; - bzero(beio, sizeof(*beio)); beio->softc = softc; mtx_lock(&softc->lock); @@ -1092,15 +1089,6 @@ ctl_be_block_dispatch(struct ctl_be_block_lun *be_lun, */ beio->sg_segs[i].len = min(MAXPHYS, len_left); beio->sg_segs[i].addr = uma_zalloc(be_lun->lun_zone, M_WAITOK); - /* - * uma_zalloc() can in theory return NULL even with M_WAITOK - * if it can't pull more memory into the zone. - */ - if (beio->sg_segs[i].addr == NULL) { - ctl_set_busy(&io->scsiio); - ctl_complete_beio(beio); - return; - } DPRINTF("segment %d addr %p len %zd\n", i, beio->sg_segs[i].addr, beio->sg_segs[i].len); @@ -1660,13 +1648,6 @@ ctl_be_block_create(struct ctl_be_block_softc *softc, struct ctl_lun_req *req) be_lun = malloc(sizeof(*be_lun), M_CTLBLK, M_ZERO | M_WAITOK); - if (be_lun == NULL) { - snprintf(req->error_str, sizeof(req->error_str), - "%s: error allocating %zd bytes", __func__, - sizeof(*be_lun)); - goto bailout_error; - } - be_lun->softc = softc; STAILQ_INIT(&be_lun->input_queue); STAILQ_INIT(&be_lun->config_write_queue); @@ -1705,12 +1686,6 @@ ctl_be_block_create(struct ctl_be_block_softc *softc, struct ctl_lun_req *req) be_lun->dev_path = malloc(file_arg->vallen, M_CTLBLK, M_WAITOK | M_ZERO); - if (be_lun->dev_path == NULL) { - snprintf(req->error_str, sizeof(req->error_str), - "%s: error allocating %d bytes", __func__, - file_arg->vallen); - goto bailout_error; - } strlcpy(be_lun->dev_path, (char *)file_arg->value, file_arg->vallen); diff --git a/sys/cam/ctl/ctl_backend_ramdisk.c b/sys/cam/ctl/ctl_backend_ramdisk.c index b1d4502..985fad4 100644 --- a/sys/cam/ctl/ctl_backend_ramdisk.c +++ b/sys/cam/ctl/ctl_backend_ramdisk.c @@ -134,7 +134,7 @@ ctl_backend_ramdisk_init(void) { struct ctl_be_ramdisk_softc *softc; #ifdef CTL_RAMDISK_PAGES - int i, j; + int i; #endif @@ -151,17 +151,8 @@ ctl_backend_ramdisk_init(void) softc->ramdisk_pages = (uint8_t **)malloc(sizeof(uint8_t *) * softc->num_pages, M_RAMDISK, M_WAITOK); - for (i = 0; i < softc->num_pages; i++) { + for (i = 0; i < softc->num_pages; i++) softc->ramdisk_pages[i] = malloc(PAGE_SIZE, M_RAMDISK,M_WAITOK); - if (softc->ramdisk_pages[i] == NULL) { - for (j = 0; j < i; j++) { - free(softc->ramdisk_pages[j], M_RAMDISK); - } - free(softc->ramdisk_pages, M_RAMDISK); - panic("RAMDisk initialization failed\n"); - return (1); /* NOTREACHED */ - } - } #else softc->ramdisk_buffer = (uint8_t *)malloc(softc->rd_size, M_RAMDISK, M_WAITOK); @@ -313,13 +304,6 @@ ctl_backend_ramdisk_submit(union ctl_io *io) io->scsiio.kern_data_ptr = malloc(sizeof(struct ctl_sg_entry) * num_sg_entries, M_RAMDISK, M_WAITOK); - if (io->scsiio.kern_data_ptr == NULL) { - ctl_set_internal_failure(&io->scsiio, - /*sks_valid*/ 0, - /*retry_count*/ 0); - ctl_done(io); - return (CTL_RETVAL_COMPLETE); - } sg_entries = (struct ctl_sg_entry *)io->scsiio.kern_data_ptr; for (i = 0, len_filled = 0; i < num_sg_entries; i++, len_filled += PAGE_SIZE) { diff --git a/sys/cam/ctl/scsi_ctl.c b/sys/cam/ctl/scsi_ctl.c index a6f58dd..8d6f7e3 100644 --- a/sys/cam/ctl/scsi_ctl.c +++ b/sys/cam/ctl/scsi_ctl.c @@ -1694,11 +1694,6 @@ ctlfe_onoffline(void *arg, int online) return; } ccb = (union ccb *)malloc(sizeof(*ccb), M_TEMP, M_WAITOK | M_ZERO); - if (ccb == NULL) { - printf("%s: unable to malloc CCB!\n", __func__); - xpt_free_path(path); - return; - } xpt_setup_ccb(&ccb->ccb_h, path, /*priority*/ 1); sim = xpt_path_sim(path); @@ -1900,12 +1895,6 @@ ctlfe_lun_enable(void *arg, struct ctl_id targ_id, int lun_id) } softc = malloc(sizeof(*softc), M_CTLFE, M_WAITOK | M_ZERO); - if (softc == NULL) { - printf("%s: could not allocate %zd bytes for softc\n", - __func__, sizeof(*softc)); - xpt_free_path(path); - return (1); - } sim = xpt_path_sim(path); mtx_lock(sim->mtx); periph = cam_periph_find(path, "ctl"); |