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