patch-2.1.121 linux/drivers/scsi/sr_ioctl.c

Next file: linux/drivers/scsi/st.c
Previous file: linux/drivers/scsi/scsi_ioctl.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.120/linux/drivers/scsi/sr_ioctl.c linux/drivers/scsi/sr_ioctl.c
@@ -55,8 +55,10 @@
     int result, err = 0, retries = 0;
     unsigned long flags;
 
+    spin_lock_irqsave(&io_request_lock, flags);
     SDev  = scsi_CDs[target].device;
     SCpnt = scsi_allocate_device(NULL, scsi_CDs[target].device, 1);
+    spin_unlock_irqrestore(&io_request_lock, flags);
 
 retry:
     if( !scsi_block_when_processing_errors(SDev) )
@@ -137,12 +139,14 @@
             err = -EIO;
 	}
     }
-    
+   
+    spin_lock_irqsave(&io_request_lock, flags);
     result = SCpnt->result;
     /* Wake up a process waiting for device*/
     wake_up(&SCpnt->device->device_wait);
     scsi_release_command(SCpnt);
     SCpnt = NULL;
+    spin_unlock_irqrestore(&io_request_lock, flags);
     return err;
 }
 
@@ -235,6 +239,7 @@
         u_char  sr_cmd[10];
 	char * buffer;
         int result;
+        unsigned long flags;
         	
 	sr_cmd[0] = SCMD_READ_SUBCHANNEL;
 	sr_cmd[1] = ((scsi_CDs[MINOR(cdi->dev)].device->lun) << 5);
@@ -245,8 +250,10 @@
 	sr_cmd[7] = 0;
 	sr_cmd[8] = 24;
 	sr_cmd[9] = 0;
