patch-2.1.77 linux/drivers/sound/softoss.c

Next file: linux/drivers/sound/sound_calls.h
Previous file: linux/drivers/sound/sequencer.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.76/linux/drivers/sound/softoss.c linux/drivers/sound/softoss.c
@@ -10,6 +10,9 @@
  * Version 2 (June 1991). See the "COPYING" file distributed with this software
  * for more info.
  */
+/*
+ * Thomas Sailer   : ioctl code reworked (vmalloc/vfree removed)
+ */
 #include <linux/config.h>
 #include <linux/module.h>
 
@@ -114,6 +117,7 @@
 static volatile int tmr_running = 0;
 static int      voice_limit = 24;
 
+
 static void
 set_max_voices(int nr)
 {
@@ -662,10 +666,11 @@
 }
 #endif
 
-static void
-start_engine(softsyn_devc * devc)
+static void start_engine(softsyn_devc * devc)
 {
 	struct dma_buffparms *dmap;
+	int trig, n;
+	mm_segment_t fs;
 
 	if (!devc->audio_opened)
 		if (softsyn_open(devc->synthdev, 0) < 0)
@@ -673,46 +678,37 @@
 
 	if (devc->audiodev >= num_audiodevs)
 		return;
-
+	
 	dmap = audio_devs[devc->audiodev]->dmap_out;
-
+	
 	devc->usecs = 0;
 	devc->next_event_usecs = ~0;
 	devc->control_rate = 64;
 	devc->control_counter = 0;
 
-	if (devc->engine_state == ES_STOPPED)
-	  {
-		  int             trig, n = 0;
-
-		  trig = 0;
-		  dma_ioctl(devc->audiodev, SNDCTL_DSP_SETTRIGGER, (caddr_t) & trig);
+	if (devc->engine_state == ES_STOPPED) {
+		n = trig = 0;
+		fs = get_fs();
+		set_fs(get_ds());
+		dma_ioctl(devc->audiodev, SNDCTL_DSP_SETTRIGGER, (caddr_t)&trig);
 #ifdef POLLED_MODE
-		  ;
-
-		  {
-			  poll_timer.expires = (1) + jiffies;
-			  add_timer(&poll_timer);
-		  };		/* Start polling */
+		poll_timer.expires = (1) + jiffies;
+		add_timer(&poll_timer);
+		/* Start polling */
 #else
-		  dmap->audio_callback = softsyn_callback;
-		  dmap->qhead = dmap->qtail = dmap->qlen = 0;
+		dmap->audio_callback = softsyn_callback;
+		dmap->qhead = dmap->qtail = dmap->qlen = 0;
 #endif
-
-		  while (dmap->qlen < devc->max_playahead && n++ < 2)
-			  do_resample(0);
-
-		  devc->engine_state = ES_STARTED;
-		  last_resample_jiffies = jiffies;
-		  resample_counter = 0;
-
-		  trig = PCM_ENABLE_OUTPUT;
-		  if (dma_ioctl(devc->audiodev, SNDCTL_DSP_SETTRIGGER,
-				(caddr_t) & trig) < 0)
-		    {
-			    printk("SoftOSS: Trigger failed\n");
-		    }
-	  }
+		while (dmap->qlen < devc->max_playahead && n++ < 2)
+			do_resample(0);
+		devc->engine_state = ES_STARTED;
+		last_resample_jiffies = jiffies;
+		resample_counter = 0;
+		trig = PCM_ENABLE_OUTPUT;
+		if (dma_ioctl(devc->audiodev, SNDCTL_DSP_SETTRIGGER, (caddr_t)&trig) < 0)
+			printk(KERN_ERR "SoftOSS: Trigger failed\n");
+		set_fs(fs);
+	}
 }
 
 static void
@@ -760,34 +756,25 @@
 	return 0;
 }
 
-static int
-softsyn_ioctl(int dev,
-	      unsigned int cmd, caddr_t arg)
+static int softsyn_ioctl(int dev, unsigned int cmd, caddr_t arg)
 {
-	switch (cmd)
-	  {
-
-	  case SNDCTL_SYNTH_INFO:
-		  softsyn_info.nr_voices = devc->maxvoice;
-
-		  memcpy((&((char *) arg)[0]), (char *) &softsyn_info, sizeof(softsyn_info));
-		  return 0;
-		  break;
-
-	  case SNDCTL_SEQ_RESETSAMPLES:
-		  stop_engine(devc);
-		  reset_samples(devc);
-		  return 0;
-		  break;
-
-	  case SNDCTL_SYNTH_MEMAVL:
-		  return devc->ram_size - devc->ram_used;
-		  break;
+	switch (cmd) {
 
-	  default:
-		  return -EINVAL;
-	  }
+	case SNDCTL_SYNTH_INFO:
+		softsyn_info.nr_voices = devc->maxvoice;
+		return __copy_to_user(arg, &softsyn_info, sizeof(softsyn_info));
 
+	case SNDCTL_SEQ_RESETSAMPLES:
+		stop_engine(devc);
+		reset_samples(devc);
+		return 0;
+		  
+	case SNDCTL_SYNTH_MEMAVL:
+		return devc->ram_size - devc->ram_used;
+
+	default:
+		return -EINVAL;
+	}
 }
 
 static int
@@ -994,12 +981,12 @@
 	return 0;
 }
 
-static int
-softsyn_open(int synthdev, int mode)
+static int softsyn_open(int synthdev, int mode)
 {
 	int             err;
 	extern int      softoss_dev;
 	int             frags = 0x7fff0007;	/* fragment size of 128 bytes */
+	mm_segment_t fs;
 
 	if (devc->audio_opened)	/* Already opened */
 		return 0;
@@ -1035,8 +1022,11 @@
 
 	DDB(printk("SoftOSS: Using audio dev %d, speed %d, bits %d, channels %d\n", devc->audiodev, devc->speed, devc->bits, devc->channels));
 
+	fs = get_fs();
+	set_fs(get_ds());
 	dma_ioctl(devc->audiodev, SNDCTL_DSP_SETFRAGMENT, (caddr_t) & frags);
 	dma_ioctl(devc->audiodev, SNDCTL_DSP_GETBLKSIZE, (caddr_t) & devc->fragsize);
+	set_fs(fs);
 
 	if (devc->bits != 16 || devc->channels != 2)
 	  {
@@ -1055,14 +1045,18 @@
 	return 0;
 }
 
-static void
-softsyn_close(int synthdev)
+static void softsyn_close(int synthdev)
 {
+	mm_segment_t fs;
+
 	devc->engine_state = ES_STOPPED;
 #ifdef POLLED_MODE
-	del_timer(&poll_timer);;
+	del_timer(&poll_timer);
 #endif
+	fs = get_fs();
+	set_fs(get_ds());
 	dma_ioctl(devc->audiodev, SNDCTL_DSP_RESET, 0);
+	set_fs(fs);
 	if (devc->audio_opened)
 		audio_release((devc->audiodev << 4) | SND_DEV_DSP16, &devc->finfo);
 	devc->audio_opened = 0;

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