ALSA: synth: Save a few bytes of memory when registering a 'snd_emux'
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sat, 20 Jan 2024 09:42:12 +0000 (10:42 +0100)
committerTakashi Iwai <tiwai@suse.de>
Mon, 22 Jan 2024 12:04:22 +0000 (13:04 +0100)
snd_emux_register() calls pass a string literal as the 'name' parameter.

So kstrdup_const() can be used instead of kfree() to avoid a memory
allocation in such cases.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/9e7b94c852a25ed4be5382e5e48a7dd77e8d4d1a.1705743706.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/emux_synth.h
sound/synth/emux/emux.c

index 1cc530434b97b4bc1a9996e216f826d1b663dc00..3f7f365ed248cd82c0fd96c0414ccfdc2c4079ae 100644 (file)
@@ -103,7 +103,7 @@ struct snd_emux {
        int ports[SNDRV_EMUX_MAX_PORTS];        /* The ports for this device */
        struct snd_emux_port *portptrs[SNDRV_EMUX_MAX_PORTS];
        int used;       /* use counter */
-       char *name;     /* name of the device (internal) */
+       const char *name;       /* name of the device (internal) */
        struct snd_rawmidi **vmidi;
        struct timer_list tlist;        /* for pending note-offs */
        int timer_active;
index 0006c3ddb51d608bcef2b61d42710003fb88cb2a..a82af937485263d402add34b268cc02137288215 100644 (file)
@@ -85,7 +85,7 @@ int snd_emux_register(struct snd_emux *emu, struct snd_card *card, int index, ch
                return -EINVAL;
 
        emu->card = card;
-       emu->name = kstrdup(name, GFP_KERNEL);
+       emu->name = kstrdup_const(name, GFP_KERNEL);
        emu->voices = kcalloc(emu->max_voices, sizeof(struct snd_emux_voice),
                              GFP_KERNEL);
        if (emu->name == NULL || emu->voices == NULL)
@@ -140,7 +140,7 @@ int snd_emux_free(struct snd_emux *emu)
        snd_emux_delete_hwdep(emu);
        snd_sf_free(emu->sflist);
        kfree(emu->voices);
-       kfree(emu->name);
+       kfree_const(emu->name);
        kfree(emu);
        return 0;
 }