-	
+
+        spin_lock_irqsave(&io_request_lock, flags);
 	buffer = (unsigned char*) scsi_malloc(512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
 	if(!buffer) return -ENOMEM;
 	
 	result = sr_do_ioctl(MINOR(cdi->dev), sr_cmd, buffer, 24, 0);
@@ -254,7 +261,9 @@
 	memcpy (mcn->medium_catalog_number, buffer + 9, 13);
         mcn->medium_catalog_number[13] = 0;
 
+        spin_lock_irqsave(&io_request_lock, flags);
 	scsi_free(buffer, 512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
 	
 	return result;
 }
@@ -384,6 +393,7 @@
     {
 	struct cdrom_tochdr* tochdr = (struct cdrom_tochdr*)arg;
 	char * buffer;
+        unsigned long flags;
 	
 	sr_cmd[0] = SCMD_READ_TOC;
 	sr_cmd[1] = ((scsi_CDs[target].device->lun) << 5);
@@ -393,7 +403,9 @@
 	sr_cmd[8] = 12;             /* LSB of length */
 	sr_cmd[9] = 0;
 	
+        spin_lock_irqsave(&io_request_lock, flags);
 	buffer = (unsigned char *) scsi_malloc(512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
 	if(!buffer) return -ENOMEM;
 	
 	result = sr_do_ioctl(target, sr_cmd, buffer, 12, 0);
@@ -401,7 +413,9 @@
 	tochdr->cdth_trk0 = buffer[2];
 	tochdr->cdth_trk1 = buffer[3];
 	
+        spin_lock_irqsave(&io_request_lock, flags);
 	scsi_free(buffer, 512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
         break;
     }
 	
@@ -409,6 +423,7 @@
     {
 	struct cdrom_tocentry* tocentry = (struct cdrom_tocentry*)arg;
 	unsigned char * buffer;
+        unsigned long flags;
 	
 	sr_cmd[0] = SCMD_READ_TOC;
 	sr_cmd[1] = ((scsi_CDs[target].device->lun) << 5) |
@@ -419,7 +434,9 @@
 	sr_cmd[8] = 12;            /* LSB of length */
 	sr_cmd[9] = 0;
 	
+        spin_lock_irqsave(&io_request_lock, flags);
 	buffer = (unsigned char *) scsi_malloc(512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
 	if(!buffer) return -ENOMEM;
 	
 	result = sr_do_ioctl (target, sr_cmd, buffer, 12, 0);
@@ -435,7 +452,9 @@
 	    tocentry->cdte_addr.lba = (((((buffer[8] << 8) + buffer[9]) << 8)
                                        + buffer[10]) << 8) + buffer[11];
 	
+        spin_lock_irqsave(&io_request_lock, flags);
 	scsi_free(buffer, 512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
         break;
     }
 	
@@ -461,6 +480,7 @@
     {
 	char * buffer, * mask;
 	struct cdrom_volctrl* volctrl = (struct cdrom_volctrl*)arg;
+        unsigned long flags;
 	
 	/* First we get the current params so we can just twiddle the volume */
 	
@@ -471,12 +491,16 @@
 	sr_cmd[4] = 28;
 	sr_cmd[5] = 0;
 	
+        spin_lock_irqsave(&io_request_lock, flags);
 	buffer = (unsigned char *) scsi_malloc(512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
 	if(!buffer) return -ENOMEM;
 	
 	if ((result = sr_do_ioctl (target, sr_cmd, buffer, 28, 0))) {
 	    printk ("Hosed while obtaining audio mode page\n");
+            spin_lock_irqsave(&io_request_lock, flags);
 	    scsi_free(buffer, 512);
+            spin_unlock_irqrestore(&io_request_lock, flags);
             break;
 	}
 	
@@ -487,17 +511,23 @@
 	sr_cmd[4] = 28;
 	sr_cmd[5] = 0;
 	
+        spin_lock_irqsave(&io_request_lock, flags);
 	mask = (unsigned char *) scsi_malloc(512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
 	if(!mask) {
+            spin_lock_irqsave(&io_request_lock, flags);
 	    scsi_free(buffer, 512);
+            spin_unlock_irqrestore(&io_request_lock, flags);
 	    result = -ENOMEM;
             break;
 	};
 
 	if ((result = sr_do_ioctl (target, sr_cmd, mask, 28, 0))) {
 	    printk ("Hosed while obtaining mask for audio mode page\n");
+            spin_lock_irqsave(&io_request_lock, flags);
 	    scsi_free(buffer, 512);
 	    scsi_free(mask, 512);
+            spin_unlock_irqrestore(&io_request_lock, flags);
 	    break;
 	}
 	
@@ -516,8 +546,10 @@
 	sr_cmd[5] = 0;
 	
 	result = sr_do_ioctl (target, sr_cmd, buffer, 28, 0);
+        spin_lock_irqsave(&io_request_lock, flags);
 	scsi_free(buffer, 512);
 	scsi_free(mask, 512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
         break;
     }
 	
@@ -525,6 +557,7 @@
     {
 	char * buffer;
 	struct cdrom_volctrl* volctrl = (struct cdrom_volctrl*)arg;
+        unsigned long flags;
 	
 	/* Get the current params */
 	
@@ -535,12 +568,16 @@
 	sr_cmd[4] = 28;
 	sr_cmd[5] = 0;
 	
+        spin_lock_irqsave(&io_request_lock, flags);
 	buffer = (unsigned char *) scsi_malloc(512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
 	if(!buffer) return -ENOMEM;
 	
 	if ((result = sr_do_ioctl (target, sr_cmd, buffer, 28, 0))) {
 	    printk ("(CDROMVOLREAD) Hosed while obtaining audio mode page\n");
+            spin_lock_irqsave(&io_request_lock, flags);
 	    scsi_free(buffer, 512);
+            spin_unlock_irqrestore(&io_request_lock, flags);
             break;
 	}
 
@@ -549,7 +586,9 @@
 	volctrl->channel2 = buffer[25];
 	volctrl->channel3 = buffer[27];
 
+        spin_lock_irqsave(&io_request_lock, flags);
 	scsi_free(buffer, 512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
         break;
     }
 	
@@ -557,6 +596,7 @@
     {
 	struct cdrom_subchnl* subchnl = (struct cdrom_subchnl*)arg;
 	char * buffer;
+        unsigned long flags;
 	
 	sr_cmd[0] = SCMD_READ_SUBCHANNEL;
 	sr_cmd[1] = ((scsi_CDs[target].device->lun) << 5) | 0x02;    /* MSF format */
@@ -568,7 +608,9 @@
 	sr_cmd[8] = 16;
 	sr_cmd[9] = 0;
 	
-	buffer = (unsigned char*) scsi_malloc(512);
+        spin_lock_irqsave(&io_request_lock, flags);
+	buffer = (unsigned char *) scsi_malloc(512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
 	if(!buffer) return -ENOMEM;
 	
 	result = sr_do_ioctl(target, sr_cmd, buffer, 16, 0);
@@ -586,7 +628,9 @@
 	subchnl->cdsc_absaddr.msf.second = buffer[10];
 	subchnl->cdsc_absaddr.msf.frame = buffer[11];
 	
+        spin_lock_irqsave(&io_request_lock, flags);
 	scsi_free(buffer, 512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
         break;
     }
     default:
@@ -694,11 +738,14 @@
 {
     unsigned char *raw_sector;
     int is_xa;
+    unsigned long flags;
     
     if (!xa_test)
         return 0;
-    
+   
+    spin_lock_irqsave(&io_request_lock, flags);
     raw_sector = (unsigned char *) scsi_malloc(2048+512);
+    spin_unlock_irqrestore(&io_request_lock, flags);
     if (!raw_sector) return -ENOMEM;
     if (0 == sr_read_sector(minor,scsi_CDs[minor].ms_offset+16,
                             CD_FRAMESIZE_RAW1,raw_sector)) {
@@ -707,7 +754,9 @@
         /* read a raw sector failed for some reason. */
         is_xa = -1;
     }
+    spin_lock_irqsave(&io_request_lock, flags);
     scsi_free(raw_sector, 2048+512);
+    spin_unlock_irqrestore(&io_request_lock, flags);
 #ifdef DEBUG
     printk("sr%d: sr_is_xa: %d\n",minor,is_xa);
 #endif
@@ -730,6 +779,7 @@
         struct cdrom_msf   msf;
         int                lba, rc;
 	int                blocksize = 2048;
+        unsigned long flags;
 
         switch (cmd) {
         case CDROMREADMODE2: blocksize = CD_FRAMESIZE_RAW0; break; /* 2336 */
@@ -738,7 +788,10 @@
 
 	if (copy_from_user(&msf,(void*)arg,sizeof(msf)))
 		return -EFAULT;
-	if (!(raw = scsi_malloc(2048+512)))
+        spin_lock_irqsave(&io_request_lock, flags);
+        raw = scsi_malloc(2048+512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
+	if (!(raw))
                 return -ENOMEM;
 
 	lba = (((msf.cdmsf_min0 * CD_SECS) + msf.cdmsf_sec0)
@@ -751,7 +804,9 @@
 		if (copy_to_user((void*)arg, raw, blocksize))
 			rc = -EFAULT;
 
+        spin_lock_irqsave(&io_request_lock, flags);
 	scsi_free(raw,2048+512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
 	return rc;
     }
     case CDROMREADAUDIO:
@@ -759,6 +814,7 @@
 	unsigned char      *raw;
         int                lba, rc=0;
         struct cdrom_read_audio ra;
+        unsigned long flags;
 
         if (!scsi_CDs[target].readcd_known || !scsi_CDs[target].readcd_cdda)
             return -EINVAL;  /* -EDRIVE_DOES_NOT_SUPPORT_THIS ? */
@@ -774,7 +830,10 @@
 
         if (lba < 0 || lba >= scsi_CDs[target].capacity)
             return -EINVAL;
-	if (!(raw = scsi_malloc(2048+512)))
+        spin_lock_irqsave(&io_request_lock, flags);
+        raw = scsi_malloc(2048+512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
+	if (!(raw))
             return -ENOMEM;
 
         while (ra.nframes > 0) {
@@ -789,7 +848,9 @@
             ra.nframes -= 1;
             lba++;
         }
+        spin_lock_irqsave(&io_request_lock, flags);
 	scsi_free(raw,2048+512);
+        spin_unlock_irqrestore(&io_request_lock, flags);
         return rc;
     }
     case BLKRAGET:

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov