From 056fd51a2215e8405ed46945b0eb147735753b9b Mon Sep 17 00:00:00 2001 From: mav Date: Wed, 20 Jun 2012 18:25:51 +0000 Subject: [PATCH] Check status of cam_periph_hold() inside cdclose(). If cd device was invalidated while open, cam_periph_hold() will return error and won't get the reference. Following reference release will crash the system. Sponsored by: iXsystems, Inc. MFC after: 3 days --- sys/cam/scsi/scsi_cd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sys/cam/scsi/scsi_cd.c b/sys/cam/scsi/scsi_cd.c index da7b8ea721e1..2d64553e427f 100644 --- a/sys/cam/scsi/scsi_cd.c +++ b/sys/cam/scsi/scsi_cd.c @@ -1041,6 +1041,7 @@ cdclose(struct disk *dp) { struct cam_periph *periph; struct cd_softc *softc; + int error; periph = (struct cam_periph *)dp->d_drv1; if (periph == NULL) @@ -1049,7 +1050,11 @@ cdclose(struct disk *dp) softc = (struct cd_softc *)periph->softc; cam_periph_lock(periph); - cam_periph_hold(periph, PRIBIO); + if ((error = cam_periph_hold(periph, PRIBIO)) != 0) { + cam_periph_unlock(periph); + cam_periph_release(periph); + return (0); + } CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH, ("cdclose\n"));