aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core/sound.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/core/sound.c')
-rw-r--r--sound/core/sound.c56
1 files changed, 44 insertions, 12 deletions
diff --git a/sound/core/sound.c b/sound/core/sound.c
index b4430db3fa4c..efa476c5210a 100644
--- a/sound/core/sound.c
+++ b/sound/core/sound.c
@@ -268,7 +268,11 @@ int snd_register_device(int type, struct snd_card *card, int dev,
268 snd_minors[minor] = preg; 268 snd_minors[minor] = preg;
269 if (card) 269 if (card)
270 device = card->dev; 270 device = card->dev;
271 class_device_create(sound_class, NULL, MKDEV(major, minor), device, "%s", name); 271 preg->class_dev = class_device_create(sound_class, NULL,
272 MKDEV(major, minor),
273 device, "%s", name);
274 if (preg->class_dev)
275 class_set_devdata(preg->class_dev, private_data);
272 276
273 mutex_unlock(&sound_mutex); 277 mutex_unlock(&sound_mutex);
274 return 0; 278 return 0;
@@ -276,6 +280,24 @@ int snd_register_device(int type, struct snd_card *card, int dev,
276 280
277EXPORT_SYMBOL(snd_register_device); 281EXPORT_SYMBOL(snd_register_device);
278 282
283/* find the matching minor record
284 * return the index of snd_minor, or -1 if not found
285 */
286static int find_snd_minor(int type, struct snd_card *card, int dev)
287{
288 int cardnum, minor;
289 struct snd_minor *mptr;
290
291 cardnum = card ? card->number : -1;
292 for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor)
293 if ((mptr = snd_minors[minor]) != NULL &&
294 mptr->type == type &&
295 mptr->card == cardnum &&
296 mptr->device == dev)
297 return minor;
298 return -1;
299}
300
279/** 301/**
280 * snd_unregister_device - unregister the device on the given card 302 * snd_unregister_device - unregister the device on the given card
281 * @type: the device type, SNDRV_DEVICE_TYPE_XXX 303 * @type: the device type, SNDRV_DEVICE_TYPE_XXX
@@ -289,32 +311,42 @@ EXPORT_SYMBOL(snd_register_device);
289 */ 311 */
290int snd_unregister_device(int type, struct snd_card *card, int dev) 312int snd_unregister_device(int type, struct snd_card *card, int dev)
291{ 313{
292 int cardnum, minor; 314 int minor;
293 struct snd_minor *mptr;
294 315
295 cardnum = card ? card->number : -1;
296 mutex_lock(&sound_mutex); 316 mutex_lock(&sound_mutex);
297 for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) 317 minor = find_snd_minor(type, card, dev);
298 if ((mptr = snd_minors[minor]) != NULL && 318 if (minor < 0) {
299 mptr->type == type &&
300 mptr->card == cardnum &&
301 mptr->device == dev)
302 break;
303 if (minor == ARRAY_SIZE(snd_minors)) {
304 mutex_unlock(&sound_mutex); 319 mutex_unlock(&sound_mutex);
305 return -EINVAL; 320 return -EINVAL;
306 } 321 }
307 322
308 class_device_destroy(sound_class, MKDEV(major, minor)); 323 class_device_destroy(sound_class, MKDEV(major, minor));
309 324
325 kfree(snd_minors[minor]);
310 snd_minors[minor] = NULL; 326 snd_minors[minor] = NULL;
311 mutex_unlock(&sound_mutex); 327 mutex_unlock(&sound_mutex);
312 kfree(mptr);
313 return 0; 328 return 0;
314} 329}
315 330
316EXPORT_SYMBOL(snd_unregister_device); 331EXPORT_SYMBOL(snd_unregister_device);
317 332
333int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev,
334 const struct class_device_attribute *attr)
335{
336 int minor, ret = -EINVAL;
337 struct class_device *cdev;
338
339 mutex_lock(&sound_mutex);
340 minor = find_snd_minor(type, card, dev);
341 if (minor >= 0 && (cdev = snd_minors[minor]->class_dev) != NULL)
342 ret = class_device_create_file(cdev, attr);
343 mutex_unlock(&sound_mutex);
344 return ret;
345
346}
347
348EXPORT_SYMBOL(snd_add_device_sysfs_file);
349
318#ifdef CONFIG_PROC_FS 350#ifdef CONFIG_PROC_FS
319/* 351/*
320 * INFO PART 352 * INFO PART