PR: 130735 Status: c Index: sys/cam/scsi/scsi_cd.c =================================================================== --- sys/cam/scsi/scsi_cd.c (revision 198477) +++ sys/cam/scsi/scsi_cd.c (working copy) @@ -3730,7 +3730,7 @@ cdreportkey(struct cam_periph *periph, s databuf = NULL; lba = 0; - ccb = cdgetccb(periph, CAM_PRIORITY_NORMAL); + cam_periph_unlock(periph); switch (authinfo->format) { case DVD_REPORT_AGID: @@ -3758,8 +3758,12 @@ cdreportkey(struct cam_periph *periph, s break; default: error = EINVAL; - goto bailout; - break; /* NOTREACHED */ + break; + } + + if (error != 0) { + cam_periph_lock(periph); + return (error); } if (length != 0) { @@ -3767,6 +3771,9 @@ cdreportkey(struct cam_periph *periph, s } else databuf = NULL; + cam_periph_lock(periph); + + ccb = cdgetccb(periph, CAM_PRIORITY_NORMAL); scsi_report_key(&ccb->csio, /* retries */ 1, @@ -3887,7 +3894,7 @@ cdsendkey(struct cam_periph *periph, str error = 0; databuf = NULL; - ccb = cdgetccb(periph, CAM_PRIORITY_NORMAL); + cam_periph_unlock(periph); switch(authinfo->format) { case DVD_SEND_CHALLENGE: { @@ -3941,10 +3948,16 @@ cdsendkey(struct cam_periph *periph, str } default: error = EINVAL; - goto bailout; - break; /* NOTREACHED */ + break; } + cam_periph_lock(periph); + + if (error != 0) + return (error); + + ccb = cdgetccb(periph, CAM_PRIORITY_NORMAL); + scsi_send_key(&ccb->csio, /* retries */ 1, /* cbfcnp */ cddone, @@ -3959,8 +3972,6 @@ cdsendkey(struct cam_periph *periph, str error = cdrunccb(ccb, cderror, /*cam_flags*/CAM_RETRY_SELTO, /*sense_flags*/SF_RETRY_UA); -bailout: - if (databuf != NULL) free(databuf, M_DEVBUF); @@ -3983,7 +3994,7 @@ cdreaddvdstructure(struct cam_periph *pe /* The address is reserved for many of the formats */ address = 0; - ccb = cdgetccb(periph, CAM_PRIORITY_NORMAL); + cam_periph_unlock(periph); switch(dvdstruct->format) { case DVD_STRUCT_PHYSICAL: @@ -4003,12 +4014,11 @@ cdreaddvdstructure(struct cam_periph *pe break; case DVD_STRUCT_CMI: error = ENODEV; - goto bailout; #ifdef notyet length = sizeof(struct scsi_read_dvd_struct_data_copy_manage); address = dvdstruct->address; #endif - break; /* NOTREACHED */ + break; case DVD_STRUCT_PROTDISCID: length = sizeof(struct scsi_read_dvd_struct_data_prot_discid); break; @@ -4026,20 +4036,18 @@ cdreaddvdstructure(struct cam_periph *pe break; case DVD_STRUCT_RMD_LAST: error = ENODEV; - goto bailout; #ifdef notyet length = sizeof(struct scsi_read_dvd_struct_data_rmd_borderout); address = dvdstruct->address; #endif - break; /* NOTREACHED */ + break; case DVD_STRUCT_RMD_RMA: error = ENODEV; - goto bailout; #ifdef notyet length = sizeof(struct scsi_read_dvd_struct_data_rmd); address = dvdstruct->address; #endif - break; /* NOTREACHED */ + break; case DVD_STRUCT_PRERECORDED: length = sizeof(struct scsi_read_dvd_struct_data_leadin); break; @@ -4048,12 +4056,11 @@ cdreaddvdstructure(struct cam_periph *pe break; case DVD_STRUCT_DCB: error = ENODEV; - goto bailout; #ifdef notyet length = sizeof(struct scsi_read_dvd_struct_data_dcb); address = dvdstruct->address; #endif - break; /* NOTREACHED */ + break; case DVD_STRUCT_LIST: /* * This is the maximum allocation length for the READ DVD @@ -4066,8 +4073,12 @@ cdreaddvdstructure(struct cam_periph *pe break; default: error = EINVAL; - goto bailout; - break; /* NOTREACHED */ + break; + } + + if (error != 0) { + cam_periph_lock(periph); + return (error); } if (length != 0) { @@ -4075,6 +4086,10 @@ cdreaddvdstructure(struct cam_periph *pe } else databuf = NULL; + cam_periph_lock(periph); + + ccb = cdgetccb(periph, CAM_PRIORITY_NORMAL); + scsi_read_dvd_structure(&ccb->csio, /* retries */ 1, /* cbfcnp */ cddone,