Index: sys/cam/ata/ata_da.c =================================================================== --- sys/cam/ata/ata_da.c +++ sys/cam/ata/ata_da.c @@ -1806,6 +1806,12 @@ "Unable to allocate softc\n"); return(CAM_REQ_CMP_ERR); } + if ((softc->disk = disk_alloc_nowait()) == NULL) { + printf("adaregister: Unable to probe new device. " + "Unable to allocate disk\n"); + free(softc, M_DEVBUF); + return(CAM_REQ_CMP_ERR); + } announce_buf = softc->announce_temp; bzero(announce_buf, ADA_ANNOUNCETMP_SZ); @@ -1813,6 +1819,7 @@ if (cam_iosched_init(&softc->cam_iosched, periph) != 0) { printf("adaregister: Unable to probe new device. " "Unable to allocate iosched memory\n"); + disk_free(softc->disk); free(softc, M_DEVBUF); return(CAM_REQ_CMP_ERR); } @@ -1868,7 +1875,6 @@ } cam_iosched_set_sort_queue(softc->cam_iosched, (softc->flags & ADA_FLAG_ROTATING) ? -1 : 0); - softc->disk = disk_alloc(); adasetgeom(softc, cgd); softc->disk->d_devstat = devstat_new_entry(periph->periph_name, periph->unit_number, softc->params.secsize, Index: sys/cam/mmc/mmc_da.c =================================================================== --- sys/cam/mmc/mmc_da.c +++ sys/cam/mmc/mmc_da.c @@ -1542,6 +1542,12 @@ printf("Cannot add partition for sdda\n"); return (false); } + if ((part->disk = disk_alloc_nowait()) == NULL) { + printf("Cannot alloc disk for sdda\n"); + free(part, M_DEVBUF); + sc->part[type] = NULL; + return (false); + } part->cnt = cnt; part->type = type; @@ -1575,7 +1581,6 @@ (void)cam_periph_hold(periph, PRIBIO); cam_periph_unlock(periph); - part->disk = disk_alloc(); part->disk->d_rotation_rate = DISK_RR_NON_ROTATING; part->disk->d_devstat = devstat_new_entry(part->name, cnt, 512, Index: sys/cam/nvme/nvme_da.c =================================================================== --- sys/cam/nvme/nvme_da.c +++ sys/cam/nvme/nvme_da.c @@ -854,16 +854,23 @@ softc = (struct nda_softc *)malloc(sizeof(*softc), M_DEVBUF, M_NOWAIT | M_ZERO); - if (softc == NULL) { printf("ndaregister: Unable to probe new device. " "Unable to allocate softc\n"); return(CAM_REQ_CMP_ERR); } + if ((disk = disk_alloc_nowait()) == NULL) { + printf("ndaregister: Unable to probe new device. " + "Unable to allocate disk\n"); + free(softc, M_DEVBUF); + return(CAM_REQ_CMP_ERR); + } + if (cam_iosched_init(&softc->cam_iosched, periph) != 0) { printf("ndaregister: Unable to probe new device. " "Unable to allocate iosched memory\n"); + disk_free(disk); free(softc, M_DEVBUF); return(CAM_REQ_CMP_ERR); } @@ -891,7 +898,7 @@ TUNABLE_INT_FETCH(announce_buf, &quirks); softc->quirks = quirks; cam_iosched_set_sort_queue(softc->cam_iosched, 0); - softc->disk = disk = disk_alloc(); + softc->disk = disk; disk->d_rotation_rate = DISK_RR_NON_ROTATING; disk->d_open = ndaopen; disk->d_close = ndaclose; Index: sys/cam/scsi/scsi_cd.c =================================================================== --- sys/cam/scsi/scsi_cd.c +++ sys/cam/scsi/scsi_cd.c @@ -605,6 +605,12 @@ "Unable to allocate softc\n"); return(CAM_REQ_CMP_ERR); } + if ((softc->disk = disk_alloc()) == NULL) { + printf("cdregister: Unable to probe new device. " + "Unable to allocate softc\n"); + free(softc, M_DEVBUF); + return(CAM_REQ_CMP_ERR); + } LIST_INIT(&softc->pending_ccbs); STAILQ_INIT(&softc->mode_queue); @@ -673,7 +679,6 @@ * WORM peripheral driver. WORM drives will also have the WORM * driver attached to them. */ - softc->disk = disk_alloc(); softc->disk->d_devstat = devstat_new_entry("cd", periph->unit_number, 0, DEVSTAT_BS_UNAVAILABLE, Index: sys/cam/scsi/scsi_da.c =================================================================== --- sys/cam/scsi/scsi_da.c +++ sys/cam/scsi/scsi_da.c @@ -2775,16 +2775,23 @@ softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF, M_NOWAIT|M_ZERO); - if (softc == NULL) { printf("daregister: Unable to probe new device. " "Unable to allocate softc\n"); return(CAM_REQ_CMP_ERR); } + if ((softc->disk = disk_alloc_nowait()) == NULL) { + printf("daregister: Unable to probe new device. " + "Unable to allocate disk\n"); + free(softc, M_DEVBUF); + return(CAM_REQ_CMP_ERR); + } + if (cam_iosched_init(&softc->cam_iosched, periph) != 0) { printf("daregister: Unable to probe new device. " "Unable to allocate iosched memory\n"); + disk_free(softc->disk); free(softc, M_DEVBUF); return(CAM_REQ_CMP_ERR); } @@ -2904,7 +2911,6 @@ /* * Register this media as a disk. */ - softc->disk = disk_alloc(); softc->disk->d_devstat = devstat_new_entry(periph->periph_name, periph->unit_number, 0, DEVSTAT_BS_UNAVAILABLE,