Merge branch 'topic/core-cleanup' into for-linus
This commit is contained in:
@@ -50,6 +50,10 @@ static int snd_ctl_open(struct inode *inode, struct file *file)
|
||||
struct snd_ctl_file *ctl;
|
||||
int err;
|
||||
|
||||
err = nonseekable_open(inode, file);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
card = snd_lookup_minor_data(iminor(inode), SNDRV_DEVICE_TYPE_CONTROL);
|
||||
if (!card) {
|
||||
err = -ENODEV;
|
||||
@@ -1388,6 +1392,7 @@ static const struct file_operations snd_ctl_f_ops =
|
||||
.read = snd_ctl_read,
|
||||
.open = snd_ctl_open,
|
||||
.release = snd_ctl_release,
|
||||
.llseek = no_llseek,
|
||||
.poll = snd_ctl_poll,
|
||||
.unlocked_ioctl = snd_ctl_ioctl,
|
||||
.compat_ioctl = snd_ctl_ioctl_compat,
|
||||
|
@@ -164,40 +164,44 @@ static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig)
|
||||
{
|
||||
struct snd_info_private_data *data;
|
||||
struct snd_info_entry *entry;
|
||||
loff_t ret;
|
||||
loff_t ret = -EINVAL, size;
|
||||
|
||||
data = file->private_data;
|
||||
entry = data->entry;
|
||||
lock_kernel();
|
||||
switch (entry->content) {
|
||||
case SNDRV_INFO_CONTENT_TEXT:
|
||||
switch (orig) {
|
||||
case SEEK_SET:
|
||||
file->f_pos = offset;
|
||||
ret = file->f_pos;
|
||||
goto out;
|
||||
case SEEK_CUR:
|
||||
file->f_pos += offset;
|
||||
ret = file->f_pos;
|
||||
goto out;
|
||||
case SEEK_END:
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
goto out;
|
||||
}
|
||||
break;
|
||||
case SNDRV_INFO_CONTENT_DATA:
|
||||
if (entry->c.ops->llseek) {
|
||||
ret = entry->c.ops->llseek(entry,
|
||||
data->file_private_data,
|
||||
file, offset, orig);
|
||||
goto out;
|
||||
}
|
||||
break;
|
||||
mutex_lock(&entry->access);
|
||||
if (entry->content == SNDRV_INFO_CONTENT_DATA &&
|
||||
entry->c.ops->llseek) {
|
||||
offset = entry->c.ops->llseek(entry,
|
||||
data->file_private_data,
|
||||
file, offset, orig);
|
||||
goto out;
|
||||
}
|
||||
ret = -ENXIO;
|
||||
out:
|
||||
unlock_kernel();
|
||||
if (entry->content == SNDRV_INFO_CONTENT_DATA)
|
||||
size = entry->size;
|
||||
else
|
||||
size = 0;
|
||||
switch (orig) {
|
||||
case SEEK_SET:
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
offset += file->f_pos;
|
||||
break;
|
||||
case SEEK_END:
|
||||
if (!size)
|
||||
goto out;
|
||||
offset += size;
|
||||
break;
|
||||
default:
|
||||
goto out;
|
||||
}
|
||||
if (offset < 0)
|
||||
goto out;
|
||||
if (size && offset > size)
|
||||
offset = size;
|
||||
file->f_pos = offset;
|
||||
ret = offset;
|
||||
out:
|
||||
mutex_unlock(&entry->access);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -232,10 +236,15 @@ static ssize_t snd_info_entry_read(struct file *file, char __user *buffer,
|
||||
return -EFAULT;
|
||||
break;
|
||||
case SNDRV_INFO_CONTENT_DATA:
|
||||
if (entry->c.ops->read)
|
||||
if (pos >= entry->size)
|
||||
return 0;
|
||||
if (entry->c.ops->read) {
|
||||
size = entry->size - pos;
|
||||
size = min(count, size);
|
||||
size = entry->c.ops->read(entry,
|
||||
data->file_private_data,
|
||||
file, buffer, count, pos);
|
||||
file, buffer, size, pos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ((ssize_t) size > 0)
|
||||
@@ -282,10 +291,13 @@ static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer
|
||||
size = count;
|
||||
break;
|
||||
case SNDRV_INFO_CONTENT_DATA:
|
||||
if (entry->c.ops->write)
|
||||
if (entry->c.ops->write && count > 0) {
|
||||
size_t maxsize = entry->size - pos;
|
||||
count = min(count, maxsize);
|
||||
size = entry->c.ops->write(entry,
|
||||
data->file_private_data,
|
||||
file, buffer, count, pos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ((ssize_t) size > 0)
|
||||
|
@@ -43,6 +43,10 @@ static int snd_mixer_oss_open(struct inode *inode, struct file *file)
|
||||
struct snd_mixer_oss_file *fmixer;
|
||||
int err;
|
||||
|
||||
err = nonseekable_open(inode, file);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
card = snd_lookup_oss_minor_data(iminor(inode),
|
||||
SNDRV_OSS_DEVICE_TYPE_MIXER);
|
||||
if (card == NULL)
|
||||
@@ -397,6 +401,7 @@ static const struct file_operations snd_mixer_oss_f_ops =
|
||||
.owner = THIS_MODULE,
|
||||
.open = snd_mixer_oss_open,
|
||||
.release = snd_mixer_oss_release,
|
||||
.llseek = no_llseek,
|
||||
.unlocked_ioctl = snd_mixer_oss_ioctl,
|
||||
.compat_ioctl = snd_mixer_oss_ioctl_compat,
|
||||
};
|
||||
|
@@ -2379,6 +2379,10 @@ static int snd_pcm_oss_open(struct inode *inode, struct file *file)
|
||||
int nonblock;
|
||||
wait_queue_t wait;
|
||||
|
||||
err = nonseekable_open(inode, file);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
pcm = snd_lookup_oss_minor_data(iminor(inode),
|
||||
SNDRV_OSS_DEVICE_TYPE_PCM);
|
||||
if (pcm == NULL) {
|
||||
@@ -2977,6 +2981,7 @@ static const struct file_operations snd_pcm_oss_f_reg =
|
||||
.write = snd_pcm_oss_write,
|
||||
.open = snd_pcm_oss_open,
|
||||
.release = snd_pcm_oss_release,
|
||||
.llseek = no_llseek,
|
||||
.poll = snd_pcm_oss_poll,
|
||||
.unlocked_ioctl = snd_pcm_oss_ioctl,
|
||||
.compat_ioctl = snd_pcm_oss_ioctl_compat,
|
||||
|
@@ -2110,7 +2110,9 @@ static int snd_pcm_open_file(struct file *file,
|
||||
static int snd_pcm_playback_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
struct snd_pcm *pcm;
|
||||
|
||||
int err = nonseekable_open(inode, file);
|
||||
if (err < 0)
|
||||
return err;
|
||||
pcm = snd_lookup_minor_data(iminor(inode),
|
||||
SNDRV_DEVICE_TYPE_PCM_PLAYBACK);
|
||||
return snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_PLAYBACK);
|
||||
@@ -2119,7 +2121,9 @@ static int snd_pcm_playback_open(struct inode *inode, struct file *file)
|
||||
static int snd_pcm_capture_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
struct snd_pcm *pcm;
|
||||
|
||||
int err = nonseekable_open(inode, file);
|
||||
if (err < 0)
|
||||
return err;
|
||||
pcm = snd_lookup_minor_data(iminor(inode),
|
||||
SNDRV_DEVICE_TYPE_PCM_CAPTURE);
|
||||
return snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_CAPTURE);
|
||||
@@ -3310,18 +3314,13 @@ static int snd_pcm_fasync(int fd, struct file * file, int on)
|
||||
struct snd_pcm_file * pcm_file;
|
||||
struct snd_pcm_substream *substream;
|
||||
struct snd_pcm_runtime *runtime;
|
||||
int err = -ENXIO;
|
||||
|
||||
lock_kernel();
|
||||
pcm_file = file->private_data;
|
||||
substream = pcm_file->substream;
|
||||
if (PCM_RUNTIME_CHECK(substream))
|
||||
goto out;
|
||||
return -ENXIO;
|
||||
runtime = substream->runtime;
|
||||
err = fasync_helper(fd, file, on, &runtime->fasync);
|
||||
out:
|
||||
unlock_kernel();
|
||||
return err;
|
||||
return fasync_helper(fd, file, on, &runtime->fasync);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3462,6 +3461,7 @@ const struct file_operations snd_pcm_f_ops[2] = {
|
||||
.aio_write = snd_pcm_aio_write,
|
||||
.open = snd_pcm_playback_open,
|
||||
.release = snd_pcm_release,
|
||||
.llseek = no_llseek,
|
||||
.poll = snd_pcm_playback_poll,
|
||||
.unlocked_ioctl = snd_pcm_playback_ioctl,
|
||||
.compat_ioctl = snd_pcm_ioctl_compat,
|
||||
@@ -3475,6 +3475,7 @@ const struct file_operations snd_pcm_f_ops[2] = {
|
||||
.aio_read = snd_pcm_aio_read,
|
||||
.open = snd_pcm_capture_open,
|
||||
.release = snd_pcm_release,
|
||||
.llseek = no_llseek,
|
||||
.poll = snd_pcm_capture_poll,
|
||||
.unlocked_ioctl = snd_pcm_capture_ioctl,
|
||||
.compat_ioctl = snd_pcm_ioctl_compat,
|
||||
|
@@ -376,6 +376,10 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
|
||||
if ((file->f_flags & O_APPEND) && !(file->f_flags & O_NONBLOCK))
|
||||
return -EINVAL; /* invalid combination */
|
||||
|
||||
err = nonseekable_open(inode, file);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
if (maj == snd_major) {
|
||||
rmidi = snd_lookup_minor_data(iminor(inode),
|
||||
SNDRV_DEVICE_TYPE_RAWMIDI);
|
||||
@@ -1391,6 +1395,7 @@ static const struct file_operations snd_rawmidi_f_ops =
|
||||
.write = snd_rawmidi_write,
|
||||
.open = snd_rawmidi_open,
|
||||
.release = snd_rawmidi_release,
|
||||
.llseek = no_llseek,
|
||||
.poll = snd_rawmidi_poll,
|
||||
.unlocked_ioctl = snd_rawmidi_ioctl,
|
||||
.compat_ioctl = snd_rawmidi_ioctl_compat,
|
||||
|
@@ -318,6 +318,11 @@ static int snd_seq_open(struct inode *inode, struct file *file)
|
||||
int c, mode; /* client id */
|
||||
struct snd_seq_client *client;
|
||||
struct snd_seq_user_client *user;
|
||||
int err;
|
||||
|
||||
err = nonseekable_open(inode, file);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
if (mutex_lock_interruptible(®ister_mutex))
|
||||
return -ERESTARTSYS;
|
||||
@@ -2550,6 +2555,7 @@ static const struct file_operations snd_seq_f_ops =
|
||||
.write = snd_seq_write,
|
||||
.open = snd_seq_open,
|
||||
.release = snd_seq_release,
|
||||
.llseek = no_llseek,
|
||||
.poll = snd_seq_poll,
|
||||
.unlocked_ioctl = snd_seq_ioctl,
|
||||
.compat_ioctl = snd_seq_ioctl_compat,
|
||||
|
@@ -120,7 +120,29 @@ void *snd_lookup_minor_data(unsigned int minor, int type)
|
||||
|
||||
EXPORT_SYMBOL(snd_lookup_minor_data);
|
||||
|
||||
static int __snd_open(struct inode *inode, struct file *file)
|
||||
#ifdef CONFIG_MODULES
|
||||
static struct snd_minor *autoload_device(unsigned int minor)
|
||||
{
|
||||
int dev;
|
||||
mutex_unlock(&sound_mutex); /* release lock temporarily */
|
||||
dev = SNDRV_MINOR_DEVICE(minor);
|
||||
if (dev == SNDRV_MINOR_CONTROL) {
|
||||
/* /dev/aloadC? */
|
||||
int card = SNDRV_MINOR_CARD(minor);
|
||||
if (snd_cards[card] == NULL)
|
||||
snd_request_card(card);
|
||||
} else if (dev == SNDRV_MINOR_GLOBAL) {
|
||||
/* /dev/aloadSEQ */
|
||||
snd_request_other(minor);
|
||||
}
|
||||
mutex_lock(&sound_mutex); /* reacuire lock */
|
||||
return snd_minors[minor];
|
||||
}
|
||||
#else /* !CONFIG_MODULES */
|
||||
#define autoload_device(minor) NULL
|
||||
#endif /* CONFIG_MODULES */
|
||||
|
||||
static int snd_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
unsigned int minor = iminor(inode);
|
||||
struct snd_minor *mptr = NULL;
|
||||
@@ -129,55 +151,36 @@ static int __snd_open(struct inode *inode, struct file *file)
|
||||
|
||||
if (minor >= ARRAY_SIZE(snd_minors))
|
||||
return -ENODEV;
|
||||
mutex_lock(&sound_mutex);
|
||||
mptr = snd_minors[minor];
|
||||
if (mptr == NULL) {
|
||||
#ifdef CONFIG_MODULES
|
||||
int dev = SNDRV_MINOR_DEVICE(minor);
|
||||
if (dev == SNDRV_MINOR_CONTROL) {
|
||||
/* /dev/aloadC? */
|
||||
int card = SNDRV_MINOR_CARD(minor);
|
||||
if (snd_cards[card] == NULL)
|
||||
snd_request_card(card);
|
||||
} else if (dev == SNDRV_MINOR_GLOBAL) {
|
||||
/* /dev/aloadSEQ */
|
||||
snd_request_other(minor);
|
||||
}
|
||||
#ifndef CONFIG_SND_DYNAMIC_MINORS
|
||||
/* /dev/snd/{controlC?,seq} */
|
||||
mptr = snd_minors[minor];
|
||||
if (mptr == NULL)
|
||||
#endif
|
||||
#endif
|
||||
mptr = autoload_device(minor);
|
||||
if (!mptr) {
|
||||
mutex_unlock(&sound_mutex);
|
||||
return -ENODEV;
|
||||
}
|
||||
}
|
||||
old_fops = file->f_op;
|
||||
file->f_op = fops_get(mptr->f_ops);
|
||||
if (file->f_op == NULL) {
|
||||
file->f_op = old_fops;
|
||||
return -ENODEV;
|
||||
err = -ENODEV;
|
||||
}
|
||||
if (file->f_op->open)
|
||||
mutex_unlock(&sound_mutex);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
if (file->f_op->open) {
|
||||
err = file->f_op->open(inode, file);
|
||||
if (err) {
|
||||
fops_put(file->f_op);
|
||||
file->f_op = fops_get(old_fops);
|
||||
if (err) {
|
||||
fops_put(file->f_op);
|
||||
file->f_op = fops_get(old_fops);
|
||||
}
|
||||
}
|
||||
fops_put(old_fops);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/* BKL pushdown: nasty #ifdef avoidance wrapper */
|
||||
static int snd_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
int ret;
|
||||
|
||||
lock_kernel();
|
||||
ret = __snd_open(inode, file);
|
||||
unlock_kernel();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct file_operations snd_fops =
|
||||
{
|
||||
.owner = THIS_MODULE,
|
||||
|
@@ -1238,6 +1238,11 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri,
|
||||
static int snd_timer_user_open(struct inode *inode, struct file *file)
|
||||
{
|
||||
struct snd_timer_user *tu;
|
||||
int err;
|
||||
|
||||
err = nonseekable_open(inode, file);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
tu = kzalloc(sizeof(*tu), GFP_KERNEL);
|
||||
if (tu == NULL)
|
||||
@@ -1922,6 +1927,7 @@ static const struct file_operations snd_timer_f_ops =
|
||||
.read = snd_timer_user_read,
|
||||
.open = snd_timer_user_open,
|
||||
.release = snd_timer_user_release,
|
||||
.llseek = no_llseek,
|
||||
.poll = snd_timer_user_poll,
|
||||
.unlocked_ioctl = snd_timer_user_ioctl,
|
||||
.compat_ioctl = snd_timer_user_ioctl_compat,
|
||||
|
Viittaa uudesa ongelmassa
Block a user