Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / sound / core / seq / seq_virmidi.c
index c493a65..f4edec6 100644 (file)
@@ -56,7 +56,8 @@ MODULE_LICENSE("GPL");
 /*
  * initialize an event record
  */
-static void snd_virmidi_init_event(snd_virmidi_t *vmidi, snd_seq_event_t *ev)
+static void snd_virmidi_init_event(struct snd_virmidi *vmidi,
+                                  struct snd_seq_event *ev)
 {
        memset(ev, 0, sizeof(*ev));
        ev->source.port = vmidi->port;
@@ -76,16 +77,17 @@ static void snd_virmidi_init_event(snd_virmidi_t *vmidi, snd_seq_event_t *ev)
 /*
  * decode input event and put to read buffer of each opened file
  */
-static int snd_virmidi_dev_receive_event(snd_virmidi_dev_t *rdev, snd_seq_event_t *ev)
+static int snd_virmidi_dev_receive_event(struct snd_virmidi_dev *rdev,
+                                        struct snd_seq_event *ev)
 {
-       snd_virmidi_t *vmidi;
+       struct snd_virmidi *vmidi;
        struct list_head *list;
        unsigned char msg[4];
        int len;
 
        read_lock(&rdev->filelist_lock);
        list_for_each(list, &rdev->filelist) {
-               vmidi = list_entry(list, snd_virmidi_t, list);
+               vmidi = list_entry(list, struct snd_virmidi, list);
                if (!vmidi->trigger)
                        continue;
                if (ev->type == SNDRV_SEQ_EVENT_SYSEX) {
@@ -110,24 +112,25 @@ static int snd_virmidi_dev_receive_event(snd_virmidi_dev_t *rdev, snd_seq_event_
  * handler of a remote port which is attached to the virmidi via
  * SNDRV_VIRMIDI_SEQ_ATTACH.
  */
-/* exported */
-int snd_virmidi_receive(snd_rawmidi_t *rmidi, snd_seq_event_t *ev)
+#if 0
+int snd_virmidi_receive(struct snd_rawmidi *rmidi, struct snd_seq_event *ev)
 {
-       snd_virmidi_dev_t *rdev;
+       struct snd_virmidi_dev *rdev;
 
-       rdev = snd_magic_cast(snd_virmidi_dev_t, rmidi->private_data, return -EINVAL);
+       rdev = rmidi->private_data;
        return snd_virmidi_dev_receive_event(rdev, ev);
 }
+#endif  /*  0  */
 
 /*
  * event handler of virmidi port
  */
-static int snd_virmidi_event_input(snd_seq_event_t *ev, int direct,
+static int snd_virmidi_event_input(struct snd_seq_event *ev, int direct,
                                   void *private_data, int atomic, int hop)
 {
-       snd_virmidi_dev_t *rdev;
+       struct snd_virmidi_dev *rdev;
 
-       rdev = snd_magic_cast(snd_virmidi_dev_t, private_data, return -EINVAL);
+       rdev = private_data;
        if (!(rdev->flags & SNDRV_VIRMIDI_USE))
                return 0; /* ignored */
        return snd_virmidi_dev_receive_event(rdev, ev);
@@ -136,9 +139,9 @@ static int snd_virmidi_event_input(snd_seq_event_t *ev, int direct,
 /*
  * trigger rawmidi stream for input
  */
-static void snd_virmidi_input_trigger(snd_rawmidi_substream_t * substream, int up)
+static void snd_virmidi_input_trigger(struct snd_rawmidi_substream *substream, int up)
 {
-       snd_virmidi_t *vmidi = snd_magic_cast(snd_virmidi_t, substream->runtime->private_data, return);
+       struct snd_virmidi *vmidi = substream->runtime->private_data;
 
        if (up) {
                vmidi->trigger = 1;
@@ -150,9 +153,9 @@ static void snd_virmidi_input_trigger(snd_rawmidi_substream_t * substream, int u
 /*
  * trigger rawmidi stream for output
  */
-static void snd_virmidi_output_trigger(snd_rawmidi_substream_t * substream, int up)
+static void snd_virmidi_output_trigger(struct snd_rawmidi_substream *substream, int up)
 {
-       snd_virmidi_t *vmidi = snd_magic_cast(snd_virmidi_t, substream->runtime->private_data, return);
+       struct snd_virmidi *vmidi = substream->runtime->private_data;
        int count, res;
        unsigned char buf[32], *pbuf;
 
@@ -164,7 +167,7 @@ static void snd_virmidi_output_trigger(snd_rawmidi_substream_t * substream, int
                        return;         /* ignored */
                }
                if (vmidi->event.type != SNDRV_SEQ_EVENT_NONE) {
-                       if (snd_seq_kernel_client_dispatch(vmidi->client, &vmidi->event, 0, 0) < 0)
+                       if (snd_seq_kernel_client_dispatch(vmidi->client, &vmidi->event, in_atomic(), 0) < 0)
                                return;
                        vmidi->event.type = SNDRV_SEQ_EVENT_NONE;
                }
@@ -183,7 +186,7 @@ static void snd_virmidi_output_trigger(snd_rawmidi_substream_t * substream, int
                                pbuf += res;
                                count -= res;
                                if (vmidi->event.type != SNDRV_SEQ_EVENT_NONE) {
-                                       if (snd_seq_kernel_client_dispatch(vmidi->client, &vmidi->event, 0, 0) < 0)
+                                       if (snd_seq_kernel_client_dispatch(vmidi->client, &vmidi->event, in_atomic(), 0) < 0)
                                                return;
                                        vmidi->event.type = SNDRV_SEQ_EVENT_NONE;
                                }
@@ -197,19 +200,19 @@ static void snd_virmidi_output_trigger(snd_rawmidi_substream_t * substream, int
 /*
  * open rawmidi handle for input
  */
-static int snd_virmidi_input_open(snd_rawmidi_substream_t * substream)
+static int snd_virmidi_input_open(struct snd_rawmidi_substream *substream)
 {
-       snd_virmidi_dev_t *rdev = snd_magic_cast(snd_virmidi_dev_t, substream->rmidi->private_data, return -EINVAL);
-       snd_rawmidi_runtime_t *runtime = substream->runtime;
-       snd_virmidi_t *vmidi;
+       struct snd_virmidi_dev *rdev = substream->rmidi->private_data;
+       struct snd_rawmidi_runtime *runtime = substream->runtime;
+       struct snd_virmidi *vmidi;
        unsigned long flags;
 
-       vmidi = snd_magic_kcalloc(snd_virmidi_t, 0, GFP_KERNEL);
+       vmidi = kzalloc(sizeof(*vmidi), GFP_KERNEL);
        if (vmidi == NULL)
                return -ENOMEM;
        vmidi->substream = substream;
        if (snd_midi_event_new(0, &vmidi->parser) < 0) {
-               snd_magic_kfree(vmidi);
+               kfree(vmidi);
                return -ENOMEM;
        }
        vmidi->seq_mode = rdev->seq_mode;
@@ -226,18 +229,18 @@ static int snd_virmidi_input_open(snd_rawmidi_substream_t * substream)
 /*
  * open rawmidi handle for output
  */
-static int snd_virmidi_output_open(snd_rawmidi_substream_t * substream)
+static int snd_virmidi_output_open(struct snd_rawmidi_substream *substream)
 {
-       snd_virmidi_dev_t *rdev = snd_magic_cast(snd_virmidi_dev_t, substream->rmidi->private_data, return -EINVAL);
-       snd_rawmidi_runtime_t *runtime = substream->runtime;
-       snd_virmidi_t *vmidi;
+       struct snd_virmidi_dev *rdev = substream->rmidi->private_data;
+       struct snd_rawmidi_runtime *runtime = substream->runtime;
+       struct snd_virmidi *vmidi;
 
-       vmidi = snd_magic_kcalloc(snd_virmidi_t, 0, GFP_KERNEL);
+       vmidi = kzalloc(sizeof(*vmidi), GFP_KERNEL);
        if (vmidi == NULL)
                return -ENOMEM;
        vmidi->substream = substream;
        if (snd_midi_event_new(MAX_MIDI_EVENT_BUF, &vmidi->parser) < 0) {
-               snd_magic_kfree(vmidi);
+               kfree(vmidi);
                return -ENOMEM;
        }
        vmidi->seq_mode = rdev->seq_mode;
@@ -252,36 +255,37 @@ static int snd_virmidi_output_open(snd_rawmidi_substream_t * substream)
 /*
  * close rawmidi handle for input
  */
-static int snd_virmidi_input_close(snd_rawmidi_substream_t * substream)
+static int snd_virmidi_input_close(struct snd_rawmidi_substream *substream)
 {
-       snd_virmidi_t *vmidi = snd_magic_cast(snd_virmidi_t, substream->runtime->private_data, return -EINVAL);
+       struct snd_virmidi *vmidi = substream->runtime->private_data;
        snd_midi_event_free(vmidi->parser);
        list_del(&vmidi->list);
        substream->runtime->private_data = NULL;
-       snd_magic_kfree(vmidi);
+       kfree(vmidi);
        return 0;
 }
 
 /*
  * close rawmidi handle for output
  */
-static int snd_virmidi_output_close(snd_rawmidi_substream_t * substream)
+static int snd_virmidi_output_close(struct snd_rawmidi_substream *substream)
 {
-       snd_virmidi_t *vmidi = snd_magic_cast(snd_virmidi_t, substream->runtime->private_data, return -EINVAL);
+       struct snd_virmidi *vmidi = substream->runtime->private_data;
        snd_midi_event_free(vmidi->parser);
        substream->runtime->private_data = NULL;
-       snd_magic_kfree(vmidi);
+       kfree(vmidi);
        return 0;
 }
 
 /*
  * subscribe callback - allow output to rawmidi device
  */
-static int snd_virmidi_subscribe(void *private_data, snd_seq_port_subscribe_t *info)
+static int snd_virmidi_subscribe(void *private_data,
+                                struct snd_seq_port_subscribe *info)
 {
-       snd_virmidi_dev_t *rdev;
+       struct snd_virmidi_dev *rdev;
 
-       rdev = snd_magic_cast(snd_virmidi_dev_t, private_data, return -EINVAL);
+       rdev = private_data;
        if (!try_module_get(rdev->card->module))
                return -EFAULT;
        rdev->flags |= SNDRV_VIRMIDI_SUBSCRIBE;
@@ -291,11 +295,12 @@ static int snd_virmidi_subscribe(void *private_data, snd_seq_port_subscribe_t *i
 /*
  * unsubscribe callback - disallow output to rawmidi device
  */
-static int snd_virmidi_unsubscribe(void *private_data, snd_seq_port_subscribe_t *info)
+static int snd_virmidi_unsubscribe(void *private_data,
+                                  struct snd_seq_port_subscribe *info)
 {
-       snd_virmidi_dev_t *rdev;
+       struct snd_virmidi_dev *rdev;
 
-       rdev = snd_magic_cast(snd_virmidi_dev_t, private_data, return -EINVAL);
+       rdev = private_data;
        rdev->flags &= ~SNDRV_VIRMIDI_SUBSCRIBE;
        module_put(rdev->card->module);
        return 0;
@@ -305,11 +310,12 @@ static int snd_virmidi_unsubscribe(void *private_data, snd_seq_port_subscribe_t
 /*
  * use callback - allow input to rawmidi device
  */
-static int snd_virmidi_use(void *private_data, snd_seq_port_subscribe_t *info)
+static int snd_virmidi_use(void *private_data,
+                          struct snd_seq_port_subscribe *info)
 {
-       snd_virmidi_dev_t *rdev;
+       struct snd_virmidi_dev *rdev;
 
-       rdev = snd_magic_cast(snd_virmidi_dev_t, private_data, return -EINVAL);
+       rdev = private_data;
        if (!try_module_get(rdev->card->module))
                return -EFAULT;
        rdev->flags |= SNDRV_VIRMIDI_USE;
@@ -319,11 +325,12 @@ static int snd_virmidi_use(void *private_data, snd_seq_port_subscribe_t *info)
 /*
  * unuse callback - disallow input to rawmidi device
  */
-static int snd_virmidi_unuse(void *private_data, snd_seq_port_subscribe_t *info)
+static int snd_virmidi_unuse(void *private_data,
+                            struct snd_seq_port_subscribe *info)
 {
-       snd_virmidi_dev_t *rdev;
+       struct snd_virmidi_dev *rdev;
 
-       rdev = snd_magic_cast(snd_virmidi_dev_t, private_data, return -EINVAL);
+       rdev = private_data;
        rdev->flags &= ~SNDRV_VIRMIDI_USE;
        module_put(rdev->card->module);
        return 0;
@@ -334,13 +341,13 @@ static int snd_virmidi_unuse(void *private_data, snd_seq_port_subscribe_t *info)
  *  Register functions
  */
 
-static snd_rawmidi_ops_t snd_virmidi_input_ops = {
+static struct snd_rawmidi_ops snd_virmidi_input_ops = {
        .open = snd_virmidi_input_open,
        .close = snd_virmidi_input_close,
        .trigger = snd_virmidi_input_trigger,
 };
 
-static snd_rawmidi_ops_t snd_virmidi_output_ops = {
+static struct snd_rawmidi_ops snd_virmidi_output_ops = {
        .open = snd_virmidi_output_open,
        .close = snd_virmidi_output_close,
        .trigger = snd_virmidi_output_trigger,
@@ -349,44 +356,42 @@ static snd_rawmidi_ops_t snd_virmidi_output_ops = {
 /*
  * create a sequencer client and a port
  */
-static int snd_virmidi_dev_attach_seq(snd_virmidi_dev_t *rdev)
+static int snd_virmidi_dev_attach_seq(struct snd_virmidi_dev *rdev)
 {
        int client;
-       snd_seq_client_callback_t callbacks;
-       snd_seq_port_callback_t pcallbacks;
-       snd_seq_client_info_t info;
-       snd_seq_port_info_t pinfo;
+       struct snd_seq_port_callback pcallbacks;
+       struct snd_seq_port_info *pinfo;
        int err;
 
        if (rdev->client >= 0)
                return 0;
 
-       memset(&callbacks, 0, sizeof(callbacks));
-       callbacks.private_data = rdev;
-       callbacks.allow_input = 1;
-       callbacks.allow_output = 1;
-       client = snd_seq_create_kernel_client(rdev->card, rdev->device, &callbacks);
-       if (client < 0)
-               return client;
-       rdev->client = client;
+       pinfo = kmalloc(sizeof(*pinfo), GFP_KERNEL);
+       if (!pinfo) {
+               err = -ENOMEM;
+               goto __error;
+       }
 
-       /* set client name */
-       memset(&info, 0, sizeof(info));
-       info.client = client;
-       info.type = KERNEL_CLIENT;
-       sprintf(info.name, "%s %d-%d", rdev->rmidi->name, rdev->card->number, rdev->device);
-       snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, &info);
+       client = snd_seq_create_kernel_client(rdev->card, rdev->device,
+                                             "%s %d-%d", rdev->rmidi->name,
+                                             rdev->card->number,
+                                             rdev->device);
+       if (client < 0) {
+               err = client;
+               goto __error;
+       }
+       rdev->client = client;
 
        /* create a port */
-       memset(&pinfo, 0, sizeof(pinfo));
-       pinfo.addr.client = client;
-       sprintf(pinfo.name, "VirMIDI %d-%d", rdev->card->number, rdev->device);
+       memset(pinfo, 0, sizeof(*pinfo));
+       pinfo->addr.client = client;
+       sprintf(pinfo->name, "VirMIDI %d-%d", rdev->card->number, rdev->device);
        /* set all capabilities */
-       pinfo.capability |= SNDRV_SEQ_PORT_CAP_WRITE | SNDRV_SEQ_PORT_CAP_SYNC_WRITE | SNDRV_SEQ_PORT_CAP_SUBS_WRITE;
-       pinfo.capability |= SNDRV_SEQ_PORT_CAP_READ | SNDRV_SEQ_PORT_CAP_SYNC_READ | SNDRV_SEQ_PORT_CAP_SUBS_READ;
-       pinfo.capability |= SNDRV_SEQ_PORT_CAP_DUPLEX;
-       pinfo.type = SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC;
-       pinfo.midi_channels = 16;
+       pinfo->capability |= SNDRV_SEQ_PORT_CAP_WRITE | SNDRV_SEQ_PORT_CAP_SYNC_WRITE | SNDRV_SEQ_PORT_CAP_SUBS_WRITE;
+       pinfo->capability |= SNDRV_SEQ_PORT_CAP_READ | SNDRV_SEQ_PORT_CAP_SYNC_READ | SNDRV_SEQ_PORT_CAP_SUBS_READ;
+       pinfo->capability |= SNDRV_SEQ_PORT_CAP_DUPLEX;
+       pinfo->type = SNDRV_SEQ_PORT_TYPE_MIDI_GENERIC;
+       pinfo->midi_channels = 16;
        memset(&pcallbacks, 0, sizeof(pcallbacks));
        pcallbacks.owner = THIS_MODULE;
        pcallbacks.private_data = rdev;
@@ -395,23 +400,27 @@ static int snd_virmidi_dev_attach_seq(snd_virmidi_dev_t *rdev)
        pcallbacks.use = snd_virmidi_use;
        pcallbacks.unuse = snd_virmidi_unuse;
        pcallbacks.event_input = snd_virmidi_event_input;
-       pinfo.kernel = &pcallbacks;
-       err = snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_CREATE_PORT, &pinfo);
+       pinfo->kernel = &pcallbacks;
+       err = snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_CREATE_PORT, pinfo);
        if (err < 0) {
                snd_seq_delete_kernel_client(client);
                rdev->client = -1;
-               return err;
+               goto __error;
        }
 
-       rdev->port = pinfo.addr.port;
-       return 0;       /* success */
+       rdev->port = pinfo->addr.port;
+       err = 0; /* success */
+
+ __error:
+       kfree(pinfo);
+       return err;
 }
 
 
 /*
  * release the sequencer client
  */
-static void snd_virmidi_dev_detach_seq(snd_virmidi_dev_t *rdev)
+static void snd_virmidi_dev_detach_seq(struct snd_virmidi_dev *rdev)
 {
        if (rdev->client >= 0) {
                snd_seq_delete_kernel_client(rdev->client);
@@ -422,9 +431,9 @@ static void snd_virmidi_dev_detach_seq(snd_virmidi_dev_t *rdev)
 /*
  * register the device
  */
-static int snd_virmidi_dev_register(snd_rawmidi_t *rmidi)
+static int snd_virmidi_dev_register(struct snd_rawmidi *rmidi)
 {
-       snd_virmidi_dev_t *rdev = snd_magic_cast(snd_virmidi_dev_t, rmidi->private_data, return -ENXIO);
+       struct snd_virmidi_dev *rdev = rmidi->private_data;
        int err;
 
        switch (rdev->seq_mode) {
@@ -449,9 +458,9 @@ static int snd_virmidi_dev_register(snd_rawmidi_t *rmidi)
 /*
  * unregister the device
  */
-static int snd_virmidi_dev_unregister(snd_rawmidi_t *rmidi)
+static int snd_virmidi_dev_unregister(struct snd_rawmidi *rmidi)
 {
-       snd_virmidi_dev_t *rdev = snd_magic_cast(snd_virmidi_dev_t, rmidi->private_data, return -ENXIO);
+       struct snd_virmidi_dev *rdev = rmidi->private_data;
 
        if (rdev->seq_mode == SNDRV_VIRMIDI_SEQ_DISPATCH)
                snd_virmidi_dev_detach_seq(rdev);
@@ -461,7 +470,7 @@ static int snd_virmidi_dev_unregister(snd_rawmidi_t *rmidi)
 /*
  *
  */
-static snd_rawmidi_global_ops_t snd_virmidi_global_ops = {
+static struct snd_rawmidi_global_ops snd_virmidi_global_ops = {
        .dev_register = snd_virmidi_dev_register,
        .dev_unregister = snd_virmidi_dev_unregister,
 };
@@ -469,10 +478,10 @@ static snd_rawmidi_global_ops_t snd_virmidi_global_ops = {
 /*
  * free device
  */
-static void snd_virmidi_free(snd_rawmidi_t *rmidi)
+static void snd_virmidi_free(struct snd_rawmidi *rmidi)
 {
-       snd_virmidi_dev_t *rdev = snd_magic_cast(snd_virmidi_dev_t, rmidi->private_data, return);
-       snd_magic_kfree(rdev);
+       struct snd_virmidi_dev *rdev = rmidi->private_data;
+       kfree(rdev);
 }
 
 /*
@@ -480,10 +489,10 @@ static void snd_virmidi_free(snd_rawmidi_t *rmidi)
  *
  */
 /* exported */
-int snd_virmidi_new(snd_card_t *card, int device, snd_rawmidi_t **rrmidi)
+int snd_virmidi_new(struct snd_card *card, int device, struct snd_rawmidi **rrmidi)
 {
-       snd_rawmidi_t *rmidi;
-       snd_virmidi_dev_t *rdev;
+       struct snd_rawmidi *rmidi;
+       struct snd_virmidi_dev *rdev;
        int err;
        
        *rrmidi = NULL;
@@ -493,7 +502,7 @@ int snd_virmidi_new(snd_card_t *card, int device, snd_rawmidi_t **rrmidi)
                                   &rmidi)) < 0)
                return err;
        strcpy(rmidi->name, rmidi->id);
-       rdev = snd_magic_kcalloc(snd_virmidi_dev_t, 0, GFP_KERNEL);
+       rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
        if (rdev == NULL) {
                snd_device_free(card, rmidi);
                return -ENOMEM;
@@ -534,4 +543,3 @@ module_init(alsa_virmidi_init)
 module_exit(alsa_virmidi_exit)
 
 EXPORT_SYMBOL(snd_virmidi_new);
-EXPORT_SYMBOL(snd_virmidi_receive);