[ALSA] seq: set client name in snd_seq_create_kernel_client()
authorClemens Ladisch <clemens@ladisch.de>
Mon, 12 Dec 2005 08:33:37 +0000 (09:33 +0100)
committerJaroslav Kysela <perex@suse.cz>
Tue, 3 Jan 2006 11:30:49 +0000 (12:30 +0100)
All users of snd_seq_create_kernel_client() have to set the client name
anyway, so we can just pass the name as parameter.  This relieves us
from having to muck around with a struct snd_seq_client_info in these
cases.

Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
12 files changed:
include/sound/seq_kernel.h
sound/core/seq/oss/seq_oss_init.c
sound/core/seq/seq_clientmgr.c
sound/core/seq/seq_dummy.c
sound/core/seq/seq_midi.c
sound/core/seq/seq_system.c
sound/core/seq/seq_virmidi.c
sound/drivers/opl3/opl3_seq.c
sound/drivers/opl4/opl4_seq.c
sound/isa/gus/gus_synth.c
sound/pci/trident/trident_synth.c
sound/synth/emux/emux_seq.c

index 77cf57e21489a7fa09e1a2a794f88c04c0fd8616..f023c1b97f8caa93cee30e8ed91f27a270c3b7a1 100644 (file)
@@ -75,7 +75,9 @@ struct snd_seq_port_callback {
 };
 
 /* interface for kernel client */
-int snd_seq_create_kernel_client(struct snd_card *card, int client_index);
+int snd_seq_create_kernel_client(struct snd_card *card, int client_index,
+                                const char *name_fmt, ...)
+       __attribute__ ((format (printf, 3, 4)));
 int snd_seq_delete_kernel_client(int client);
 int snd_seq_kernel_client_enqueue(int client, struct snd_seq_event *ev, int atomic, int hop);
 int snd_seq_kernel_client_dispatch(int client, struct snd_seq_event *ev, int atomic, int hop);
