mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-16 00:34:20 +08:00
292a089d78
Due to several bugs caused by timers being re-armed after they are shutdown and just before they are freed, a new state of timers was added called "shutdown". After a timer is set to this state, then it can no longer be re-armed. The following script was run to find all the trivial locations where del_timer() or del_timer_sync() is called in the same function that the object holding the timer is freed. It also ignores any locations where the timer->function is modified between the del_timer*() and the free(), as that is not considered a "trivial" case. This was created by using a coccinelle script and the following commands: $ cat timer.cocci @@ expression ptr, slab; identifier timer, rfield; @@ ( - del_timer(&ptr->timer); + timer_shutdown(&ptr->timer); | - del_timer_sync(&ptr->timer); + timer_shutdown_sync(&ptr->timer); ) ... when strict when != ptr->timer ( kfree_rcu(ptr, rfield); | kmem_cache_free(slab, ptr); | kfree(ptr); ) $ spatch timer.cocci . > /tmp/t.patch $ patch -p1 < /tmp/t.patch Link: https://lore.kernel.org/lkml/20221123201306.823305113@linutronix.de/ Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Acked-by: Pavel Machek <pavel@ucw.cz> [ LED ] Acked-by: Kalle Valo <kvalo@kernel.org> [ wireless ] Acked-by: Paolo Abeni <pabeni@redhat.com> [ networking ] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
149 lines
3.2 KiB
C
149 lines
3.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* Copyright (C) 2000 Takashi Iwai <tiwai@suse.de>
|
|
*
|
|
* Routines for control of EMU WaveTable chip
|
|
*/
|
|
|
|
#include <linux/wait.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/string.h>
|
|
#include <sound/core.h>
|
|
#include <sound/emux_synth.h>
|
|
#include <linux/init.h>
|
|
#include <linux/module.h>
|
|
#include "emux_voice.h"
|
|
|
|
MODULE_AUTHOR("Takashi Iwai");
|
|
MODULE_DESCRIPTION("Routines for control of EMU WaveTable chip");
|
|
MODULE_LICENSE("GPL");
|
|
|
|
/*
|
|
* create a new hardware dependent device for Emu8000/Emu10k1
|
|
*/
|
|
int snd_emux_new(struct snd_emux **remu)
|
|
{
|
|
struct snd_emux *emu;
|
|
|
|
*remu = NULL;
|
|
emu = kzalloc(sizeof(*emu), GFP_KERNEL);
|
|
if (emu == NULL)
|
|
return -ENOMEM;
|
|
|
|
spin_lock_init(&emu->voice_lock);
|
|
mutex_init(&emu->register_mutex);
|
|
|
|
emu->client = -1;
|
|
#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
|
|
emu->oss_synth = NULL;
|
|
#endif
|
|
emu->max_voices = 0;
|
|
emu->use_time = 0;
|
|
|
|
timer_setup(&emu->tlist, snd_emux_timer_callback, 0);
|
|
emu->timer_active = 0;
|
|
|
|
*remu = emu;
|
|
return 0;
|
|
}
|
|
|
|
EXPORT_SYMBOL(snd_emux_new);
|
|
|
|
/*
|
|
*/
|
|
static int sf_sample_new(void *private_data, struct snd_sf_sample *sp,
|
|
struct snd_util_memhdr *hdr,
|
|
const void __user *buf, long count)
|
|
{
|
|
struct snd_emux *emu = private_data;
|
|
return emu->ops.sample_new(emu, sp, hdr, buf, count);
|
|
|
|
}
|
|
|
|
static int sf_sample_free(void *private_data, struct snd_sf_sample *sp,
|
|
struct snd_util_memhdr *hdr)
|
|
{
|
|
struct snd_emux *emu = private_data;
|
|
return emu->ops.sample_free(emu, sp, hdr);
|
|
|
|
}
|
|
|
|
static void sf_sample_reset(void *private_data)
|
|
{
|
|
struct snd_emux *emu = private_data;
|
|
emu->ops.sample_reset(emu);
|
|
}
|
|
|
|
int snd_emux_register(struct snd_emux *emu, struct snd_card *card, int index, char *name)
|
|
{
|
|
int err;
|
|
struct snd_sf_callback sf_cb;
|
|
|
|
if (snd_BUG_ON(!emu->hw || emu->max_voices <= 0))
|
|
return -EINVAL;
|
|
if (snd_BUG_ON(!card || !name))
|
|
return -EINVAL;
|
|
|
|
emu->card = card;
|
|
emu->name = kstrdup(name, GFP_KERNEL);
|
|
emu->voices = kcalloc(emu->max_voices, sizeof(struct snd_emux_voice),
|
|
GFP_KERNEL);
|
|
if (emu->name == NULL || emu->voices == NULL)
|
|
return -ENOMEM;
|
|
|
|
/* create soundfont list */
|
|
memset(&sf_cb, 0, sizeof(sf_cb));
|
|
sf_cb.private_data = emu;
|
|
if (emu->ops.sample_new)
|
|
sf_cb.sample_new = sf_sample_new;
|
|
if (emu->ops.sample_free)
|
|
sf_cb.sample_free = sf_sample_free;
|
|
if (emu->ops.sample_reset)
|
|
sf_cb.sample_reset = sf_sample_reset;
|
|
emu->sflist = snd_sf_new(&sf_cb, emu->memhdr);
|
|
if (emu->sflist == NULL)
|
|
return -ENOMEM;
|
|
|
|
err = snd_emux_init_hwdep(emu);
|
|
if (err < 0)
|
|
return err;
|
|
|
|
snd_emux_init_voices(emu);
|
|
|
|
snd_emux_init_seq(emu, card, index);
|
|
#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
|
|
snd_emux_init_seq_oss(emu);
|
|
#endif
|
|
snd_emux_init_virmidi(emu, card);
|
|
|
|
snd_emux_proc_init(emu, card, index);
|
|
return 0;
|
|
}
|
|
|
|
EXPORT_SYMBOL(snd_emux_register);
|
|
|
|
/*
|
|
*/
|
|
int snd_emux_free(struct snd_emux *emu)
|
|
{
|
|
if (! emu)
|
|
return -EINVAL;
|
|
|
|
timer_shutdown_sync(&emu->tlist);
|
|
|
|
snd_emux_proc_free(emu);
|
|
snd_emux_delete_virmidi(emu);
|
|
#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
|
|
snd_emux_detach_seq_oss(emu);
|
|
#endif
|
|
snd_emux_detach_seq(emu);
|
|
snd_emux_delete_hwdep(emu);
|
|
snd_sf_free(emu->sflist);
|
|
kfree(emu->voices);
|
|
kfree(emu->name);
|
|
kfree(emu);
|
|
return 0;
|
|
}
|
|
|
|
EXPORT_SYMBOL(snd_emux_free);
|