diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-01-29 10:41:27 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2015-02-02 08:42:41 -0500 |
commit | 0fcd9f4b3c60382205e5819c456aa9ea17b6f20f (patch) | |
tree | 02c793b240b7fc8a1d8c0b7d7f6b8bb5048a83ae /sound/core | |
parent | 4b440be667c6187717c99e4d427119fa415ced29 (diff) |
ALSA: control: Embed struct device
This patch embeds a struct device for the control device into the card
object and avoid the device creation at registration time.
Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/core')
-rw-r--r-- | sound/core/control.c | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/sound/core/control.c b/sound/core/control.c index cd246a0bcd55..e214fabbc671 100644 --- a/sound/core/control.c +++ b/sound/core/control.c | |||
@@ -1660,19 +1660,10 @@ static const struct file_operations snd_ctl_f_ops = | |||
1660 | static int snd_ctl_dev_register(struct snd_device *device) | 1660 | static int snd_ctl_dev_register(struct snd_device *device) |
1661 | { | 1661 | { |
1662 | struct snd_card *card = device->device_data; | 1662 | struct snd_card *card = device->device_data; |
1663 | int err, cardnum; | ||
1664 | char name[16]; | ||
1665 | 1663 | ||
1666 | if (snd_BUG_ON(!card)) | 1664 | return snd_register_device_for_dev(SNDRV_DEVICE_TYPE_CONTROL, card, |
1667 | return -ENXIO; | 1665 | -1, &snd_ctl_f_ops, card, |
1668 | cardnum = card->number; | 1666 | &card->ctl_dev, NULL, NULL); |
1669 | if (snd_BUG_ON(cardnum < 0 || cardnum >= SNDRV_CARDS)) | ||
1670 | return -ENXIO; | ||
1671 | sprintf(name, "controlC%i", cardnum); | ||
1672 | if ((err = snd_register_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1, | ||
1673 | &snd_ctl_f_ops, card, name)) < 0) | ||
1674 | return err; | ||
1675 | return 0; | ||
1676 | } | 1667 | } |
1677 | 1668 | ||
1678 | /* | 1669 | /* |
@@ -1682,13 +1673,6 @@ static int snd_ctl_dev_disconnect(struct snd_device *device) | |||
1682 | { | 1673 | { |
1683 | struct snd_card *card = device->device_data; | 1674 | struct snd_card *card = device->device_data; |
1684 | struct snd_ctl_file *ctl; | 1675 | struct snd_ctl_file *ctl; |
1685 | int err, cardnum; | ||
1686 | |||
1687 | if (snd_BUG_ON(!card)) | ||
1688 | return -ENXIO; | ||
1689 | cardnum = card->number; | ||
1690 | if (snd_BUG_ON(cardnum < 0 || cardnum >= SNDRV_CARDS)) | ||
1691 | return -ENXIO; | ||
1692 | 1676 | ||
1693 | read_lock(&card->ctl_files_rwlock); | 1677 | read_lock(&card->ctl_files_rwlock); |
1694 | list_for_each_entry(ctl, &card->ctl_files, list) { | 1678 | list_for_each_entry(ctl, &card->ctl_files, list) { |
@@ -1697,10 +1681,7 @@ static int snd_ctl_dev_disconnect(struct snd_device *device) | |||
1697 | } | 1681 | } |
1698 | read_unlock(&card->ctl_files_rwlock); | 1682 | read_unlock(&card->ctl_files_rwlock); |
1699 | 1683 | ||
1700 | if ((err = snd_unregister_device(SNDRV_DEVICE_TYPE_CONTROL, | 1684 | return snd_unregister_device(SNDRV_DEVICE_TYPE_CONTROL, card, -1); |
1701 | card, -1)) < 0) | ||
1702 | return err; | ||
1703 | return 0; | ||
1704 | } | 1685 | } |
1705 | 1686 | ||
1706 | /* | 1687 | /* |
@@ -1717,6 +1698,7 @@ static int snd_ctl_dev_free(struct snd_device *device) | |||
1717 | snd_ctl_remove(card, control); | 1698 | snd_ctl_remove(card, control); |
1718 | } | 1699 | } |
1719 | up_write(&card->controls_rwsem); | 1700 | up_write(&card->controls_rwsem); |
1701 | put_device(&card->ctl_dev); | ||
1720 | return 0; | 1702 | return 0; |
1721 | } | 1703 | } |
1722 | 1704 | ||
@@ -1731,10 +1713,20 @@ int snd_ctl_create(struct snd_card *card) | |||
1731 | .dev_register = snd_ctl_dev_register, | 1713 | .dev_register = snd_ctl_dev_register, |
1732 | .dev_disconnect = snd_ctl_dev_disconnect, | 1714 | .dev_disconnect = snd_ctl_dev_disconnect, |
1733 | }; | 1715 | }; |
1716 | int err; | ||
1734 | 1717 | ||
1735 | if (snd_BUG_ON(!card)) | 1718 | if (snd_BUG_ON(!card)) |
1736 | return -ENXIO; | 1719 | return -ENXIO; |
1737 | return snd_device_new(card, SNDRV_DEV_CONTROL, card, &ops); | 1720 | if (snd_BUG_ON(card->number < 0 || card->number >= SNDRV_CARDS)) |
1721 | return -ENXIO; | ||
1722 | |||
1723 | snd_device_initialize(&card->ctl_dev, card); | ||
1724 | dev_set_name(&card->ctl_dev, "controlC%d", card->number); | ||
1725 | |||
1726 | err = snd_device_new(card, SNDRV_DEV_CONTROL, card, &ops); | ||
1727 | if (err < 0) | ||
1728 | put_device(&card->ctl_dev); | ||
1729 | return err; | ||
1738 | } | 1730 | } |
1739 | 1731 | ||
1740 | /* | 1732 | /* |