index cd4139adec0be6426a9a98e7afd682ffb9aea2eb..ca5a2ed4d7c3a669315c6dc926813e28d38306d8 100644 (file)
@@ -65,33 +65,24 @@ int __init
 snd_seq_oss_create_client(void)
 {
        int rc;
-       struct snd_seq_client_info *info;
        struct snd_seq_port_info *port;
        struct snd_seq_port_callback port_callback;
 
-       info = kmalloc(sizeof(*info), GFP_KERNEL);
        port = kmalloc(sizeof(*port), GFP_KERNEL);
-       if (!info || !port) {
+       if (!port) {
                rc = -ENOMEM;
                goto __error;
        }
 
        /* create ALSA client */
-       rc = snd_seq_create_kernel_client(NULL, SNDRV_SEQ_CLIENT_OSS);
+       rc = snd_seq_create_kernel_client(NULL, SNDRV_SEQ_CLIENT_OSS,
+                                         "OSS sequencer");
        if (rc < 0)
                goto __error;
 
        system_client = rc;
        debug_printk(("new client = %d\n", rc));
 
-       /* set client information */
-       memset(info, 0, sizeof(*info));
-       info->client = system_client;
-       info->type = KERNEL_CLIENT;
-       strcpy(info->name, "OSS sequencer");
-
-       rc = call_ctl(SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, info);
-
        /* look up midi devices */
        snd_seq_oss_midi_lookup_ports(system_client);
 
@@ -124,7 +115,6 @@ snd_seq_oss_create_client(void)
 
  __error:
        kfree(port);
-       kfree(info);
        return rc;
 }
 
index bd8c0989785f38500f5b6ffc0881a2be12435c32..606d076f72f49083771d9b538b32bacdee81e527 100644 (file)
@@ -2212,9 +2212,11 @@ static long snd_seq_ioctl(struct file *file, unsigned int cmd, unsigned long arg
 
 
 /* exported to kernel modules */
-int snd_seq_create_kernel_client(struct snd_card *card, int client_index)
+int snd_seq_create_kernel_client(struct snd_card *card, int client_index,
+                                const char *name_fmt, ...)
 {
        struct snd_seq_client *client;
+       va_list args;
 
        snd_assert(! in_interrupt(), return -EBUSY);
 
@@ -2244,7 +2246,9 @@ int snd_seq_create_kernel_client(struct snd_card *card, int client_index)
        client->accept_input = 1;
        client->accept_output = 1;
                
-       sprintf(client->name, "Client-%d", client->number);
+       va_start(args, name_fmt);
+       vsnprintf(client->name, sizeof(client->name), name_fmt, args);
+       va_end(args);
 
        client->type = KERNEL_CLIENT;
        up(&register_mutex);
index e7344b6332daf5f8e2214b8e9196e07d38590a6e..2a283a59ea4db15dc744db76d1ffc636d9e51977 100644 (file)
@@ -193,7 +193,6 @@ create_port(int idx, int type)
 static int __init
 register_client(void)
 {
-       struct snd_seq_client_info cinfo;
        struct snd_seq_dummy_port *rec1, *rec2;
        int i;
 
@@ -203,17 +202,11 @@ register_client(void)
        }
 
        /* create client */
-       my_client = snd_seq_create_kernel_client(NULL, SNDRV_SEQ_CLIENT_DUMMY);
+       my_client = snd_seq_create_kernel_client(NULL, SNDRV_SEQ_CLIENT_DUMMY,
+                                                "Midi Through");
        if (my_client < 0)
                return my_client;
 
-       /* set client name */
-       memset(&cinfo, 0, sizeof(cinfo));
-       cinfo.client = my_client;
-       cinfo.type = KERNEL_CLIENT;
-       strcpy(cinfo.name, "Midi Through");
-       snd_seq_kernel_client_ctl(my_client, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, &cinfo);
-
        /* create ports */
        for (i = 0; i < ports; i++) {
                rec1 = create_port(i, 0);
index 512ffddd158c3dac03782301340ea26ade7eaab0..ce0df86157de683ca9b9b49acce39458dbf57ed4 100644 (file)
@@ -270,21 +270,6 @@ static void snd_seq_midisynth_delete(struct seq_midisynth *msynth)
                snd_midi_event_free(msynth->parser);
 }
 
-/* set our client name */
-static int set_client_name(struct seq_midisynth_client *client, struct snd_card *card,
-                          struct snd_rawmidi_info *rmidi)
-{
-       struct snd_seq_client_info cinfo;
-       const char *name;
-
-       memset(&cinfo, 0, sizeof(cinfo));
-       cinfo.client = client->seq_client;
-       cinfo.type = KERNEL_CLIENT;
-       name = rmidi->name[0] ? (const char *)rmidi->name : "External MIDI";
-       strlcpy(cinfo.name, name, sizeof(cinfo.name));
-       return snd_seq_kernel_client_ctl(client->seq_client, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, &cinfo);
-}
-
 /* register new midi synth port */
 static int
 snd_seq_midisynth_register_port(struct snd_seq_device *dev)
@@ -333,16 +318,17 @@ snd_seq_midisynth_register_port(struct snd_seq_device *dev)
                        kfree(info);
                        return -ENOMEM;
                }
-               client->seq_client = snd_seq_create_kernel_client(card, 0);
+               client->seq_client =
+                       snd_seq_create_kernel_client(
+                               card, 0, "%s", info->name[0] ?
+                               (const char *)info->name : "External MIDI");
                if (client->seq_client < 0) {
                        kfree(client);
                        up(&register_mutex);
                        kfree(info);
                        return -ENOMEM;
                }
-               set_client_name(client, card, info);
-       } else if (device == 0)
-               set_client_name(client, card, info); /* use the first device's name */
+       }
 
        msynth = kcalloc(ports, sizeof(struct seq_midisynth), GFP_KERNEL);
        port = kmalloc(sizeof(*port), GFP_KERNEL);
