diff options
Diffstat (limited to 'sound/core/device.c')
-rw-r--r-- | sound/core/device.c | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/sound/core/device.c b/sound/core/device.c index 41bec3075ae5..8918838b1999 100644 --- a/sound/core/device.c +++ b/sound/core/device.c | |||
@@ -50,10 +50,8 @@ int snd_device_new(struct snd_card *card, enum snd_device_type type, | |||
50 | if (snd_BUG_ON(!card || !device_data || !ops)) | 50 | if (snd_BUG_ON(!card || !device_data || !ops)) |
51 | return -ENXIO; | 51 | return -ENXIO; |
52 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | 52 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
53 | if (dev == NULL) { | 53 | if (!dev) |
54 | dev_err(card->dev, "Cannot allocate device, type=%d\n", type); | ||
55 | return -ENOMEM; | 54 | return -ENOMEM; |
56 | } | ||
57 | INIT_LIST_HEAD(&dev->list); | 55 | INIT_LIST_HEAD(&dev->list); |
58 | dev->card = card; | 56 | dev->card = card; |
59 | dev->type = type; | 57 | dev->type = type; |
@@ -73,7 +71,7 @@ int snd_device_new(struct snd_card *card, enum snd_device_type type, | |||
73 | } | 71 | } |
74 | EXPORT_SYMBOL(snd_device_new); | 72 | EXPORT_SYMBOL(snd_device_new); |
75 | 73 | ||
76 | static int __snd_device_disconnect(struct snd_device *dev) | 74 | static void __snd_device_disconnect(struct snd_device *dev) |
77 | { | 75 | { |
78 | if (dev->state == SNDRV_DEV_REGISTERED) { | 76 | if (dev->state == SNDRV_DEV_REGISTERED) { |
79 | if (dev->ops->dev_disconnect && | 77 | if (dev->ops->dev_disconnect && |
@@ -81,7 +79,6 @@ static int __snd_device_disconnect(struct snd_device *dev) | |||
81 | dev_err(dev->card->dev, "device disconnect failure\n"); | 79 | dev_err(dev->card->dev, "device disconnect failure\n"); |
82 | dev->state = SNDRV_DEV_DISCONNECTED; | 80 | dev->state = SNDRV_DEV_DISCONNECTED; |
83 | } | 81 | } |
84 | return 0; | ||
85 | } | 82 | } |
86 | 83 | ||
87 | static void __snd_device_free(struct snd_device *dev) | 84 | static void __snd_device_free(struct snd_device *dev) |
@@ -109,6 +106,34 @@ static struct snd_device *look_for_dev(struct snd_card *card, void *device_data) | |||
109 | } | 106 | } |
110 | 107 | ||
111 | /** | 108 | /** |
109 | * snd_device_disconnect - disconnect the device | ||
110 | * @card: the card instance | ||
111 | * @device_data: the data pointer to disconnect | ||
112 | * | ||
113 | * Turns the device into the disconnection state, invoking | ||
114 | * dev_disconnect callback, if the device was already registered. | ||
115 | * | ||
116 | * Usually called from snd_card_disconnect(). | ||
117 | * | ||
118 | * Return: Zero if successful, or a negative error code on failure or if the | ||
119 | * device not found. | ||
120 | */ | ||
121 | void snd_device_disconnect(struct snd_card *card, void *device_data) | ||
122 | { | ||
123 | struct snd_device *dev; | ||
124 | |||
125 | if (snd_BUG_ON(!card || !device_data)) | ||
126 | return; | ||
127 | dev = look_for_dev(card, device_data); | ||
128 | if (dev) | ||
129 | __snd_device_disconnect(dev); | ||
130 | else | ||
131 | dev_dbg(card->dev, "device disconnect %p (from %pF), not found\n", | ||
132 | device_data, __builtin_return_address(0)); | ||
133 | } | ||
134 | EXPORT_SYMBOL_GPL(snd_device_disconnect); | ||
135 | |||
136 | /** | ||
112 | * snd_device_free - release the device from the card | 137 | * snd_device_free - release the device from the card |
113 | * @card: the card instance | 138 | * @card: the card instance |
114 | * @device_data: the data pointer to release | 139 | * @device_data: the data pointer to release |
@@ -195,18 +220,14 @@ int snd_device_register_all(struct snd_card *card) | |||
195 | * disconnect all the devices on the card. | 220 | * disconnect all the devices on the card. |
196 | * called from init.c | 221 | * called from init.c |
197 | */ | 222 | */ |
198 | int snd_device_disconnect_all(struct snd_card *card) | 223 | void snd_device_disconnect_all(struct snd_card *card) |
199 | { | 224 | { |
200 | struct snd_device *dev; | 225 | struct snd_device *dev; |
201 | int err = 0; | ||
202 | 226 | ||
203 | if (snd_BUG_ON(!card)) | 227 | if (snd_BUG_ON(!card)) |
204 | return -ENXIO; | 228 | return; |
205 | list_for_each_entry_reverse(dev, &card->devices, list) { | 229 | list_for_each_entry_reverse(dev, &card->devices, list) |
206 | if (__snd_device_disconnect(dev) < 0) | 230 | __snd_device_disconnect(dev); |
207 | err = -ENXIO; | ||
208 | } | ||
209 | return err; | ||
210 | } | 231 | } |
211 | 232 | ||
212 | /* | 233 | /* |