2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* OSS compatible sequencer driver
|
|
|
|
*
|
|
|
|
* synth device handlers
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998,99 Takashi Iwai <tiwai@suse.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "seq_oss_synth.h"
|
|
|
|
#include "seq_oss_midi.h"
|
|
|
|
#include "../seq_lock.h"
|
|
|
|
#include <linux/init.h>
|
2011-07-15 10:38:28 -06:00
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* constants
|
|
|
|
*/
|
|
|
|
#define SNDRV_SEQ_OSS_MAX_SYNTH_NAME 30
|
|
|
|
#define MAX_SYSEX_BUFLEN 128
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* definition of synth info records
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* sysex buffer */
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth_sysex {
|
2005-04-16 16:20:36 -06:00
|
|
|
int len;
|
|
|
|
int skip;
|
|
|
|
unsigned char buf[MAX_SYSEX_BUFLEN];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* synth info */
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth {
|
2005-04-16 16:20:36 -06:00
|
|
|
int seq_device;
|
|
|
|
|
|
|
|
/* for synth_info */
|
|
|
|
int synth_type;
|
|
|
|
int synth_subtype;
|
|
|
|
int nr_voices;
|
|
|
|
|
|
|
|
char name[SNDRV_SEQ_OSS_MAX_SYNTH_NAME];
|
2005-11-17 06:05:16 -07:00
|
|
|
struct snd_seq_oss_callback oper;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
int opened;
|
|
|
|
|
|
|
|
void *private_data;
|
|
|
|
snd_use_lock_t use_lock;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* device table
|
|
|
|
*/
|
|
|
|
static int max_synth_devs;
|
2005-11-17 06:05:16 -07:00
|
|
|
static struct seq_oss_synth *synth_devs[SNDRV_SEQ_OSS_MAX_SYNTH_DEVS];
|
|
|
|
static struct seq_oss_synth midi_synth_dev = {
|
2005-04-16 16:20:36 -06:00
|
|
|
-1, /* seq_device */
|
|
|
|
SYNTH_TYPE_MIDI, /* synth_type */
|
|
|
|
0, /* synth_subtype */
|
|
|
|
16, /* nr_voices */
|
|
|
|
"MIDI", /* name */
|
|
|
|
};
|
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(register_lock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* prototypes
|
|
|
|
*/
|
2005-11-17 06:05:16 -07:00
|
|
|
static struct seq_oss_synth *get_synthdev(struct seq_oss_devinfo *dp, int dev);
|
|
|
|
static void reset_channels(struct seq_oss_synthinfo *info);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* global initialization
|
|
|
|
*/
|
|
|
|
void __init
|
|
|
|
snd_seq_oss_synth_init(void)
|
|
|
|
{
|
|
|
|
snd_use_lock_init(&midi_synth_dev.use_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* registration of the synth device
|
|
|
|
*/
|
|
|
|
int
|
2005-11-17 06:05:16 -07:00
|
|
|
snd_seq_oss_synth_register(struct snd_seq_device *dev)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int i;
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth *rec;
|
|
|
|
struct snd_seq_oss_reg *reg = SNDRV_SEQ_DEVICE_ARGPTR(dev);
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned long flags;
|
|
|
|
|
2005-09-09 06:20:49 -06:00
|
|
|
if ((rec = kzalloc(sizeof(*rec), GFP_KERNEL)) == NULL) {
|
2014-02-04 10:24:04 -07:00
|
|
|
pr_err("ALSA: seq_oss: can't malloc synth info\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
rec->seq_device = -1;
|
|
|
|
rec->synth_type = reg->type;
|
|
|
|
rec->synth_subtype = reg->subtype;
|
|
|
|
rec->nr_voices = reg->nvoices;
|
|
|
|
rec->oper = reg->oper;
|
|
|
|
rec->private_data = reg->private_data;
|
|
|
|
rec->opened = 0;
|
|
|
|
snd_use_lock_init(&rec->use_lock);
|
|
|
|
|
|
|
|
/* copy and truncate the name of synth device */
|
|
|
|
strlcpy(rec->name, dev->name, sizeof(rec->name));
|
|
|
|
|
|
|
|
/* registration */
|
|
|
|
spin_lock_irqsave(®ister_lock, flags);
|
|
|
|
for (i = 0; i < max_synth_devs; i++) {
|
|
|
|
if (synth_devs[i] == NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= max_synth_devs) {
|
|
|
|
if (max_synth_devs >= SNDRV_SEQ_OSS_MAX_SYNTH_DEVS) {
|
|
|
|
spin_unlock_irqrestore(®ister_lock, flags);
|
2014-02-04 10:24:04 -07:00
|
|
|
pr_err("ALSA: seq_oss: no more synth slot\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
kfree(rec);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
max_synth_devs++;
|
|
|
|
}
|
|
|
|
rec->seq_device = i;
|
|
|
|
synth_devs[i] = rec;
|
|
|
|
spin_unlock_irqrestore(®ister_lock, flags);
|
|
|
|
dev->driver_data = rec;
|
|
|
|
#ifdef SNDRV_OSS_INFO_DEV_SYNTH
|
|
|
|
if (i < SNDRV_CARDS)
|
|
|
|
snd_oss_info_register(SNDRV_OSS_INFO_DEV_SYNTH, i, rec->name);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2005-11-17 06:05:16 -07:00
|
|
|
snd_seq_oss_synth_unregister(struct snd_seq_device *dev)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int index;
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth *rec = dev->driver_data;
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(®ister_lock, flags);
|
|
|
|
for (index = 0; index < max_synth_devs; index++) {
|
|
|
|
if (synth_devs[index] == rec)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (index >= max_synth_devs) {
|
|
|
|
spin_unlock_irqrestore(®ister_lock, flags);
|
2014-02-04 10:24:04 -07:00
|
|
|
pr_err("ALSA: seq_oss: can't unregister synth\n");
|
2005-04-16 16:20:36 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
synth_devs[index] = NULL;
|
|
|
|
if (index == max_synth_devs - 1) {
|
|
|
|
for (index--; index >= 0; index--) {
|
|
|
|
if (synth_devs[index])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
max_synth_devs = index + 1;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(®ister_lock, flags);
|
|
|
|
#ifdef SNDRV_OSS_INFO_DEV_SYNTH
|
|
|
|
if (rec->seq_device < SNDRV_CARDS)
|
|
|
|
snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_SYNTH, rec->seq_device);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
snd_use_lock_sync(&rec->use_lock);
|
|
|
|
kfree(rec);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
2005-11-17 06:05:16 -07:00
|
|
|
static struct seq_oss_synth *
|
2005-04-16 16:20:36 -06:00
|
|
|
get_sdev(int dev)
|
|
|
|
{
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth *rec;
|
2005-04-16 16:20:36 -06:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(®ister_lock, flags);
|
|
|
|
rec = synth_devs[dev];
|
|
|
|
if (rec)
|
|
|
|
snd_use_lock_use(&rec->use_lock);
|
|
|
|
spin_unlock_irqrestore(®ister_lock, flags);
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set up synth tables
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2005-11-17 06:05:16 -07:00
|
|
|
snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int i;
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth *rec;
|
|
|
|
struct seq_oss_synthinfo *info;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
dp->max_synthdev = max_synth_devs;
|
|
|
|
dp->synth_opened = 0;
|
|
|
|
memset(dp->synths, 0, sizeof(dp->synths));
|
|
|
|
for (i = 0; i < dp->max_synthdev; i++) {
|
|
|
|
rec = get_sdev(i);
|
|
|
|
if (rec == NULL)
|
|
|
|
continue;
|
|
|
|
if (rec->oper.open == NULL || rec->oper.close == NULL) {
|
|
|
|
snd_use_lock_free(&rec->use_lock);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
info = &dp->synths[i];
|
|
|
|
info->arg.app_index = dp->port;
|
|
|
|
info->arg.file_mode = dp->file_mode;
|
|
|
|
info->arg.seq_mode = dp->seq_mode;
|
|
|
|
if (dp->seq_mode == SNDRV_SEQ_OSS_MODE_SYNTH)
|
|
|
|
info->arg.event_passing = SNDRV_SEQ_OSS_PROCESS_EVENTS;
|
|
|
|
else
|
|
|
|
info->arg.event_passing = SNDRV_SEQ_OSS_PASS_EVENTS;
|
|
|
|
info->opened = 0;
|
|
|
|
if (!try_module_get(rec->oper.owner)) {
|
|
|
|
snd_use_lock_free(&rec->use_lock);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (rec->oper.open(&info->arg, rec->private_data) < 0) {
|
|
|
|
module_put(rec->oper.owner);
|
|
|
|
snd_use_lock_free(&rec->use_lock);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
info->nr_voices = rec->nr_voices;
|
|
|
|
if (info->nr_voices > 0) {
|
2005-11-17 06:05:16 -07:00
|
|
|
info->ch = kcalloc(info->nr_voices, sizeof(struct seq_oss_chinfo), GFP_KERNEL);
|
2008-02-21 04:40:00 -07:00
|
|
|
if (!info->ch) {
|
2014-02-04 10:24:04 -07:00
|
|
|
pr_err("ALSA: seq_oss: Cannot malloc voices\n");
|
2008-02-21 04:40:00 -07:00
|
|
|
rec->oper.close(&info->arg);
|
|
|
|
module_put(rec->oper.owner);
|
|
|
|
snd_use_lock_free(&rec->use_lock);
|
|
|
|
continue;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
reset_channels(info);
|
|
|
|
}
|
|
|
|
info->opened++;
|
|
|
|
rec->opened++;
|
|
|
|
dp->synth_opened++;
|
|
|
|
snd_use_lock_free(&rec->use_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set up synth tables for MIDI emulation - /dev/music mode only
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2005-11-17 06:05:16 -07:00
|
|
|
snd_seq_oss_synth_setup_midi(struct seq_oss_devinfo *dp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (dp->max_synthdev >= SNDRV_SEQ_OSS_MAX_SYNTH_DEVS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < dp->max_mididev; i++) {
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synthinfo *info;
|
2005-04-16 16:20:36 -06:00
|
|
|
info = &dp->synths[dp->max_synthdev];
|
|
|
|
if (snd_seq_oss_midi_open(dp, i, dp->file_mode) < 0)
|
|
|
|
continue;
|
|
|
|
info->arg.app_index = dp->port;
|
|
|
|
info->arg.file_mode = dp->file_mode;
|
|
|
|
info->arg.seq_mode = dp->seq_mode;
|
|
|
|
info->arg.private_data = info;
|
|
|
|
info->is_midi = 1;
|
|
|
|
info->midi_mapped = i;
|
|
|
|
info->arg.event_passing = SNDRV_SEQ_OSS_PASS_EVENTS;
|
|
|
|
snd_seq_oss_midi_get_addr(dp, i, &info->arg.addr);
|
|
|
|
info->opened = 1;
|
|
|
|
midi_synth_dev.opened++;
|
|
|
|
dp->max_synthdev++;
|
|
|
|
if (dp->max_synthdev >= SNDRV_SEQ_OSS_MAX_SYNTH_DEVS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* clean up synth tables
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
2005-11-17 06:05:16 -07:00
|
|
|
snd_seq_oss_synth_cleanup(struct seq_oss_devinfo *dp)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int i;
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth *rec;
|
|
|
|
struct seq_oss_synthinfo *info;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-08-08 09:09:09 -06:00
|
|
|
if (snd_BUG_ON(dp->max_synthdev >= SNDRV_SEQ_OSS_MAX_SYNTH_DEVS))
|
|
|
|
return;
|
2005-04-16 16:20:36 -06:00
|
|
|
for (i = 0; i < dp->max_synthdev; i++) {
|
|
|
|
info = &dp->synths[i];
|
|
|
|
if (! info->opened)
|
|
|
|
continue;
|
|
|
|
if (info->is_midi) {
|
|
|
|
if (midi_synth_dev.opened > 0) {
|
|
|
|
snd_seq_oss_midi_close(dp, info->midi_mapped);
|
|
|
|
midi_synth_dev.opened--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rec = get_sdev(i);
|
|
|
|
if (rec == NULL)
|
|
|
|
continue;
|
|
|
|
if (rec->opened > 0) {
|
|
|
|
rec->oper.close(&info->arg);
|
|
|
|
module_put(rec->oper.owner);
|
|
|
|
rec->opened = 0;
|
|
|
|
}
|
|
|
|
snd_use_lock_free(&rec->use_lock);
|
|
|
|
}
|
[ALSA] Remove redundant NULL checks before kfree
Timer Midlevel,ALSA sequencer,ALSA<-OSS sequencer,Digigram VX core
I2C tea6330t,GUS Library,VIA82xx driver,VIA82xx-modem driver
CA0106 driver,CS46xx driver,EMU10K1/EMU10K2 driver,YMFPCI driver
Digigram VX Pocket driver,Common EMU synth,USB generic driver,USB USX2Y
Checking a pointer for NULL before calling kfree() on it is redundant,
kfree() deals with NULL pointers just fine.
This patch removes such checks from sound/
This patch also makes another, but closely related, change.
It avoids casting pointers about to be kfree()'ed.
Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2005-05-30 09:30:32 -06:00
|
|
|
kfree(info->sysex);
|
|
|
|
info->sysex = NULL;
|
|
|
|
kfree(info->ch);
|
|
|
|
info->ch = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
dp->synth_opened = 0;
|
|
|
|
dp->max_synthdev = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check if the specified device is MIDI mapped device
|
|
|
|
*/
|
|
|
|
static int
|
2005-11-17 06:05:16 -07:00
|
|
|
is_midi_dev(struct seq_oss_devinfo *dp, int dev)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
if (dev < 0 || dev >= dp->max_synthdev)
|
|
|
|
return 0;
|
|
|
|
if (dp->synths[dev].is_midi)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* return synth device information pointer
|
|
|
|
*/
|
2005-11-17 06:05:16 -07:00
|
|
|
static struct seq_oss_synth *
|
|
|
|
get_synthdev(struct seq_oss_devinfo *dp, int dev)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth *rec;
|
2005-04-16 16:20:36 -06:00
|
|
|
if (dev < 0 || dev >= dp->max_synthdev)
|
|
|
|
return NULL;
|
|
|
|
if (! dp->synths[dev].opened)
|
|
|
|
return NULL;
|
|
|
|
if (dp->synths[dev].is_midi)
|
|
|
|
return &midi_synth_dev;
|
|
|
|
if ((rec = get_sdev(dev)) == NULL)
|
|
|
|
return NULL;
|
|
|
|
if (! rec->opened) {
|
|
|
|
snd_use_lock_free(&rec->use_lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* reset note and velocity on each channel.
|
|
|
|
*/
|
|
|
|
static void
|
2005-11-17 06:05:16 -07:00
|
|
|
reset_channels(struct seq_oss_synthinfo *info)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (info->ch == NULL || ! info->nr_voices)
|
|
|
|
return;
|
|
|
|
for (i = 0; i < info->nr_voices; i++) {
|
|
|
|
info->ch[i].note = -1;
|
|
|
|
info->ch[i].vel = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* reset synth device:
|
|
|
|
* call reset callback. if no callback is defined, send a heartbeat
|
|
|
|
* event to the corresponding port.
|
|
|
|
*/
|
|
|
|
void
|
2005-11-17 06:05:16 -07:00
|
|
|
snd_seq_oss_synth_reset(struct seq_oss_devinfo *dp, int dev)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth *rec;
|
|
|
|
struct seq_oss_synthinfo *info;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-08-08 09:09:09 -06:00
|
|
|
if (snd_BUG_ON(dev < 0 || dev >= dp->max_synthdev))
|
|
|
|
return;
|
2005-04-16 16:20:36 -06:00
|
|
|
info = &dp->synths[dev];
|
|
|
|
if (! info->opened)
|
|
|
|
return;
|
|
|
|
if (info->sysex)
|
|
|
|
info->sysex->len = 0; /* reset sysex */
|
|
|
|
reset_channels(info);
|
|
|
|
if (info->is_midi) {
|
|
|
|
if (midi_synth_dev.opened <= 0)
|
|
|
|
return;
|
|
|
|
snd_seq_oss_midi_reset(dp, info->midi_mapped);
|
|
|
|
/* reopen the device */
|
|
|
|
snd_seq_oss_midi_close(dp, dev);
|
|
|
|
if (snd_seq_oss_midi_open(dp, info->midi_mapped,
|
|
|
|
dp->file_mode) < 0) {
|
|
|
|
midi_synth_dev.opened--;
|
|
|
|
info->opened = 0;
|
[ALSA] Remove redundant NULL checks before kfree
Timer Midlevel,ALSA sequencer,ALSA<-OSS sequencer,Digigram VX core
I2C tea6330t,GUS Library,VIA82xx driver,VIA82xx-modem driver
CA0106 driver,CS46xx driver,EMU10K1/EMU10K2 driver,YMFPCI driver
Digigram VX Pocket driver,Common EMU synth,USB generic driver,USB USX2Y
Checking a pointer for NULL before calling kfree() on it is redundant,
kfree() deals with NULL pointers just fine.
This patch removes such checks from sound/
This patch also makes another, but closely related, change.
It avoids casting pointers about to be kfree()'ed.
Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2005-05-30 09:30:32 -06:00
|
|
|
kfree(info->sysex);
|
|
|
|
info->sysex = NULL;
|
|
|
|
kfree(info->ch);
|
|
|
|
info->ch = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rec = get_sdev(dev);
|
|
|
|
if (rec == NULL)
|
|
|
|
return;
|
|
|
|
if (rec->oper.reset) {
|
|
|
|
rec->oper.reset(&info->arg);
|
|
|
|
} else {
|
2005-11-17 06:05:16 -07:00
|
|
|
struct snd_seq_event ev;
|
2005-04-16 16:20:36 -06:00
|
|
|
memset(&ev, 0, sizeof(ev));
|
|
|
|
snd_seq_oss_fill_addr(dp, &ev, info->arg.addr.client,
|
|
|
|
info->arg.addr.port);
|
|
|
|
ev.type = SNDRV_SEQ_EVENT_RESET;
|
|
|
|
snd_seq_oss_dispatch(dp, &ev, 0, 0);
|
|
|
|
}
|
|
|
|
snd_use_lock_free(&rec->use_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* load a patch record:
|
|
|
|
* call load_patch callback function
|
|
|
|
*/
|
|
|
|
int
|
2005-11-17 06:05:16 -07:00
|
|
|
snd_seq_oss_synth_load_patch(struct seq_oss_devinfo *dp, int dev, int fmt,
|
2005-04-16 16:20:36 -06:00
|
|
|
const char __user *buf, int p, int c)
|
|
|
|
{
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth *rec;
|
2005-04-16 16:20:36 -06:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (dev < 0 || dev >= dp->max_synthdev)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
if (is_midi_dev(dp, dev))
|
|
|
|
return 0;
|
|
|
|
if ((rec = get_synthdev(dp, dev)) == NULL)
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
if (rec->oper.load_patch == NULL)
|
|
|
|
rc = -ENXIO;
|
|
|
|
else
|
|
|
|
rc = rec->oper.load_patch(&dp->synths[dev].arg, fmt, buf, p, c);
|
|
|
|
snd_use_lock_free(&rec->use_lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check if the device is valid synth device
|
|
|
|
*/
|
|
|
|
int
|
2005-11-17 06:05:16 -07:00
|
|
|
snd_seq_oss_synth_is_valid(struct seq_oss_devinfo *dp, int dev)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth *rec;
|
2005-04-16 16:20:36 -06:00
|
|
|
rec = get_synthdev(dp, dev);
|
|
|
|
if (rec) {
|
|
|
|
snd_use_lock_free(&rec->use_lock);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* receive OSS 6 byte sysex packet:
|
|
|
|
* the full sysex message will be sent if it reaches to the end of data
|
|
|
|
* (0xff).
|
|
|
|
*/
|
|
|
|
int
|
2005-11-17 06:05:16 -07:00
|
|
|
snd_seq_oss_synth_sysex(struct seq_oss_devinfo *dp, int dev, unsigned char *buf, struct snd_seq_event *ev)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int i, send;
|
|
|
|
unsigned char *dest;
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth_sysex *sysex;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
if (! snd_seq_oss_synth_is_valid(dp, dev))
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
sysex = dp->synths[dev].sysex;
|
|
|
|
if (sysex == NULL) {
|
2005-09-09 06:20:49 -06:00
|
|
|
sysex = kzalloc(sizeof(*sysex), GFP_KERNEL);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (sysex == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
dp->synths[dev].sysex = sysex;
|
|
|
|
}
|
|
|
|
|
|
|
|
send = 0;
|
|
|
|
dest = sysex->buf + sysex->len;
|
|
|
|
/* copy 6 byte packet to the buffer */
|
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
if (buf[i] == 0xff) {
|
|
|
|
send = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dest[i] = buf[i];
|
|
|
|
sysex->len++;
|
|
|
|
if (sysex->len >= MAX_SYSEX_BUFLEN) {
|
|
|
|
sysex->len = 0;
|
|
|
|
sysex->skip = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sysex->len && send) {
|
|
|
|
if (sysex->skip) {
|
|
|
|
sysex->skip = 0;
|
|
|
|
sysex->len = 0;
|
|
|
|
return -EINVAL; /* skip */
|
|
|
|
}
|
|
|
|
/* copy the data to event record and send it */
|
|
|
|
ev->flags = SNDRV_SEQ_EVENT_LENGTH_VARIABLE;
|
|
|
|
if (snd_seq_oss_synth_addr(dp, dev, ev))
|
|
|
|
return -EINVAL;
|
|
|
|
ev->data.ext.len = sysex->len;
|
|
|
|
ev->data.ext.ptr = sysex->buf;
|
|
|
|
sysex->len = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL; /* skip */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fill the event source/destination addresses
|
|
|
|
*/
|
|
|
|
int
|
2005-11-17 06:05:16 -07:00
|
|
|
snd_seq_oss_synth_addr(struct seq_oss_devinfo *dp, int dev, struct snd_seq_event *ev)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
if (! snd_seq_oss_synth_is_valid(dp, dev))
|
|
|
|
return -EINVAL;
|
|
|
|
snd_seq_oss_fill_addr(dp, ev, dp->synths[dev].arg.addr.client,
|
|
|
|
dp->synths[dev].arg.addr.port);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* OSS compatible ioctl
|
|
|
|
*/
|
|
|
|
int
|
2005-11-17 06:05:16 -07:00
|
|
|
snd_seq_oss_synth_ioctl(struct seq_oss_devinfo *dp, int dev, unsigned int cmd, unsigned long addr)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth *rec;
|
2005-04-16 16:20:36 -06:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (is_midi_dev(dp, dev))
|
|
|
|
return -ENXIO;
|
|
|
|
if ((rec = get_synthdev(dp, dev)) == NULL)
|
|
|
|
return -ENXIO;
|
|
|
|
if (rec->oper.ioctl == NULL)
|
|
|
|
rc = -ENXIO;
|
|
|
|
else
|
|
|
|
rc = rec->oper.ioctl(&dp->synths[dev].arg, cmd, addr);
|
|
|
|
snd_use_lock_free(&rec->use_lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* send OSS raw events - SEQ_PRIVATE and SEQ_VOLUME
|
|
|
|
*/
|
|
|
|
int
|
2005-11-17 06:05:16 -07:00
|
|
|
snd_seq_oss_synth_raw_event(struct seq_oss_devinfo *dp, int dev, unsigned char *data, struct snd_seq_event *ev)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
if (! snd_seq_oss_synth_is_valid(dp, dev) || is_midi_dev(dp, dev))
|
|
|
|
return -ENXIO;
|
|
|
|
ev->type = SNDRV_SEQ_EVENT_OSS;
|
|
|
|
memcpy(ev->data.raw8.d, data, 8);
|
|
|
|
return snd_seq_oss_synth_addr(dp, dev, ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create OSS compatible synth_info record
|
|
|
|
*/
|
|
|
|
int
|
2005-11-17 06:05:16 -07:00
|
|
|
snd_seq_oss_synth_make_info(struct seq_oss_devinfo *dp, int dev, struct synth_info *inf)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth *rec;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-08-02 10:25:16 -06:00
|
|
|
if (dev < 0 || dev >= dp->max_synthdev)
|
|
|
|
return -ENXIO;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (dp->synths[dev].is_midi) {
|
|
|
|
struct midi_info minf;
|
|
|
|
snd_seq_oss_midi_make_info(dp, dp->synths[dev].midi_mapped, &minf);
|
|
|
|
inf->synth_type = SYNTH_TYPE_MIDI;
|
|
|
|
inf->synth_subtype = 0;
|
|
|
|
inf->nr_voices = 16;
|
|
|
|
inf->device = dev;
|
|
|
|
strlcpy(inf->name, minf.name, sizeof(inf->name));
|
|
|
|
} else {
|
|
|
|
if ((rec = get_synthdev(dp, dev)) == NULL)
|
|
|
|
return -ENXIO;
|
|
|
|
inf->synth_type = rec->synth_type;
|
|
|
|
inf->synth_subtype = rec->synth_subtype;
|
|
|
|
inf->nr_voices = rec->nr_voices;
|
|
|
|
inf->device = dev;
|
|
|
|
strlcpy(inf->name, rec->name, sizeof(inf->name));
|
|
|
|
snd_use_lock_free(&rec->use_lock);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-01 02:43:51 -07:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* proc interface
|
|
|
|
*/
|
|
|
|
void
|
2005-11-17 06:05:16 -07:00
|
|
|
snd_seq_oss_synth_info_read(struct snd_info_buffer *buf)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int i;
|
2005-11-17 06:05:16 -07:00
|
|
|
struct seq_oss_synth *rec;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
snd_iprintf(buf, "\nNumber of synth devices: %d\n", max_synth_devs);
|
|
|
|
for (i = 0; i < max_synth_devs; i++) {
|
|
|
|
snd_iprintf(buf, "\nsynth %d: ", i);
|
|
|
|
rec = get_sdev(i);
|
|
|
|
if (rec == NULL) {
|
|
|
|
snd_iprintf(buf, "*empty*\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
snd_iprintf(buf, "[%s]\n", rec->name);
|
|
|
|
snd_iprintf(buf, " type 0x%x : subtype 0x%x : voices %d\n",
|
|
|
|
rec->synth_type, rec->synth_subtype,
|
|
|
|
rec->nr_voices);
|
|
|
|
snd_iprintf(buf, " capabilities : ioctl %s / load_patch %s\n",
|
|
|
|
enabled_str((long)rec->oper.ioctl),
|
|
|
|
enabled_str((long)rec->oper.load_patch));
|
|
|
|
snd_use_lock_free(&rec->use_lock);
|
|
|
|
}
|
|
|
|
}
|
2005-12-01 02:43:51 -07:00
|
|
|
#endif /* CONFIG_PROC_FS */
|