index c87c883bd92d15163c4c9de430e48ed54f7888dd..b201b76e9412b58b9761f4fdf3bbf2e30bbffc3a 100644 (file)
@@ -121,29 +121,18 @@ static int event_input_timer(struct snd_seq_event * ev, int direct, void *privat
 int __init snd_seq_system_client_init(void)
 {
        struct snd_seq_port_callback pcallbacks;
-       struct snd_seq_client_info *inf;
        struct snd_seq_port_info *port;
 
-       inf = kzalloc(sizeof(*inf), GFP_KERNEL);
        port = kzalloc(sizeof(*port), GFP_KERNEL);
-       if (! inf || ! port) {
-               kfree(inf);
-               kfree(port);
+       if (!port)
                return -ENOMEM;
-       }
 
        memset(&pcallbacks, 0, sizeof(pcallbacks));
        pcallbacks.owner = THIS_MODULE;
        pcallbacks.event_input = event_input_timer;
 
        /* register client */
-       sysclient = snd_seq_create_kernel_client(NULL, 0);
-
-       /* set our name */
-       inf->client = 0;
-       inf->type = KERNEL_CLIENT;
-       strcpy(inf->name, "System");
-       snd_seq_kernel_client_ctl(sysclient, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, inf);
+       sysclient = snd_seq_create_kernel_client(NULL, 0, "System");
 
        /* register timer */
        strcpy(port->name, "Timer");
@@ -167,7 +156,6 @@ int __init snd_seq_system_client_init(void)
        snd_seq_kernel_client_ctl(sysclient, SNDRV_SEQ_IOCTL_CREATE_PORT, port);
        announce_port = port->addr.port;
 
-       kfree(inf);
        kfree(port);
        return 0;
 }
index 2739f577257853ceb6a77856e15ca430b10503ca..14fd1a608e14ffcbde41136d4f738fad3da97aac 100644 (file)
@@ -360,34 +360,28 @@ static int snd_virmidi_dev_attach_seq(struct snd_virmidi_dev *rdev)
 {
        int client;
        struct snd_seq_port_callback pcallbacks;
-       struct snd_seq_client_info *info;
        struct snd_seq_port_info *pinfo;
        int err;
 
        if (rdev->client >= 0)
                return 0;
 
-       info = kmalloc(sizeof(*info), GFP_KERNEL);
        pinfo = kmalloc(sizeof(*pinfo), GFP_KERNEL);
-       if (! info || ! pinfo) {
+       if (!pinfo) {
                err = -ENOMEM;
                goto __error;
        }
 
-       client = snd_seq_create_kernel_client(rdev->card, rdev->device);
+       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;
 
-       /* 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);
-
        /* create a port */
        memset(pinfo, 0, sizeof(*pinfo));
        pinfo->addr.client = client;
@@ -418,7 +412,6 @@ static int snd_virmidi_dev_attach_seq(struct snd_virmidi_dev *rdev)
        err = 0; /* success */
 
  __error:
-       kfree(info);
        kfree(pinfo);
        return err;
 }
index 582ff63e784bee00e3f182ede650dcb95c193b0b..c4ead790008a32ac66c3b35eff538f6dabae1fa8 100644 (file)
@@ -219,7 +219,7 @@ static int snd_opl3_seq_new_device(struct snd_seq_device *dev)
 {
        struct snd_opl3 *opl3;
        int client;
-       struct snd_seq_client_info cinfo;
+       char name[32];
        int opl_ver;
 
        opl3 = *(struct snd_opl3 **)SNDRV_SEQ_DEVICE_ARGPTR(dev);
@@ -231,19 +231,14 @@ static int snd_opl3_seq_new_device(struct snd_seq_device *dev)
        opl3->seq_client = -1;
 
        /* allocate new client */
+       opl_ver = (opl3->hardware & OPL3_HW_MASK) >> 8;
+       sprintf(name, "OPL%i FM synth", opl_ver);
        client = opl3->seq_client =
-               snd_seq_create_kernel_client(opl3->card, opl3->seq_dev_num);
+               snd_seq_create_kernel_client(opl3->card, opl3->seq_dev_num,
+                                            name);
        if (client < 0)
                return client;
 
-       /* change name of client */
-       memset(&cinfo, 0, sizeof(cinfo));
-       cinfo.client = client;
-       cinfo.type = KERNEL_CLIENT;
-       opl_ver = (opl3->hardware & OPL3_HW_MASK) >> 8;
-       sprintf(cinfo.name, "OPL%i FM synth", opl_ver);
-       snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, &cinfo);
-
        snd_opl3_synth_create_port(opl3);
 
        /* initialize instrument list */
@@ -264,7 +259,7 @@ static int snd_opl3_seq_new_device(struct snd_seq_device *dev)
        opl3->sys_timer_status = 0;
 
 #ifdef CONFIG_SND_SEQUENCER_OSS
-       snd_opl3_init_seq_oss(opl3, cinfo.name);
+       snd_opl3_init_seq_oss(opl3, name);
 #endif
        return 0;
 }
index a69117dd0071eb26efeda0170f82f3debf014f97..e3480326e735a115916a1490627e08d9574edade 100644 (file)
@@ -127,7 +127,6 @@ static int snd_opl4_seq_new_device(struct snd_seq_device *dev)
 {
        struct snd_opl4 *opl4;
        int client;
-       struct snd_seq_client_info cinfo;
        struct snd_seq_port_callback pcallbacks;
 
        opl4 = *(struct snd_opl4 **)SNDRV_SEQ_DEVICE_ARGPTR(dev);
@@ -143,7 +142,8 @@ static int snd_opl4_seq_new_device(struct snd_seq_device *dev)
        opl4->chset->private_data = opl4;
 
        /* allocate new client */
-       client = snd_seq_create_kernel_client(opl4->card, opl4->seq_dev_num);
+       client = snd_seq_create_kernel_client(opl4->card, opl4->seq_dev_num,
+                                             "OPL4 Wavetable");
        if (client < 0) {
                snd_midi_channel_free_set(opl4->chset);
                return client;
@@ -151,13 +151,6 @@ static int snd_opl4_seq_new_device(struct snd_seq_device *dev)
        opl4->seq_client = client;
        opl4->chset->client = client;
 
-       /* change name of client */
-       memset(&cinfo, 0, sizeof(cinfo));
-       cinfo.client = client;
-       cinfo.type = KERNEL_CLIENT;
-       strcpy(cinfo.name, "OPL4 Wavetable");
-       snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, &cinfo);
-
        /* create new port */
        memset(&pcallbacks, 0, sizeof(pcallbacks));
        pcallbacks.owner = THIS_MODULE;
index 6464488363e4f9485ea809559a845b59cf0f67a1..85a1b051f09a4f1010d61a1fce26236f4fab4719 100644 (file)
@@ -214,7 +214,6 @@ static int snd_gus_synth_new_device(struct snd_seq_device *dev)
 {
        struct snd_gus_card *gus;
        int client, i;
-       struct snd_seq_client_info *cinfo;
        struct snd_seq_port_subscribe sub;
        struct snd_iwffff_ops *iwops;
        struct snd_gf1_ops *gf1ops;
@@ -227,25 +226,12 @@ static int snd_gus_synth_new_device(struct snd_seq_device *dev)
        init_MUTEX(&gus->register_mutex);
        gus->gf1.seq_client = -1;
        
-       cinfo = kmalloc(sizeof(*cinfo), GFP_KERNEL);
-       if (! cinfo)
-               return -ENOMEM;
-
        /* allocate new client */
        client = gus->gf1.seq_client =
-               snd_seq_create_kernel_client(gus->card, 1);
-       if (client < 0) {
-               kfree(cinfo);
+               snd_seq_create_kernel_client(gus->card, 1, gus->interwave ?
+                                            "AMD InterWave" : "GF1");
+       if (client < 0)
                return client;
-       }
-
-       /* change name of client */
-       memset(cinfo, 0, sizeof(*cinfo));
-       cinfo->client = client;
-       cinfo->type = KERNEL_CLIENT;
-       sprintf(cinfo->name, gus->interwave ? "AMD InterWave" : "GF1");
-       snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, cinfo);
-       kfree(cinfo);
 
        for (i = 0; i < 4; i++)
                snd_gus_synth_create_port(gus, i);
index e31055a4bd2549e1957385b1fc43c08b96c2c008..cc7af8bc55a0a0f83f5e30b94534bd4581c67695 100644 (file)
@@ -934,7 +934,6 @@ static int snd_trident_synth_new_device(struct snd_seq_device *dev)
 {
        struct snd_trident *trident;
        int client, i;
-       struct snd_seq_client_info cinfo;
        struct snd_seq_port_subscribe sub;
        struct snd_simple_ops *simpleops;
        char *str;
@@ -946,23 +945,16 @@ static int snd_trident_synth_new_device(struct snd_seq_device *dev)
        trident->synth.seq_client = -1;
 
        /* allocate new client */
-       client = trident->synth.seq_client =
-               snd_seq_create_kernel_client(trident->card, 1);
-       if (client < 0)
-               return client;
-
-       /* change name of client */
-       memset(&cinfo, 0, sizeof(cinfo));
-       cinfo.client = client;
-       cinfo.type = KERNEL_CLIENT;
        str = "???";
        switch (trident->device) {
        case TRIDENT_DEVICE_ID_DX:      str = "Trident 4DWave-DX"; break;
        case TRIDENT_DEVICE_ID_NX:      str = "Trident 4DWave-NX"; break;
        case TRIDENT_DEVICE_ID_SI7018:  str = "SiS 7018"; break;
        }
-       sprintf(cinfo.name, str);
-       snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, &cinfo);
+       client = trident->synth.seq_client =
+               snd_seq_create_kernel_client(trident->card, 1, str);
+       if (client < 0)
+               return client;
 
        for (i = 0; i < 4; i++)
                snd_trident_synth_create_port(trident, i);
index b7129c5aee06c400bbbf2bdc66deab910e0710e6..1a973d7a90f8a302fd453f9c808597a9a41dd75f 100644 (file)
@@ -28,7 +28,6 @@ static void free_port(void *private);
 static void snd_emux_init_port(struct snd_emux_port *p);
 static int snd_emux_use(void *private_data, struct snd_seq_port_subscribe *info);
 static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *info);
-static int get_client(struct snd_card *card, int index, char *name);
 
 /*
  * MIDI emulation operators
@@ -71,8 +70,8 @@ snd_emux_init_seq(struct snd_emux *emu, struct snd_card *card, int index)
        struct snd_seq_port_callback pinfo;
        char tmpname[64];
 
-       sprintf(tmpname, "%s WaveTable", emu->name);
-       emu->client = get_client(card, index, tmpname);
+       emu->client = snd_seq_create_kernel_client(card, index,
+                                                  "%s WaveTable", emu->name);
        if (emu->client < 0) {
                snd_printk("can't create client\n");
                return -ENODEV;
@@ -341,30 +340,6 @@ snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *info)
 }
 
 
-/*
- * Create a sequencer client
- */
-static int
-get_client(struct snd_card *card, int index, char *name)
-{
-       struct snd_seq_client_info cinfo;
-       int client;
-
-       /* Find a free client, start from 1 as the MPU expects to use 0 */
-       client = snd_seq_create_kernel_client(card, index);
-       if (client < 0)
-               return client;
-
-       memset(&cinfo, 0, sizeof(cinfo));
-       cinfo.client = client;
-       cinfo.type = KERNEL_CLIENT;
-       strcpy(cinfo.name, name);
-       snd_seq_kernel_client_ctl(client, SNDRV_SEQ_IOCTL_SET_CLIENT_INFO, &cinfo);
-
-       return client;
-}
-
-
 /*
  * attach virtual rawmidi devices
  */