diff options
Diffstat (limited to 'sound/core/rawmidi.c')
-rw-r--r-- | sound/core/rawmidi.c | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c index 6fc71a4c8a51..b5a748596fc4 100644 --- a/sound/core/rawmidi.c +++ b/sound/core/rawmidi.c | |||
@@ -57,11 +57,11 @@ static LIST_HEAD(snd_rawmidi_devices); | |||
57 | static DEFINE_MUTEX(register_mutex); | 57 | static DEFINE_MUTEX(register_mutex); |
58 | 58 | ||
59 | #define rmidi_err(rmidi, fmt, args...) \ | 59 | #define rmidi_err(rmidi, fmt, args...) \ |
60 | dev_err((rmidi)->card->dev, fmt, ##args) | 60 | dev_err(&(rmidi)->dev, fmt, ##args) |
61 | #define rmidi_warn(rmidi, fmt, args...) \ | 61 | #define rmidi_warn(rmidi, fmt, args...) \ |
62 | dev_warn((rmidi)->card->dev, fmt, ##args) | 62 | dev_warn(&(rmidi)->dev, fmt, ##args) |
63 | #define rmidi_dbg(rmidi, fmt, args...) \ | 63 | #define rmidi_dbg(rmidi, fmt, args...) \ |
64 | dev_dbg((rmidi)->card->dev, fmt, ##args) | 64 | dev_dbg(&(rmidi)->dev, fmt, ##args) |
65 | 65 | ||
66 | static struct snd_rawmidi *snd_rawmidi_search(struct snd_card *card, int device) | 66 | static struct snd_rawmidi *snd_rawmidi_search(struct snd_card *card, int device) |
67 | { | 67 | { |
@@ -369,7 +369,6 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file) | |||
369 | struct snd_rawmidi *rmidi; | 369 | struct snd_rawmidi *rmidi; |
370 | struct snd_rawmidi_file *rawmidi_file = NULL; | 370 | struct snd_rawmidi_file *rawmidi_file = NULL; |
371 | wait_queue_t wait; | 371 | wait_queue_t wait; |
372 | struct snd_ctl_file *kctl; | ||
373 | 372 | ||
374 | if ((file->f_flags & O_APPEND) && !(file->f_flags & O_NONBLOCK)) | 373 | if ((file->f_flags & O_APPEND) && !(file->f_flags & O_NONBLOCK)) |
375 | return -EINVAL; /* invalid combination */ | 374 | return -EINVAL; /* invalid combination */ |
@@ -413,16 +412,7 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file) | |||
413 | init_waitqueue_entry(&wait, current); | 412 | init_waitqueue_entry(&wait, current); |
414 | add_wait_queue(&rmidi->open_wait, &wait); | 413 | add_wait_queue(&rmidi->open_wait, &wait); |
415 | while (1) { | 414 | while (1) { |
416 | subdevice = -1; | 415 | subdevice = snd_ctl_get_preferred_subdevice(card, SND_CTL_SUBDEV_RAWMIDI); |
417 | read_lock(&card->ctl_files_rwlock); | ||
418 | list_for_each_entry(kctl, &card->ctl_files, list) { | ||
419 | if (kctl->pid == task_pid(current)) { | ||
420 | subdevice = kctl->prefer_rawmidi_subdevice; | ||
421 | if (subdevice != -1) | ||
422 | break; | ||
423 | } | ||
424 | } | ||
425 | read_unlock(&card->ctl_files_rwlock); | ||
426 | err = rawmidi_open_priv(rmidi, subdevice, fflags, rawmidi_file); | 416 | err = rawmidi_open_priv(rmidi, subdevice, fflags, rawmidi_file); |
427 | if (err >= 0) | 417 | if (err >= 0) |
428 | break; | 418 | break; |
@@ -862,7 +852,7 @@ static int snd_rawmidi_control_ioctl(struct snd_card *card, | |||
862 | 852 | ||
863 | if (get_user(val, (int __user *)argp)) | 853 | if (get_user(val, (int __user *)argp)) |
864 | return -EFAULT; | 854 | return -EFAULT; |
865 | control->prefer_rawmidi_subdevice = val; | 855 | control->preferred_subdevice[SND_CTL_SUBDEV_RAWMIDI] = val; |
866 | return 0; | 856 | return 0; |
867 | } | 857 | } |
868 | case SNDRV_CTL_IOCTL_RAWMIDI_INFO: | 858 | case SNDRV_CTL_IOCTL_RAWMIDI_INFO: |
@@ -1453,6 +1443,11 @@ static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi, | |||
1453 | return 0; | 1443 | return 0; |
1454 | } | 1444 | } |
1455 | 1445 | ||
1446 | static void release_rawmidi_device(struct device *dev) | ||
1447 | { | ||
1448 | kfree(container_of(dev, struct snd_rawmidi, dev)); | ||
1449 | } | ||
1450 | |||
1456 | /** | 1451 | /** |
1457 | * snd_rawmidi_new - create a rawmidi instance | 1452 | * snd_rawmidi_new - create a rawmidi instance |
1458 | * @card: the card instance | 1453 | * @card: the card instance |
@@ -1497,6 +1492,11 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device, | |||
1497 | 1492 | ||
1498 | if (id != NULL) | 1493 | if (id != NULL) |
1499 | strlcpy(rmidi->id, id, sizeof(rmidi->id)); | 1494 | strlcpy(rmidi->id, id, sizeof(rmidi->id)); |
1495 | |||
1496 | snd_device_initialize(&rmidi->dev, card); | ||
1497 | rmidi->dev.release = release_rawmidi_device; | ||
1498 | dev_set_name(&rmidi->dev, "midiC%iD%i", card->number, device); | ||
1499 | |||
1500 | if ((err = snd_rawmidi_alloc_substreams(rmidi, | 1500 | if ((err = snd_rawmidi_alloc_substreams(rmidi, |
1501 | &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT], | 1501 | &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT], |
1502 | SNDRV_RAWMIDI_STREAM_INPUT, | 1502 | SNDRV_RAWMIDI_STREAM_INPUT, |
@@ -1548,7 +1548,7 @@ static int snd_rawmidi_free(struct snd_rawmidi *rmidi) | |||
1548 | snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]); | 1548 | snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]); |
1549 | if (rmidi->private_free) | 1549 | if (rmidi->private_free) |
1550 | rmidi->private_free(rmidi); | 1550 | rmidi->private_free(rmidi); |
1551 | kfree(rmidi); | 1551 | put_device(&rmidi->dev); |
1552 | return 0; | 1552 | return 0; |
1553 | } | 1553 | } |
1554 | 1554 | ||
@@ -1581,19 +1581,18 @@ static int snd_rawmidi_dev_register(struct snd_device *device) | |||
1581 | return -EBUSY; | 1581 | return -EBUSY; |
1582 | } | 1582 | } |
1583 | list_add_tail(&rmidi->list, &snd_rawmidi_devices); | 1583 | list_add_tail(&rmidi->list, &snd_rawmidi_devices); |
1584 | sprintf(name, "midiC%iD%i", rmidi->card->number, rmidi->device); | 1584 | err = snd_register_device(SNDRV_DEVICE_TYPE_RAWMIDI, |
1585 | if ((err = snd_register_device(SNDRV_DEVICE_TYPE_RAWMIDI, | 1585 | rmidi->card, rmidi->device, |
1586 | rmidi->card, rmidi->device, | 1586 | &snd_rawmidi_f_ops, rmidi, &rmidi->dev); |
1587 | &snd_rawmidi_f_ops, rmidi, name)) < 0) { | 1587 | if (err < 0) { |
1588 | rmidi_err(rmidi, "unable to register rawmidi device %i:%i\n", | 1588 | rmidi_err(rmidi, "unable to register\n"); |
1589 | rmidi->card->number, rmidi->device); | ||
1590 | list_del(&rmidi->list); | 1589 | list_del(&rmidi->list); |
1591 | mutex_unlock(®ister_mutex); | 1590 | mutex_unlock(®ister_mutex); |
1592 | return err; | 1591 | return err; |
1593 | } | 1592 | } |
1594 | if (rmidi->ops && rmidi->ops->dev_register && | 1593 | if (rmidi->ops && rmidi->ops->dev_register && |
1595 | (err = rmidi->ops->dev_register(rmidi)) < 0) { | 1594 | (err = rmidi->ops->dev_register(rmidi)) < 0) { |
1596 | snd_unregister_device(SNDRV_DEVICE_TYPE_RAWMIDI, rmidi->card, rmidi->device); | 1595 | snd_unregister_device(&rmidi->dev); |
1597 | list_del(&rmidi->list); | 1596 | list_del(&rmidi->list); |
1598 | mutex_unlock(®ister_mutex); | 1597 | mutex_unlock(®ister_mutex); |
1599 | return err; | 1598 | return err; |
@@ -1681,7 +1680,7 @@ static int snd_rawmidi_dev_disconnect(struct snd_device *device) | |||
1681 | rmidi->ossreg = 0; | 1680 | rmidi->ossreg = 0; |
1682 | } | 1681 | } |
1683 | #endif /* CONFIG_SND_OSSEMUL */ | 1682 | #endif /* CONFIG_SND_OSSEMUL */ |
1684 | snd_unregister_device(SNDRV_DEVICE_TYPE_RAWMIDI, rmidi->card, rmidi->device); | 1683 | snd_unregister_device(&rmidi->dev); |
1685 | mutex_unlock(&rmidi->open_mutex); | 1684 | mutex_unlock(&rmidi->open_mutex); |
1686 | mutex_unlock(®ister_mutex); | 1685 | mutex_unlock(®ister_mutex); |
1687 | return 0; | 1686 | return 0; |