Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Information interface for ALSA driver |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 3 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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 |
| 19 | * |
| 20 | */ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/time.h> |
Andrea Righi | 27ac792 | 2008-07-23 21:28:13 -0700 | [diff] [blame] | 24 | #include <linux/mm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Paulo Marques | 543537b | 2005-06-23 00:09:02 -0700 | [diff] [blame] | 26 | #include <linux/string.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <sound/core.h> |
| 29 | #include <sound/minors.h> |
| 30 | #include <sound/info.h> |
Jaroslav Kysela | 4266274 | 2012-09-04 11:21:45 +0200 | [diff] [blame] | 31 | #include <linux/utsname.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/proc_fs.h> |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 33 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <stdarg.h> |
| 35 | |
| 36 | /* |
| 37 | * |
| 38 | */ |
| 39 | |
Takashi Iwai | e28563c | 2005-12-01 10:42:42 +0100 | [diff] [blame] | 40 | #ifdef CONFIG_PROC_FS |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | int snd_info_check_reserved_words(const char *str) |
| 43 | { |
| 44 | static char *reserved[] = |
| 45 | { |
| 46 | "version", |
| 47 | "meminfo", |
| 48 | "memdebug", |
| 49 | "detect", |
| 50 | "devices", |
| 51 | "oss", |
| 52 | "cards", |
| 53 | "timers", |
| 54 | "synth", |
| 55 | "pcm", |
| 56 | "seq", |
| 57 | NULL |
| 58 | }; |
| 59 | char **xstr = reserved; |
| 60 | |
| 61 | while (*xstr) { |
| 62 | if (!strcmp(*xstr, str)) |
| 63 | return 0; |
| 64 | xstr++; |
| 65 | } |
| 66 | if (!strncmp(str, "card", 4)) |
| 67 | return 0; |
| 68 | return 1; |
| 69 | } |
| 70 | |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 71 | static DEFINE_MUTEX(info_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 73 | struct snd_info_private_data { |
| 74 | struct snd_info_buffer *rbuffer; |
| 75 | struct snd_info_buffer *wbuffer; |
| 76 | struct snd_info_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | void *file_private_data; |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 78 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | static int snd_info_version_init(void); |
| 81 | static int snd_info_version_done(void); |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 82 | static void snd_info_disconnect(struct snd_info_entry *entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* |
| 85 | |
| 86 | */ |
| 87 | |
Takashi Iwai | 6581f4e | 2006-05-17 17:14:51 +0200 | [diff] [blame] | 88 | static struct proc_dir_entry *snd_proc_root; |
| 89 | struct snd_info_entry *snd_seq_root; |
Takashi Iwai | c0d3fb3 | 2006-04-28 15:13:39 +0200 | [diff] [blame] | 90 | EXPORT_SYMBOL(snd_seq_root); |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | #ifdef CONFIG_SND_OSSEMUL |
Takashi Iwai | 6581f4e | 2006-05-17 17:14:51 +0200 | [diff] [blame] | 93 | struct snd_info_entry *snd_oss_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | #endif |
| 95 | |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 96 | static int alloc_info_private(struct snd_info_entry *entry, |
| 97 | struct snd_info_private_data **ret) |
| 98 | { |
| 99 | struct snd_info_private_data *data; |
| 100 | |
| 101 | if (!entry || !entry->p) |
| 102 | return -ENODEV; |
| 103 | if (!try_module_get(entry->module)) |
| 104 | return -EFAULT; |
| 105 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
| 106 | if (!data) { |
| 107 | module_put(entry->module); |
| 108 | return -ENOMEM; |
| 109 | } |
| 110 | data->entry = entry; |
| 111 | *ret = data; |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | static bool valid_pos(loff_t pos, size_t count) |
| 116 | { |
| 117 | if (pos < 0 || (long) pos != pos || (ssize_t) count < 0) |
| 118 | return false; |
| 119 | if ((unsigned long) pos + (unsigned long) count < (unsigned long) pos) |
| 120 | return false; |
| 121 | return true; |
| 122 | } |
| 123 | |
| 124 | /* |
| 125 | * file ops for binary proc files |
| 126 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig) |
| 128 | { |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 129 | struct snd_info_private_data *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | struct snd_info_entry *entry; |
Takashi Iwai | 73029e0 | 2010-04-13 11:39:47 +0200 | [diff] [blame] | 131 | loff_t ret = -EINVAL, size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | data = file->private_data; |
| 134 | entry = data->entry; |
Takashi Iwai | 5b5cd55 | 2010-04-07 18:33:57 +0200 | [diff] [blame] | 135 | mutex_lock(&entry->access); |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 136 | if (entry->c.ops->llseek) { |
Takashi Iwai | 73029e0 | 2010-04-13 11:39:47 +0200 | [diff] [blame] | 137 | offset = entry->c.ops->llseek(entry, |
| 138 | data->file_private_data, |
| 139 | file, offset, orig); |
| 140 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 142 | |
| 143 | size = entry->size; |
Takashi Iwai | 73029e0 | 2010-04-13 11:39:47 +0200 | [diff] [blame] | 144 | switch (orig) { |
| 145 | case SEEK_SET: |
| 146 | break; |
| 147 | case SEEK_CUR: |
| 148 | offset += file->f_pos; |
| 149 | break; |
| 150 | case SEEK_END: |
| 151 | if (!size) |
| 152 | goto out; |
| 153 | offset += size; |
| 154 | break; |
| 155 | default: |
| 156 | goto out; |
| 157 | } |
| 158 | if (offset < 0) |
| 159 | goto out; |
| 160 | if (size && offset > size) |
| 161 | offset = size; |
| 162 | file->f_pos = offset; |
| 163 | ret = offset; |
| 164 | out: |
Takashi Iwai | 5b5cd55 | 2010-04-07 18:33:57 +0200 | [diff] [blame] | 165 | mutex_unlock(&entry->access); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | return ret; |
| 167 | } |
| 168 | |
| 169 | static ssize_t snd_info_entry_read(struct file *file, char __user *buffer, |
| 170 | size_t count, loff_t * offset) |
| 171 | { |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 172 | struct snd_info_private_data *data = file->private_data; |
| 173 | struct snd_info_entry *entry = data->entry; |
| 174 | size_t size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | loff_t pos; |
| 176 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | pos = *offset; |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 178 | if (!valid_pos(pos, count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | return -EIO; |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 180 | if (pos >= entry->size) |
| 181 | return 0; |
| 182 | size = entry->size - pos; |
| 183 | size = min(count, size); |
| 184 | size = entry->c.ops->read(entry, data->file_private_data, |
| 185 | file, buffer, size, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | if ((ssize_t) size > 0) |
| 187 | *offset = pos + size; |
| 188 | return size; |
| 189 | } |
| 190 | |
| 191 | static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer, |
| 192 | size_t count, loff_t * offset) |
| 193 | { |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 194 | struct snd_info_private_data *data = file->private_data; |
| 195 | struct snd_info_entry *entry = data->entry; |
Takashi Iwai | 7e4eeec | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 196 | ssize_t size = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | loff_t pos; |
| 198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | pos = *offset; |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 200 | if (!valid_pos(pos, count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | return -EIO; |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 202 | if (count > 0) { |
| 203 | size_t maxsize = entry->size - pos; |
| 204 | count = min(count, maxsize); |
| 205 | size = entry->c.ops->write(entry, data->file_private_data, |
| 206 | file, buffer, count, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 208 | if (size > 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | *offset = pos + size; |
| 210 | return size; |
| 211 | } |
| 212 | |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 213 | static unsigned int snd_info_entry_poll(struct file *file, poll_table *wait) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 215 | struct snd_info_private_data *data = file->private_data; |
| 216 | struct snd_info_entry *entry = data->entry; |
| 217 | unsigned int mask = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 219 | if (entry->c.ops->poll) |
| 220 | return entry->c.ops->poll(entry, |
| 221 | data->file_private_data, |
| 222 | file, wait); |
| 223 | if (entry->c.ops->read) |
| 224 | mask |= POLLIN | POLLRDNORM; |
| 225 | if (entry->c.ops->write) |
| 226 | mask |= POLLOUT | POLLWRNORM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | return mask; |
| 228 | } |
| 229 | |
Ingo Molnar | d99e988 | 2006-01-09 16:44:46 +0100 | [diff] [blame] | 230 | static long snd_info_entry_ioctl(struct file *file, unsigned int cmd, |
| 231 | unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 233 | struct snd_info_private_data *data = file->private_data; |
| 234 | struct snd_info_entry *entry = data->entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 236 | if (!entry->c.ops->ioctl) |
| 237 | return -ENOTTY; |
| 238 | return entry->c.ops->ioctl(entry, data->file_private_data, |
| 239 | file, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | static int snd_info_entry_mmap(struct file *file, struct vm_area_struct *vma) |
| 243 | { |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 244 | struct inode *inode = file_inode(file); |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 245 | struct snd_info_private_data *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | struct snd_info_entry *entry; |
| 247 | |
| 248 | data = file->private_data; |
| 249 | if (data == NULL) |
| 250 | return 0; |
| 251 | entry = data->entry; |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 252 | if (!entry->c.ops->mmap) |
| 253 | return -ENXIO; |
| 254 | return entry->c.ops->mmap(entry, data->file_private_data, |
| 255 | inode, file, vma); |
| 256 | } |
| 257 | |
| 258 | static int snd_info_entry_open(struct inode *inode, struct file *file) |
| 259 | { |
| 260 | struct snd_info_entry *entry = PDE_DATA(inode); |
| 261 | struct snd_info_private_data *data; |
| 262 | int mode, err; |
| 263 | |
| 264 | mutex_lock(&info_mutex); |
| 265 | err = alloc_info_private(entry, &data); |
| 266 | if (err < 0) |
| 267 | goto unlock; |
| 268 | |
| 269 | mode = file->f_flags & O_ACCMODE; |
| 270 | if (((mode == O_RDONLY || mode == O_RDWR) && !entry->c.ops->read) || |
| 271 | ((mode == O_WRONLY || mode == O_RDWR) && !entry->c.ops->write)) { |
| 272 | err = -ENODEV; |
| 273 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 275 | |
| 276 | if (entry->c.ops->open) { |
| 277 | err = entry->c.ops->open(entry, mode, &data->file_private_data); |
| 278 | if (err < 0) |
| 279 | goto error; |
| 280 | } |
| 281 | |
| 282 | file->private_data = data; |
| 283 | mutex_unlock(&info_mutex); |
| 284 | return 0; |
| 285 | |
| 286 | error: |
| 287 | kfree(data); |
| 288 | module_put(entry->module); |
| 289 | unlock: |
| 290 | mutex_unlock(&info_mutex); |
| 291 | return err; |
| 292 | } |
| 293 | |
| 294 | static int snd_info_entry_release(struct inode *inode, struct file *file) |
| 295 | { |
| 296 | struct snd_info_private_data *data = file->private_data; |
| 297 | struct snd_info_entry *entry = data->entry; |
| 298 | |
| 299 | if (entry->c.ops->release) |
| 300 | entry->c.ops->release(entry, file->f_flags & O_ACCMODE, |
| 301 | data->file_private_data); |
| 302 | module_put(entry->module); |
| 303 | kfree(data); |
| 304 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Arjan van de Ven | 9c2e08c | 2007-02-12 00:55:37 -0800 | [diff] [blame] | 307 | static const struct file_operations snd_info_entry_operations = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
Ingo Molnar | d99e988 | 2006-01-09 16:44:46 +0100 | [diff] [blame] | 309 | .owner = THIS_MODULE, |
| 310 | .llseek = snd_info_entry_llseek, |
| 311 | .read = snd_info_entry_read, |
| 312 | .write = snd_info_entry_write, |
| 313 | .poll = snd_info_entry_poll, |
| 314 | .unlocked_ioctl = snd_info_entry_ioctl, |
| 315 | .mmap = snd_info_entry_mmap, |
| 316 | .open = snd_info_entry_open, |
| 317 | .release = snd_info_entry_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | }; |
| 319 | |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 320 | /* |
| 321 | * file ops for text proc files |
| 322 | */ |
| 323 | static ssize_t snd_info_text_entry_write(struct file *file, |
| 324 | const char __user *buffer, |
| 325 | size_t count, loff_t *offset) |
| 326 | { |
| 327 | struct seq_file *m = file->private_data; |
| 328 | struct snd_info_private_data *data = m->private; |
| 329 | struct snd_info_entry *entry = data->entry; |
| 330 | struct snd_info_buffer *buf; |
| 331 | loff_t pos; |
| 332 | size_t next; |
| 333 | int err = 0; |
| 334 | |
| 335 | pos = *offset; |
| 336 | if (!valid_pos(pos, count)) |
| 337 | return -EIO; |
| 338 | next = pos + count; |
| 339 | mutex_lock(&entry->access); |
| 340 | buf = data->wbuffer; |
| 341 | if (!buf) { |
| 342 | data->wbuffer = buf = kzalloc(sizeof(*buf), GFP_KERNEL); |
| 343 | if (!buf) { |
| 344 | err = -ENOMEM; |
| 345 | goto error; |
| 346 | } |
| 347 | } |
| 348 | if (next > buf->len) { |
| 349 | char *nbuf = krealloc(buf->buffer, PAGE_ALIGN(next), |
| 350 | GFP_KERNEL | __GFP_ZERO); |
| 351 | if (!nbuf) { |
| 352 | err = -ENOMEM; |
| 353 | goto error; |
| 354 | } |
| 355 | buf->buffer = nbuf; |
| 356 | buf->len = PAGE_ALIGN(next); |
| 357 | } |
| 358 | if (copy_from_user(buf->buffer + pos, buffer, count)) { |
| 359 | err = -EFAULT; |
| 360 | goto error; |
| 361 | } |
| 362 | buf->size = next; |
| 363 | error: |
| 364 | mutex_unlock(&entry->access); |
| 365 | if (err < 0) |
| 366 | return err; |
| 367 | *offset = next; |
| 368 | return count; |
| 369 | } |
| 370 | |
| 371 | static int snd_info_seq_show(struct seq_file *seq, void *p) |
| 372 | { |
| 373 | struct snd_info_private_data *data = seq->private; |
| 374 | struct snd_info_entry *entry = data->entry; |
| 375 | |
| 376 | if (entry->c.text.read) { |
| 377 | data->rbuffer->buffer = (char *)seq; /* XXX hack! */ |
| 378 | entry->c.text.read(entry, data->rbuffer); |
| 379 | } |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | static int snd_info_text_entry_open(struct inode *inode, struct file *file) |
| 384 | { |
| 385 | struct snd_info_entry *entry = PDE_DATA(inode); |
| 386 | struct snd_info_private_data *data; |
| 387 | int err; |
| 388 | |
| 389 | mutex_lock(&info_mutex); |
| 390 | err = alloc_info_private(entry, &data); |
| 391 | if (err < 0) |
| 392 | goto unlock; |
| 393 | |
| 394 | data->rbuffer = kzalloc(sizeof(*data->rbuffer), GFP_KERNEL); |
| 395 | if (!data->rbuffer) { |
| 396 | err = -ENOMEM; |
| 397 | goto error; |
| 398 | } |
| 399 | if (entry->size) |
| 400 | err = single_open_size(file, snd_info_seq_show, data, |
| 401 | entry->size); |
| 402 | else |
| 403 | err = single_open(file, snd_info_seq_show, data); |
| 404 | if (err < 0) |
| 405 | goto error; |
| 406 | mutex_unlock(&info_mutex); |
| 407 | return 0; |
| 408 | |
| 409 | error: |
| 410 | kfree(data->rbuffer); |
| 411 | kfree(data); |
| 412 | module_put(entry->module); |
| 413 | unlock: |
| 414 | mutex_unlock(&info_mutex); |
| 415 | return err; |
| 416 | } |
| 417 | |
| 418 | static int snd_info_text_entry_release(struct inode *inode, struct file *file) |
| 419 | { |
| 420 | struct seq_file *m = file->private_data; |
| 421 | struct snd_info_private_data *data = m->private; |
| 422 | struct snd_info_entry *entry = data->entry; |
| 423 | |
| 424 | if (data->wbuffer && entry->c.text.write) |
| 425 | entry->c.text.write(entry, data->wbuffer); |
| 426 | |
| 427 | single_release(inode, file); |
| 428 | kfree(data->rbuffer); |
| 429 | if (data->wbuffer) { |
| 430 | kfree(data->wbuffer->buffer); |
| 431 | kfree(data->wbuffer); |
| 432 | } |
| 433 | |
| 434 | module_put(entry->module); |
| 435 | kfree(data); |
| 436 | return 0; |
| 437 | } |
| 438 | |
| 439 | static const struct file_operations snd_info_text_entry_ops = |
| 440 | { |
| 441 | .owner = THIS_MODULE, |
| 442 | .open = snd_info_text_entry_open, |
| 443 | .release = snd_info_text_entry_release, |
| 444 | .write = snd_info_text_entry_write, |
| 445 | .llseek = seq_lseek, |
| 446 | .read = seq_read, |
| 447 | }; |
| 448 | |
Takashi Iwai | 886364f | 2015-04-22 17:54:25 +0200 | [diff] [blame^] | 449 | static struct snd_info_entry *create_subdir(struct module *mod, |
| 450 | const char *name) |
| 451 | { |
| 452 | struct snd_info_entry *entry; |
| 453 | |
| 454 | entry = snd_info_create_module_entry(mod, name, NULL); |
| 455 | if (!entry) |
| 456 | return NULL; |
| 457 | entry->mode = S_IFDIR | S_IRUGO | S_IXUGO; |
| 458 | if (snd_info_register(entry) < 0) { |
| 459 | snd_info_free_entry(entry); |
| 460 | return NULL; |
| 461 | } |
| 462 | return entry; |
| 463 | } |
| 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | int __init snd_info_init(void) |
| 466 | { |
| 467 | struct proc_dir_entry *p; |
| 468 | |
Al Viro | e55d92b | 2011-07-24 02:07:46 -0400 | [diff] [blame] | 469 | p = proc_mkdir("asound", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | if (p == NULL) |
| 471 | return -ENOMEM; |
| 472 | snd_proc_root = p; |
| 473 | #ifdef CONFIG_SND_OSSEMUL |
Takashi Iwai | 886364f | 2015-04-22 17:54:25 +0200 | [diff] [blame^] | 474 | snd_oss_root = create_subdir(THIS_MODULE, "oss"); |
| 475 | if (!snd_oss_root) |
| 476 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | #endif |
Takashi Iwai | 8eeaa2f | 2014-02-10 09:48:47 +0100 | [diff] [blame] | 478 | #if IS_ENABLED(CONFIG_SND_SEQUENCER) |
Takashi Iwai | 886364f | 2015-04-22 17:54:25 +0200 | [diff] [blame^] | 479 | snd_seq_root = create_subdir(THIS_MODULE, "seq"); |
| 480 | if (!snd_seq_root) |
| 481 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | #endif |
| 483 | snd_info_version_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | snd_minor_info_init(); |
| 485 | snd_minor_info_oss_init(); |
| 486 | snd_card_info_init(); |
| 487 | return 0; |
Takashi Iwai | 886364f | 2015-04-22 17:54:25 +0200 | [diff] [blame^] | 488 | |
| 489 | error: |
| 490 | #ifdef CONFIG_SND_OSSEMUL |
| 491 | snd_info_free_entry(snd_oss_root); |
| 492 | #endif |
| 493 | proc_remove(snd_proc_root); |
| 494 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | int __exit snd_info_done(void) |
| 498 | { |
| 499 | snd_card_info_done(); |
| 500 | snd_minor_info_oss_done(); |
| 501 | snd_minor_info_done(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | snd_info_version_done(); |
| 503 | if (snd_proc_root) { |
Takashi Iwai | 8eeaa2f | 2014-02-10 09:48:47 +0100 | [diff] [blame] | 504 | #if IS_ENABLED(CONFIG_SND_SEQUENCER) |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 505 | snd_info_free_entry(snd_seq_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | #endif |
| 507 | #ifdef CONFIG_SND_OSSEMUL |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 508 | snd_info_free_entry(snd_oss_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | #endif |
David Howells | a8ca16e | 2013-04-12 17:27:28 +0100 | [diff] [blame] | 510 | proc_remove(snd_proc_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | } |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | /* |
| 516 | |
| 517 | */ |
| 518 | |
| 519 | |
| 520 | /* |
| 521 | * create a card proc file |
| 522 | * called from init.c |
| 523 | */ |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 524 | int snd_info_card_create(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | { |
| 526 | char str[8]; |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 527 | struct snd_info_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 529 | if (snd_BUG_ON(!card)) |
| 530 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
| 532 | sprintf(str, "card%i", card->number); |
Takashi Iwai | 886364f | 2015-04-22 17:54:25 +0200 | [diff] [blame^] | 533 | entry = create_subdir(card->module, str); |
| 534 | if (!entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | card->proc_root = entry; |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | /* |
| 541 | * register the card proc file |
| 542 | * called from init.c |
| 543 | */ |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 544 | int snd_info_card_register(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | { |
| 546 | struct proc_dir_entry *p; |
| 547 | |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 548 | if (snd_BUG_ON(!card)) |
| 549 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
| 551 | if (!strcmp(card->id, card->proc_root->name)) |
| 552 | return 0; |
| 553 | |
| 554 | p = proc_symlink(card->id, snd_proc_root, card->proc_root->name); |
| 555 | if (p == NULL) |
| 556 | return -ENOMEM; |
| 557 | card->proc_root_link = p; |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | /* |
Jaroslav Kysela | c2eb9c4 | 2008-11-12 16:31:37 +0100 | [diff] [blame] | 562 | * called on card->id change |
| 563 | */ |
| 564 | void snd_info_card_id_change(struct snd_card *card) |
| 565 | { |
| 566 | mutex_lock(&info_mutex); |
| 567 | if (card->proc_root_link) { |
David Howells | a8ca16e | 2013-04-12 17:27:28 +0100 | [diff] [blame] | 568 | proc_remove(card->proc_root_link); |
Jaroslav Kysela | c2eb9c4 | 2008-11-12 16:31:37 +0100 | [diff] [blame] | 569 | card->proc_root_link = NULL; |
| 570 | } |
| 571 | if (strcmp(card->id, card->proc_root->name)) |
| 572 | card->proc_root_link = proc_symlink(card->id, |
| 573 | snd_proc_root, |
| 574 | card->proc_root->name); |
| 575 | mutex_unlock(&info_mutex); |
| 576 | } |
| 577 | |
| 578 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | * de-register the card proc file |
| 580 | * called from init.c |
| 581 | */ |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 582 | void snd_info_card_disconnect(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | { |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 584 | if (!card) |
| 585 | return; |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 586 | mutex_lock(&info_mutex); |
David Howells | a8ca16e | 2013-04-12 17:27:28 +0100 | [diff] [blame] | 587 | proc_remove(card->proc_root_link); |
| 588 | card->proc_root_link = NULL; |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 589 | if (card->proc_root) |
| 590 | snd_info_disconnect(card->proc_root); |
| 591 | mutex_unlock(&info_mutex); |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | * release the card proc file resources |
| 596 | * called from init.c |
| 597 | */ |
| 598 | int snd_info_card_free(struct snd_card *card) |
| 599 | { |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 600 | if (!card) |
| 601 | return 0; |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 602 | snd_info_free_entry(card->proc_root); |
| 603 | card->proc_root = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | return 0; |
| 605 | } |
| 606 | |
| 607 | |
| 608 | /** |
| 609 | * snd_info_get_line - read one line from the procfs buffer |
| 610 | * @buffer: the procfs buffer |
| 611 | * @line: the buffer to store |
Clemens Ladisch | ddc64b2 | 2014-08-21 20:55:21 +0200 | [diff] [blame] | 612 | * @len: the max. buffer size |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | * |
| 614 | * Reads one line from the buffer and stores the string. |
| 615 | * |
Yacine Belkadi | eb7c06e | 2013-03-11 22:05:14 +0100 | [diff] [blame] | 616 | * Return: Zero if successful, or 1 if error or EOF. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | */ |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 618 | int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | { |
| 620 | int c = -1; |
| 621 | |
Takashi Iwai | 0bc0ec9 | 2013-03-13 12:11:13 +0100 | [diff] [blame] | 622 | if (snd_BUG_ON(!buffer || !buffer->buffer)) |
| 623 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | if (len <= 0 || buffer->stop || buffer->error) |
| 625 | return 1; |
Takashi Iwai | 0bc0ec9 | 2013-03-13 12:11:13 +0100 | [diff] [blame] | 626 | while (!buffer->stop) { |
Takashi Iwai | 7e4eeec | 2006-04-28 15:13:40 +0200 | [diff] [blame] | 627 | c = buffer->buffer[buffer->curr++]; |
| 628 | if (buffer->curr >= buffer->size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | buffer->stop = 1; |
Takashi Iwai | 0bc0ec9 | 2013-03-13 12:11:13 +0100 | [diff] [blame] | 630 | if (c == '\n') |
| 631 | break; |
Clemens Ladisch | ddc64b2 | 2014-08-21 20:55:21 +0200 | [diff] [blame] | 632 | if (len > 1) { |
Takashi Iwai | 0bc0ec9 | 2013-03-13 12:11:13 +0100 | [diff] [blame] | 633 | len--; |
| 634 | *line++ = c; |
| 635 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
| 637 | *line = '\0'; |
| 638 | return 0; |
| 639 | } |
| 640 | |
Takashi Iwai | c0d3fb3 | 2006-04-28 15:13:39 +0200 | [diff] [blame] | 641 | EXPORT_SYMBOL(snd_info_get_line); |
| 642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | /** |
Henrik Kretzschmar | 856def8 | 2005-07-08 13:53:42 +0200 | [diff] [blame] | 644 | * snd_info_get_str - parse a string token |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | * @dest: the buffer to store the string token |
| 646 | * @src: the original string |
| 647 | * @len: the max. length of token - 1 |
| 648 | * |
| 649 | * Parses the original string and copy a token to the given |
| 650 | * string buffer. |
| 651 | * |
Yacine Belkadi | eb7c06e | 2013-03-11 22:05:14 +0100 | [diff] [blame] | 652 | * Return: The updated pointer of the original string so that |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | * it can be used for the next call. |
| 654 | */ |
Takashi Iwai | 4f7454a | 2009-09-08 14:29:58 +0200 | [diff] [blame] | 655 | const char *snd_info_get_str(char *dest, const char *src, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | { |
| 657 | int c; |
| 658 | |
| 659 | while (*src == ' ' || *src == '\t') |
| 660 | src++; |
| 661 | if (*src == '"' || *src == '\'') { |
| 662 | c = *src++; |
| 663 | while (--len > 0 && *src && *src != c) { |
| 664 | *dest++ = *src++; |
| 665 | } |
| 666 | if (*src == c) |
| 667 | src++; |
| 668 | } else { |
| 669 | while (--len > 0 && *src && *src != ' ' && *src != '\t') { |
| 670 | *dest++ = *src++; |
| 671 | } |
| 672 | } |
| 673 | *dest = 0; |
| 674 | while (*src == ' ' || *src == '\t') |
| 675 | src++; |
| 676 | return src; |
| 677 | } |
| 678 | |
Takashi Iwai | c0d3fb3 | 2006-04-28 15:13:39 +0200 | [diff] [blame] | 679 | EXPORT_SYMBOL(snd_info_get_str); |
| 680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | /** |
| 682 | * snd_info_create_entry - create an info entry |
| 683 | * @name: the proc file name |
| 684 | * |
| 685 | * Creates an info entry with the given file name and initializes as |
| 686 | * the default state. |
| 687 | * |
| 688 | * Usually called from other functions such as |
| 689 | * snd_info_create_card_entry(). |
| 690 | * |
Yacine Belkadi | eb7c06e | 2013-03-11 22:05:14 +0100 | [diff] [blame] | 691 | * Return: The pointer of the new instance, or %NULL on failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | */ |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 693 | static struct snd_info_entry *snd_info_create_entry(const char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | { |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 695 | struct snd_info_entry *entry; |
Takashi Iwai | ca2c096 | 2005-09-09 14:20:23 +0200 | [diff] [blame] | 696 | entry = kzalloc(sizeof(*entry), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | if (entry == NULL) |
| 698 | return NULL; |
Paulo Marques | 543537b | 2005-06-23 00:09:02 -0700 | [diff] [blame] | 699 | entry->name = kstrdup(name, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | if (entry->name == NULL) { |
| 701 | kfree(entry); |
| 702 | return NULL; |
| 703 | } |
| 704 | entry->mode = S_IFREG | S_IRUGO; |
| 705 | entry->content = SNDRV_INFO_CONTENT_TEXT; |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 706 | mutex_init(&entry->access); |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 707 | INIT_LIST_HEAD(&entry->children); |
| 708 | INIT_LIST_HEAD(&entry->list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | return entry; |
| 710 | } |
| 711 | |
| 712 | /** |
| 713 | * snd_info_create_module_entry - create an info entry for the given module |
| 714 | * @module: the module pointer |
| 715 | * @name: the file name |
| 716 | * @parent: the parent directory |
| 717 | * |
| 718 | * Creates a new info entry and assigns it to the given module. |
| 719 | * |
Yacine Belkadi | eb7c06e | 2013-03-11 22:05:14 +0100 | [diff] [blame] | 720 | * Return: The pointer of the new instance, or %NULL on failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | */ |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 722 | struct snd_info_entry *snd_info_create_module_entry(struct module * module, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | const char *name, |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 724 | struct snd_info_entry *parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | { |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 726 | struct snd_info_entry *entry = snd_info_create_entry(name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | if (entry) { |
| 728 | entry->module = module; |
| 729 | entry->parent = parent; |
| 730 | } |
| 731 | return entry; |
| 732 | } |
| 733 | |
Takashi Iwai | c0d3fb3 | 2006-04-28 15:13:39 +0200 | [diff] [blame] | 734 | EXPORT_SYMBOL(snd_info_create_module_entry); |
| 735 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | /** |
| 737 | * snd_info_create_card_entry - create an info entry for the given card |
| 738 | * @card: the card instance |
| 739 | * @name: the file name |
| 740 | * @parent: the parent directory |
| 741 | * |
| 742 | * Creates a new info entry and assigns it to the given card. |
| 743 | * |
Yacine Belkadi | eb7c06e | 2013-03-11 22:05:14 +0100 | [diff] [blame] | 744 | * Return: The pointer of the new instance, or %NULL on failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | */ |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 746 | struct snd_info_entry *snd_info_create_card_entry(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | const char *name, |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 748 | struct snd_info_entry * parent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | { |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 750 | struct snd_info_entry *entry = snd_info_create_entry(name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | if (entry) { |
| 752 | entry->module = card->module; |
| 753 | entry->card = card; |
| 754 | entry->parent = parent; |
| 755 | } |
| 756 | return entry; |
| 757 | } |
| 758 | |
Takashi Iwai | c0d3fb3 | 2006-04-28 15:13:39 +0200 | [diff] [blame] | 759 | EXPORT_SYMBOL(snd_info_create_card_entry); |
| 760 | |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 761 | static void snd_info_disconnect(struct snd_info_entry *entry) |
| 762 | { |
| 763 | struct list_head *p, *n; |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 764 | |
| 765 | list_for_each_safe(p, n, &entry->children) { |
| 766 | snd_info_disconnect(list_entry(p, struct snd_info_entry, list)); |
| 767 | } |
| 768 | |
| 769 | if (! entry->p) |
| 770 | return; |
| 771 | list_del_init(&entry->list); |
David Howells | a8ca16e | 2013-04-12 17:27:28 +0100 | [diff] [blame] | 772 | proc_remove(entry->p); |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 773 | entry->p = NULL; |
| 774 | } |
| 775 | |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 776 | static int snd_info_dev_free_entry(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | { |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 778 | struct snd_info_entry *entry = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | snd_info_free_entry(entry); |
| 780 | return 0; |
| 781 | } |
| 782 | |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 783 | static int snd_info_dev_register_entry(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | { |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 785 | struct snd_info_entry *entry = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | return snd_info_register(entry); |
| 787 | } |
| 788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | /** |
| 790 | * snd_card_proc_new - create an info entry for the given card |
| 791 | * @card: the card instance |
| 792 | * @name: the file name |
| 793 | * @entryp: the pointer to store the new info entry |
| 794 | * |
| 795 | * Creates a new info entry and assigns it to the given card. |
| 796 | * Unlike snd_info_create_card_entry(), this function registers the |
| 797 | * info entry as an ALSA device component, so that it can be |
| 798 | * unregistered/released without explicit call. |
| 799 | * Also, you don't have to register this entry via snd_info_register(), |
| 800 | * since this will be registered by snd_card_register() automatically. |
| 801 | * |
| 802 | * The parent is assumed as card->proc_root. |
| 803 | * |
| 804 | * For releasing this entry, use snd_device_free() instead of |
| 805 | * snd_info_free_entry(). |
| 806 | * |
Yacine Belkadi | eb7c06e | 2013-03-11 22:05:14 +0100 | [diff] [blame] | 807 | * Return: Zero if successful, or a negative error code on failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | */ |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 809 | int snd_card_proc_new(struct snd_card *card, const char *name, |
| 810 | struct snd_info_entry **entryp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | { |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 812 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | .dev_free = snd_info_dev_free_entry, |
| 814 | .dev_register = snd_info_dev_register_entry, |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 815 | /* disconnect is done via snd_info_card_disconnect() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | }; |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 817 | struct snd_info_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | int err; |
| 819 | |
| 820 | entry = snd_info_create_card_entry(card, name, card->proc_root); |
| 821 | if (! entry) |
| 822 | return -ENOMEM; |
| 823 | if ((err = snd_device_new(card, SNDRV_DEV_INFO, entry, &ops)) < 0) { |
| 824 | snd_info_free_entry(entry); |
| 825 | return err; |
| 826 | } |
| 827 | if (entryp) |
| 828 | *entryp = entry; |
| 829 | return 0; |
| 830 | } |
| 831 | |
Takashi Iwai | c0d3fb3 | 2006-04-28 15:13:39 +0200 | [diff] [blame] | 832 | EXPORT_SYMBOL(snd_card_proc_new); |
| 833 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | /** |
| 835 | * snd_info_free_entry - release the info entry |
| 836 | * @entry: the info entry |
| 837 | * |
| 838 | * Releases the info entry. Don't call this after registered. |
| 839 | */ |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 840 | void snd_info_free_entry(struct snd_info_entry * entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | { |
| 842 | if (entry == NULL) |
| 843 | return; |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 844 | if (entry->p) { |
| 845 | mutex_lock(&info_mutex); |
| 846 | snd_info_disconnect(entry); |
| 847 | mutex_unlock(&info_mutex); |
| 848 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | kfree(entry->name); |
| 850 | if (entry->private_free) |
| 851 | entry->private_free(entry); |
| 852 | kfree(entry); |
| 853 | } |
| 854 | |
Takashi Iwai | c0d3fb3 | 2006-04-28 15:13:39 +0200 | [diff] [blame] | 855 | EXPORT_SYMBOL(snd_info_free_entry); |
| 856 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | /** |
| 858 | * snd_info_register - register the info entry |
| 859 | * @entry: the info entry |
| 860 | * |
| 861 | * Registers the proc info entry. |
| 862 | * |
Yacine Belkadi | eb7c06e | 2013-03-11 22:05:14 +0100 | [diff] [blame] | 863 | * Return: Zero if successful, or a negative error code on failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | */ |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 865 | int snd_info_register(struct snd_info_entry * entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | { |
| 867 | struct proc_dir_entry *root, *p = NULL; |
| 868 | |
Takashi Iwai | 7eaa943 | 2008-08-08 17:09:09 +0200 | [diff] [blame] | 869 | if (snd_BUG_ON(!entry)) |
| 870 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | root = entry->parent == NULL ? snd_proc_root : entry->parent->p; |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 872 | mutex_lock(&info_mutex); |
Al Viro | aee0c61 | 2013-03-28 23:01:34 -0400 | [diff] [blame] | 873 | if (S_ISDIR(entry->mode)) { |
| 874 | p = proc_mkdir_mode(entry->name, entry->mode, root); |
| 875 | if (!p) { |
| 876 | mutex_unlock(&info_mutex); |
| 877 | return -ENOMEM; |
| 878 | } |
| 879 | } else { |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 880 | const struct file_operations *ops; |
| 881 | if (entry->content == SNDRV_INFO_CONTENT_DATA) |
| 882 | ops = &snd_info_entry_operations; |
| 883 | else |
| 884 | ops = &snd_info_text_entry_ops; |
Al Viro | aee0c61 | 2013-03-28 23:01:34 -0400 | [diff] [blame] | 885 | p = proc_create_data(entry->name, entry->mode, root, |
Takashi Iwai | 4adb7bc | 2015-04-22 16:10:22 +0200 | [diff] [blame] | 886 | ops, entry); |
Al Viro | aee0c61 | 2013-03-28 23:01:34 -0400 | [diff] [blame] | 887 | if (!p) { |
| 888 | mutex_unlock(&info_mutex); |
| 889 | return -ENOMEM; |
| 890 | } |
David Howells | 271a15e | 2013-04-12 00:38:51 +0100 | [diff] [blame] | 891 | proc_set_size(p, entry->size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | entry->p = p; |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 894 | if (entry->parent) |
| 895 | list_add_tail(&entry->list, &entry->parent->children); |
Ingo Molnar | 1a60d4c | 2006-01-16 16:29:08 +0100 | [diff] [blame] | 896 | mutex_unlock(&info_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | return 0; |
| 898 | } |
| 899 | |
Takashi Iwai | c0d3fb3 | 2006-04-28 15:13:39 +0200 | [diff] [blame] | 900 | EXPORT_SYMBOL(snd_info_register); |
| 901 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | /* |
| 903 | |
| 904 | */ |
| 905 | |
Takashi Iwai | 6581f4e | 2006-05-17 17:14:51 +0200 | [diff] [blame] | 906 | static struct snd_info_entry *snd_info_version_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 908 | static void snd_info_version_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | { |
| 910 | snd_iprintf(buffer, |
Jaroslav Kysela | 4266274 | 2012-09-04 11:21:45 +0200 | [diff] [blame] | 911 | "Advanced Linux Sound Architecture Driver Version k%s.\n", |
| 912 | init_utsname()->release); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | static int __init snd_info_version_init(void) |
| 916 | { |
Takashi Iwai | 24c1f93 | 2005-11-17 13:58:48 +0100 | [diff] [blame] | 917 | struct snd_info_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
| 919 | entry = snd_info_create_module_entry(THIS_MODULE, "version", NULL); |
| 920 | if (entry == NULL) |
| 921 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | entry->c.text.read = snd_info_version_read; |
| 923 | if (snd_info_register(entry) < 0) { |
| 924 | snd_info_free_entry(entry); |
| 925 | return -ENOMEM; |
| 926 | } |
| 927 | snd_info_version_entry = entry; |
| 928 | return 0; |
| 929 | } |
| 930 | |
| 931 | static int __exit snd_info_version_done(void) |
| 932 | { |
Takashi Iwai | 746d4a0 | 2006-06-23 14:37:59 +0200 | [diff] [blame] | 933 | snd_info_free_entry(snd_info_version_entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | #endif /* CONFIG_PROC_FS */ |