[PATCH] orinoco: orinoco_xmit() should only return valid symbolic constants
[linux-2.6/sactl.git] / sound / core / info.c
blob2582b74d319953ebd0cb95d46f36d7e044e520fe
1 /*
2 * Information interface for ALSA driver
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sound/driver.h>
23 #include <linux/init.h>
24 #include <linux/vmalloc.h>
25 #include <linux/time.h>
26 #include <linux/smp_lock.h>
27 #include <linux/string.h>
28 #include <sound/core.h>
29 #include <sound/minors.h>
30 #include <sound/info.h>
31 #include <sound/version.h>
32 #include <linux/proc_fs.h>
33 #include <linux/devfs_fs_kernel.h>
34 #include <linux/mutex.h>
35 #include <stdarg.h>
41 #ifdef CONFIG_PROC_FS
43 int snd_info_check_reserved_words(const char *str)
45 static char *reserved[] =
47 "version",
48 "meminfo",
49 "memdebug",
50 "detect",
51 "devices",
52 "oss",
53 "cards",
54 "timers",
55 "synth",
56 "pcm",
57 "seq",
58 NULL
60 char **xstr = reserved;
62 while (*xstr) {
63 if (!strcmp(*xstr, str))
64 return 0;
65 xstr++;
67 if (!strncmp(str, "card", 4))
68 return 0;
69 return 1;
72 static DEFINE_MUTEX(info_mutex);
74 struct snd_info_private_data {
75 struct snd_info_buffer *rbuffer;
76 struct snd_info_buffer *wbuffer;
77 struct snd_info_entry *entry;
78 void *file_private_data;
81 static int snd_info_version_init(void);
82 static int snd_info_version_done(void);
85 /**
86 * snd_iprintf - printf on the procfs buffer
87 * @buffer: the procfs buffer
88 * @fmt: the printf format
90 * Outputs the string on the procfs buffer just like printf().
92 * Returns the size of output string.
94 int snd_iprintf(struct snd_info_buffer *buffer, char *fmt,...)
96 va_list args;
97 int len, res;
99 if (buffer->stop || buffer->error)
100 return 0;
101 len = buffer->len - buffer->size;
102 va_start(args, fmt);
103 res = vsnprintf(buffer->curr, len, fmt, args);
104 va_end(args);
105 if (res >= len) {
106 buffer->stop = 1;
107 return 0;
109 buffer->curr += res;
110 buffer->size += res;
111 return res;
118 static struct proc_dir_entry *snd_proc_root = NULL;
119 struct snd_info_entry *snd_seq_root = NULL;
120 #ifdef CONFIG_SND_OSSEMUL
121 struct snd_info_entry *snd_oss_root = NULL;
122 #endif
124 static inline void snd_info_entry_prepare(struct proc_dir_entry *de)
126 de->owner = THIS_MODULE;
129 static void snd_remove_proc_entry(struct proc_dir_entry *parent,
130 struct proc_dir_entry *de)
132 if (de)
133 remove_proc_entry(de->name, parent);
136 static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig)
138 struct snd_info_private_data *data;
139 struct snd_info_entry *entry;
140 loff_t ret;
142 data = file->private_data;
143 entry = data->entry;
144 lock_kernel();
145 switch (entry->content) {
146 case SNDRV_INFO_CONTENT_TEXT:
147 switch (orig) {
148 case 0: /* SEEK_SET */
149 file->f_pos = offset;
150 ret = file->f_pos;
151 goto out;
152 case 1: /* SEEK_CUR */
153 file->f_pos += offset;
154 ret = file->f_pos;
155 goto out;
156 case 2: /* SEEK_END */
157 default:
158 ret = -EINVAL;
159 goto out;
161 break;
162 case SNDRV_INFO_CONTENT_DATA:
163 if (entry->c.ops->llseek) {
164 ret = entry->c.ops->llseek(entry,
165 data->file_private_data,
166 file, offset, orig);
167 goto out;
169 break;
171 ret = -ENXIO;
172 out:
173 unlock_kernel();
174 return ret;
177 static ssize_t snd_info_entry_read(struct file *file, char __user *buffer,
178 size_t count, loff_t * offset)
180 struct snd_info_private_data *data;
181 struct snd_info_entry *entry;
182 struct snd_info_buffer *buf;
183 size_t size = 0;
184 loff_t pos;
186 data = file->private_data;
187 snd_assert(data != NULL, return -ENXIO);
188 pos = *offset;
189 if (pos < 0 || (long) pos != pos || (ssize_t) count < 0)
190 return -EIO;
191 if ((unsigned long) pos + (unsigned long) count < (unsigned long) pos)
192 return -EIO;
193 entry = data->entry;
194 switch (entry->content) {
195 case SNDRV_INFO_CONTENT_TEXT:
196 buf = data->rbuffer;
197 if (buf == NULL)
198 return -EIO;
199 if (pos >= buf->size)
200 return 0;
201 size = buf->size - pos;
202 size = min(count, size);
203 if (copy_to_user(buffer, buf->buffer + pos, size))
204 return -EFAULT;
205 break;
206 case SNDRV_INFO_CONTENT_DATA:
207 if (entry->c.ops->read)
208 size = entry->c.ops->read(entry,
209 data->file_private_data,
210 file, buffer, count, pos);
211 break;
213 if ((ssize_t) size > 0)
214 *offset = pos + size;
215 return size;
218 static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer,
219 size_t count, loff_t * offset)
221 struct snd_info_private_data *data;
222 struct snd_info_entry *entry;
223 struct snd_info_buffer *buf;
224 size_t size = 0;
225 loff_t pos;
227 data = file->private_data;
228 snd_assert(data != NULL, return -ENXIO);
229 entry = data->entry;
230 pos = *offset;
231 if (pos < 0 || (long) pos != pos || (ssize_t) count < 0)
232 return -EIO;
233 if ((unsigned long) pos + (unsigned long) count < (unsigned long) pos)
234 return -EIO;
235 switch (entry->content) {
236 case SNDRV_INFO_CONTENT_TEXT:
237 buf = data->wbuffer;
238 if (buf == NULL)
239 return -EIO;
240 if (pos >= buf->len)
241 return -ENOMEM;
242 size = buf->len - pos;
243 size = min(count, size);
244 if (copy_from_user(buf->buffer + pos, buffer, size))
245 return -EFAULT;
246 if ((long)buf->size < pos + size)
247 buf->size = pos + size;
248 break;
249 case SNDRV_INFO_CONTENT_DATA:
250 if (entry->c.ops->write)
251 size = entry->c.ops->write(entry,
252 data->file_private_data,
253 file, buffer, count, pos);
254 break;
256 if ((ssize_t) size > 0)
257 *offset = pos + size;
258 return size;
261 static int snd_info_entry_open(struct inode *inode, struct file *file)
263 struct snd_info_entry *entry;
264 struct snd_info_private_data *data;
265 struct snd_info_buffer *buffer;
266 struct proc_dir_entry *p;
267 int mode, err;
269 mutex_lock(&info_mutex);
270 p = PDE(inode);
271 entry = p == NULL ? NULL : (struct snd_info_entry *)p->data;
272 if (entry == NULL || entry->disconnected) {
273 mutex_unlock(&info_mutex);
274 return -ENODEV;
276 if (!try_module_get(entry->module)) {
277 err = -EFAULT;
278 goto __error1;
280 mode = file->f_flags & O_ACCMODE;
281 if (mode == O_RDONLY || mode == O_RDWR) {
282 if ((entry->content == SNDRV_INFO_CONTENT_TEXT &&
283 !entry->c.text.read_size) ||
284 (entry->content == SNDRV_INFO_CONTENT_DATA &&
285 entry->c.ops->read == NULL)) {
286 err = -ENODEV;
287 goto __error;
290 if (mode == O_WRONLY || mode == O_RDWR) {
291 if ((entry->content == SNDRV_INFO_CONTENT_TEXT &&
292 !entry->c.text.write_size) ||
293 (entry->content == SNDRV_INFO_CONTENT_DATA &&
294 entry->c.ops->write == NULL)) {
295 err = -ENODEV;
296 goto __error;
299 data = kzalloc(sizeof(*data), GFP_KERNEL);
300 if (data == NULL) {
301 err = -ENOMEM;
302 goto __error;
304 data->entry = entry;
305 switch (entry->content) {
306 case SNDRV_INFO_CONTENT_TEXT:
307 if (mode == O_RDONLY || mode == O_RDWR) {
308 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
309 if (buffer == NULL) {
310 kfree(data);
311 err = -ENOMEM;
312 goto __error;
314 buffer->len = (entry->c.text.read_size +
315 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
316 buffer->buffer = vmalloc(buffer->len);
317 if (buffer->buffer == NULL) {
318 kfree(buffer);
319 kfree(data);
320 err = -ENOMEM;
321 goto __error;
323 buffer->curr = buffer->buffer;
324 data->rbuffer = buffer;
326 if (mode == O_WRONLY || mode == O_RDWR) {
327 buffer = kzalloc(sizeof(*buffer), GFP_KERNEL);
328 if (buffer == NULL) {
329 if (mode == O_RDWR) {
330 vfree(data->rbuffer->buffer);
331 kfree(data->rbuffer);
333 kfree(data);
334 err = -ENOMEM;
335 goto __error;
337 buffer->len = (entry->c.text.write_size +
338 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
339 buffer->buffer = vmalloc(buffer->len);
340 if (buffer->buffer == NULL) {
341 if (mode == O_RDWR) {
342 vfree(data->rbuffer->buffer);
343 kfree(data->rbuffer);
345 kfree(buffer);
346 kfree(data);
347 err = -ENOMEM;
348 goto __error;
350 buffer->curr = buffer->buffer;
351 data->wbuffer = buffer;
353 break;
354 case SNDRV_INFO_CONTENT_DATA: /* data */
355 if (entry->c.ops->open) {
356 if ((err = entry->c.ops->open(entry, mode,
357 &data->file_private_data)) < 0) {
358 kfree(data);
359 goto __error;
362 break;
364 file->private_data = data;
365 mutex_unlock(&info_mutex);
366 if (entry->content == SNDRV_INFO_CONTENT_TEXT &&
367 (mode == O_RDONLY || mode == O_RDWR)) {
368 if (entry->c.text.read) {
369 mutex_lock(&entry->access);
370 entry->c.text.read(entry, data->rbuffer);
371 mutex_unlock(&entry->access);
374 return 0;
376 __error:
377 module_put(entry->module);
378 __error1:
379 mutex_unlock(&info_mutex);
380 return err;
383 static int snd_info_entry_release(struct inode *inode, struct file *file)
385 struct snd_info_entry *entry;
386 struct snd_info_private_data *data;
387 int mode;
389 mode = file->f_flags & O_ACCMODE;
390 data = file->private_data;
391 entry = data->entry;
392 switch (entry->content) {
393 case SNDRV_INFO_CONTENT_TEXT:
394 if (mode == O_RDONLY || mode == O_RDWR) {
395 vfree(data->rbuffer->buffer);
396 kfree(data->rbuffer);
398 if (mode == O_WRONLY || mode == O_RDWR) {
399 if (entry->c.text.write) {
400 entry->c.text.write(entry, data->wbuffer);
401 if (data->wbuffer->error) {
402 snd_printk(KERN_WARNING "data write error to %s (%i)\n",
403 entry->name,
404 data->wbuffer->error);
407 vfree(data->wbuffer->buffer);
408 kfree(data->wbuffer);
410 break;
411 case SNDRV_INFO_CONTENT_DATA:
412 if (entry->c.ops->release)
413 entry->c.ops->release(entry, mode,
414 data->file_private_data);
415 break;
417 module_put(entry->module);
418 kfree(data);
419 return 0;
422 static unsigned int snd_info_entry_poll(struct file *file, poll_table * wait)
424 struct snd_info_private_data *data;
425 struct snd_info_entry *entry;
426 unsigned int mask;
428 data = file->private_data;
429 if (data == NULL)
430 return 0;
431 entry = data->entry;
432 mask = 0;
433 switch (entry->content) {
434 case SNDRV_INFO_CONTENT_DATA:
435 if (entry->c.ops->poll)
436 return entry->c.ops->poll(entry,
437 data->file_private_data,
438 file, wait);
439 if (entry->c.ops->read)
440 mask |= POLLIN | POLLRDNORM;
441 if (entry->c.ops->write)
442 mask |= POLLOUT | POLLWRNORM;
443 break;
445 return mask;
448 static long snd_info_entry_ioctl(struct file *file, unsigned int cmd,
449 unsigned long arg)
451 struct snd_info_private_data *data;
452 struct snd_info_entry *entry;
454 data = file->private_data;
455 if (data == NULL)
456 return 0;
457 entry = data->entry;
458 switch (entry->content) {
459 case SNDRV_INFO_CONTENT_DATA:
460 if (entry->c.ops->ioctl)
461 return entry->c.ops->ioctl(entry,
462 data->file_private_data,
463 file, cmd, arg);
464 break;
466 return -ENOTTY;
469 static int snd_info_entry_mmap(struct file *file, struct vm_area_struct *vma)
471 struct inode *inode = file->f_dentry->d_inode;
472 struct snd_info_private_data *data;
473 struct snd_info_entry *entry;
475 data = file->private_data;
476 if (data == NULL)
477 return 0;
478 entry = data->entry;
479 switch (entry->content) {
480 case SNDRV_INFO_CONTENT_DATA:
481 if (entry->c.ops->mmap)
482 return entry->c.ops->mmap(entry,
483 data->file_private_data,
484 inode, file, vma);
485 break;
487 return -ENXIO;
490 static struct file_operations snd_info_entry_operations =
492 .owner = THIS_MODULE,
493 .llseek = snd_info_entry_llseek,
494 .read = snd_info_entry_read,
495 .write = snd_info_entry_write,
496 .poll = snd_info_entry_poll,
497 .unlocked_ioctl = snd_info_entry_ioctl,
498 .mmap = snd_info_entry_mmap,
499 .open = snd_info_entry_open,
500 .release = snd_info_entry_release,
504 * snd_create_proc_entry - create a procfs entry
505 * @name: the name of the proc file
506 * @mode: the file permission bits, S_Ixxx
507 * @parent: the parent proc-directory entry
509 * Creates a new proc file entry with the given name and permission
510 * on the given directory.
512 * Returns the pointer of new instance or NULL on failure.
514 static struct proc_dir_entry *snd_create_proc_entry(const char *name, mode_t mode,
515 struct proc_dir_entry *parent)
517 struct proc_dir_entry *p;
518 p = create_proc_entry(name, mode, parent);
519 if (p)
520 snd_info_entry_prepare(p);
521 return p;
524 int __init snd_info_init(void)
526 struct proc_dir_entry *p;
528 p = snd_create_proc_entry("asound", S_IFDIR | S_IRUGO | S_IXUGO, &proc_root);
529 if (p == NULL)
530 return -ENOMEM;
531 snd_proc_root = p;
532 #ifdef CONFIG_SND_OSSEMUL
534 struct snd_info_entry *entry;
535 if ((entry = snd_info_create_module_entry(THIS_MODULE, "oss", NULL)) == NULL)
536 return -ENOMEM;
537 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
538 if (snd_info_register(entry) < 0) {
539 snd_info_free_entry(entry);
540 return -ENOMEM;
542 snd_oss_root = entry;
544 #endif
545 #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
547 struct snd_info_entry *entry;
548 if ((entry = snd_info_create_module_entry(THIS_MODULE, "seq", NULL)) == NULL)
549 return -ENOMEM;
550 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
551 if (snd_info_register(entry) < 0) {
552 snd_info_free_entry(entry);
553 return -ENOMEM;
555 snd_seq_root = entry;
557 #endif
558 snd_info_version_init();
559 snd_minor_info_init();
560 snd_minor_info_oss_init();
561 snd_card_info_init();
562 return 0;
565 int __exit snd_info_done(void)
567 snd_card_info_done();
568 snd_minor_info_oss_done();
569 snd_minor_info_done();
570 snd_info_version_done();
571 if (snd_proc_root) {
572 #if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
573 snd_info_unregister(snd_seq_root);
574 #endif
575 #ifdef CONFIG_SND_OSSEMUL
576 snd_info_unregister(snd_oss_root);
577 #endif
578 snd_remove_proc_entry(&proc_root, snd_proc_root);
580 return 0;
589 * create a card proc file
590 * called from init.c
592 int snd_info_card_create(struct snd_card *card)
594 char str[8];
595 struct snd_info_entry *entry;
597 snd_assert(card != NULL, return -ENXIO);
599 sprintf(str, "card%i", card->number);
600 if ((entry = snd_info_create_module_entry(card->module, str, NULL)) == NULL)
601 return -ENOMEM;
602 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
603 if (snd_info_register(entry) < 0) {
604 snd_info_free_entry(entry);
605 return -ENOMEM;
607 card->proc_root = entry;
608 return 0;
612 * register the card proc file
613 * called from init.c
615 int snd_info_card_register(struct snd_card *card)
617 struct proc_dir_entry *p;
619 snd_assert(card != NULL, return -ENXIO);
621 if (!strcmp(card->id, card->proc_root->name))
622 return 0;
624 p = proc_symlink(card->id, snd_proc_root, card->proc_root->name);
625 if (p == NULL)
626 return -ENOMEM;
627 card->proc_root_link = p;
628 return 0;
632 * de-register the card proc file
633 * called from init.c
635 int snd_info_card_free(struct snd_card *card)
637 snd_assert(card != NULL, return -ENXIO);
638 if (card->proc_root_link) {
639 snd_remove_proc_entry(snd_proc_root, card->proc_root_link);
640 card->proc_root_link = NULL;
642 if (card->proc_root) {
643 snd_info_unregister(card->proc_root);
644 card->proc_root = NULL;
646 return 0;
651 * snd_info_get_line - read one line from the procfs buffer
652 * @buffer: the procfs buffer
653 * @line: the buffer to store
654 * @len: the max. buffer size - 1
656 * Reads one line from the buffer and stores the string.
658 * Returns zero if successful, or 1 if error or EOF.
660 int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len)
662 int c = -1;
664 if (len <= 0 || buffer->stop || buffer->error)
665 return 1;
666 while (--len > 0) {
667 c = *buffer->curr++;
668 if (c == '\n') {
669 if ((buffer->curr - buffer->buffer) >= (long)buffer->size) {
670 buffer->stop = 1;
672 break;
674 *line++ = c;
675 if ((buffer->curr - buffer->buffer) >= (long)buffer->size) {
676 buffer->stop = 1;
677 break;
680 while (c != '\n' && !buffer->stop) {
681 c = *buffer->curr++;
682 if ((buffer->curr - buffer->buffer) >= (long)buffer->size) {
683 buffer->stop = 1;
686 *line = '\0';
687 return 0;
691 * snd_info_get_str - parse a string token
692 * @dest: the buffer to store the string token
693 * @src: the original string
694 * @len: the max. length of token - 1
696 * Parses the original string and copy a token to the given
697 * string buffer.
699 * Returns the updated pointer of the original string so that
700 * it can be used for the next call.
702 char *snd_info_get_str(char *dest, char *src, int len)
704 int c;
706 while (*src == ' ' || *src == '\t')
707 src++;
708 if (*src == '"' || *src == '\'') {
709 c = *src++;
710 while (--len > 0 && *src && *src != c) {
711 *dest++ = *src++;
713 if (*src == c)
714 src++;
715 } else {
716 while (--len > 0 && *src && *src != ' ' && *src != '\t') {
717 *dest++ = *src++;
720 *dest = 0;
721 while (*src == ' ' || *src == '\t')
722 src++;
723 return src;
727 * snd_info_create_entry - create an info entry
728 * @name: the proc file name
730 * Creates an info entry with the given file name and initializes as
731 * the default state.
733 * Usually called from other functions such as
734 * snd_info_create_card_entry().
736 * Returns the pointer of the new instance, or NULL on failure.
738 static struct snd_info_entry *snd_info_create_entry(const char *name)
740 struct snd_info_entry *entry;
741 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
742 if (entry == NULL)
743 return NULL;
744 entry->name = kstrdup(name, GFP_KERNEL);
745 if (entry->name == NULL) {
746 kfree(entry);
747 return NULL;
749 entry->mode = S_IFREG | S_IRUGO;
750 entry->content = SNDRV_INFO_CONTENT_TEXT;
751 mutex_init(&entry->access);
752 return entry;
756 * snd_info_create_module_entry - create an info entry for the given module
757 * @module: the module pointer
758 * @name: the file name
759 * @parent: the parent directory
761 * Creates a new info entry and assigns it to the given module.
763 * Returns the pointer of the new instance, or NULL on failure.
765 struct snd_info_entry *snd_info_create_module_entry(struct module * module,
766 const char *name,
767 struct snd_info_entry *parent)
769 struct snd_info_entry *entry = snd_info_create_entry(name);
770 if (entry) {
771 entry->module = module;
772 entry->parent = parent;
774 return entry;
778 * snd_info_create_card_entry - create an info entry for the given card
779 * @card: the card instance
780 * @name: the file name
781 * @parent: the parent directory
783 * Creates a new info entry and assigns it to the given card.
785 * Returns the pointer of the new instance, or NULL on failure.
787 struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card,
788 const char *name,
789 struct snd_info_entry * parent)
791 struct snd_info_entry *entry = snd_info_create_entry(name);
792 if (entry) {
793 entry->module = card->module;
794 entry->card = card;
795 entry->parent = parent;
797 return entry;
800 static int snd_info_dev_free_entry(struct snd_device *device)
802 struct snd_info_entry *entry = device->device_data;
803 snd_info_free_entry(entry);
804 return 0;
807 static int snd_info_dev_register_entry(struct snd_device *device)
809 struct snd_info_entry *entry = device->device_data;
810 return snd_info_register(entry);
813 static int snd_info_dev_disconnect_entry(struct snd_device *device)
815 struct snd_info_entry *entry = device->device_data;
816 entry->disconnected = 1;
817 return 0;
820 static int snd_info_dev_unregister_entry(struct snd_device *device)
822 struct snd_info_entry *entry = device->device_data;
823 return snd_info_unregister(entry);
827 * snd_card_proc_new - create an info entry for the given card
828 * @card: the card instance
829 * @name: the file name
830 * @entryp: the pointer to store the new info entry
832 * Creates a new info entry and assigns it to the given card.
833 * Unlike snd_info_create_card_entry(), this function registers the
834 * info entry as an ALSA device component, so that it can be
835 * unregistered/released without explicit call.
836 * Also, you don't have to register this entry via snd_info_register(),
837 * since this will be registered by snd_card_register() automatically.
839 * The parent is assumed as card->proc_root.
841 * For releasing this entry, use snd_device_free() instead of
842 * snd_info_free_entry().
844 * Returns zero if successful, or a negative error code on failure.
846 int snd_card_proc_new(struct snd_card *card, const char *name,
847 struct snd_info_entry **entryp)
849 static struct snd_device_ops ops = {
850 .dev_free = snd_info_dev_free_entry,
851 .dev_register = snd_info_dev_register_entry,
852 .dev_disconnect = snd_info_dev_disconnect_entry,
853 .dev_unregister = snd_info_dev_unregister_entry
855 struct snd_info_entry *entry;
856 int err;
858 entry = snd_info_create_card_entry(card, name, card->proc_root);
859 if (! entry)
860 return -ENOMEM;
861 if ((err = snd_device_new(card, SNDRV_DEV_INFO, entry, &ops)) < 0) {
862 snd_info_free_entry(entry);
863 return err;
865 if (entryp)
866 *entryp = entry;
867 return 0;
871 * snd_info_free_entry - release the info entry
872 * @entry: the info entry
874 * Releases the info entry. Don't call this after registered.
876 void snd_info_free_entry(struct snd_info_entry * entry)
878 if (entry == NULL)
879 return;
880 kfree(entry->name);
881 if (entry->private_free)
882 entry->private_free(entry);
883 kfree(entry);
887 * snd_info_register - register the info entry
888 * @entry: the info entry
890 * Registers the proc info entry.
892 * Returns zero if successful, or a negative error code on failure.
894 int snd_info_register(struct snd_info_entry * entry)
896 struct proc_dir_entry *root, *p = NULL;
898 snd_assert(entry != NULL, return -ENXIO);
899 root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
900 mutex_lock(&info_mutex);
901 p = snd_create_proc_entry(entry->name, entry->mode, root);
902 if (!p) {
903 mutex_unlock(&info_mutex);
904 return -ENOMEM;
906 p->owner = entry->module;
907 if (!S_ISDIR(entry->mode))
908 p->proc_fops = &snd_info_entry_operations;
909 p->size = entry->size;
910 p->data = entry;
911 entry->p = p;
912 mutex_unlock(&info_mutex);
913 return 0;
917 * snd_info_unregister - de-register the info entry
918 * @entry: the info entry
920 * De-registers the info entry and releases the instance.
922 * Returns zero if successful, or a negative error code on failure.
924 int snd_info_unregister(struct snd_info_entry * entry)
926 struct proc_dir_entry *root;
928 if (! entry)
929 return 0;
930 snd_assert(entry->p != NULL, return -ENXIO);
931 root = entry->parent == NULL ? snd_proc_root : entry->parent->p;
932 snd_assert(root, return -ENXIO);
933 mutex_lock(&info_mutex);
934 snd_remove_proc_entry(root, entry->p);
935 mutex_unlock(&info_mutex);
936 snd_info_free_entry(entry);
937 return 0;
944 static struct snd_info_entry *snd_info_version_entry = NULL;
946 static void snd_info_version_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
948 snd_iprintf(buffer,
949 "Advanced Linux Sound Architecture Driver Version "
950 CONFIG_SND_VERSION CONFIG_SND_DATE ".\n"
954 static int __init snd_info_version_init(void)
956 struct snd_info_entry *entry;
958 entry = snd_info_create_module_entry(THIS_MODULE, "version", NULL);
959 if (entry == NULL)
960 return -ENOMEM;
961 entry->c.text.read_size = 256;
962 entry->c.text.read = snd_info_version_read;
963 if (snd_info_register(entry) < 0) {
964 snd_info_free_entry(entry);
965 return -ENOMEM;
967 snd_info_version_entry = entry;
968 return 0;
971 static int __exit snd_info_version_done(void)
973 if (snd_info_version_entry)
974 snd_info_unregister(snd_info_version_entry);
975 return 0;
978 #endif /* CONFIG_PROC_FS */