| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * dsp_pipeline.c: pipelined audio processing |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2007, Nadi Sarrar |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Nadi Sarrar <nadi@beronet.com> |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 9 | | - * under the terms of the GNU General Public License as published by the Free |
|---|
| 10 | | - * Software Foundation; either version 2 of the License, or (at your option) |
|---|
| 11 | | - * any later version. |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 14 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 15 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 16 | | - * more details. |
|---|
| 17 | | - * |
|---|
| 18 | | - * You should have received a copy of the GNU General Public License along with |
|---|
| 19 | | - * this program; if not, write to the Free Software Foundation, Inc., 59 |
|---|
| 20 | | - * Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 21 | | - * |
|---|
| 22 | | - * The full GNU General Public License is included in this distribution in the |
|---|
| 23 | | - * file called LICENSE. |
|---|
| 24 | | - * |
|---|
| 25 | 8 | */ |
|---|
| 26 | 9 | |
|---|
| 27 | 10 | #include <linux/kernel.h> |
|---|
| .. | .. |
|---|
| 33 | 16 | #include <linux/export.h> |
|---|
| 34 | 17 | #include "dsp.h" |
|---|
| 35 | 18 | #include "dsp_hwec.h" |
|---|
| 36 | | - |
|---|
| 37 | | -/* uncomment for debugging */ |
|---|
| 38 | | -/*#define PIPELINE_DEBUG*/ |
|---|
| 39 | 19 | |
|---|
| 40 | 20 | struct dsp_pipeline_entry { |
|---|
| 41 | 21 | struct mISDN_dsp_element *elem; |
|---|
| .. | .. |
|---|
| 97 | 77 | if (!entry) |
|---|
| 98 | 78 | return -ENOMEM; |
|---|
| 99 | 79 | |
|---|
| 80 | + INIT_LIST_HEAD(&entry->list); |
|---|
| 100 | 81 | entry->elem = elem; |
|---|
| 101 | 82 | |
|---|
| 102 | 83 | entry->dev.class = elements_class; |
|---|
| .. | .. |
|---|
| 121 | 102 | } |
|---|
| 122 | 103 | } |
|---|
| 123 | 104 | |
|---|
| 124 | | -#ifdef PIPELINE_DEBUG |
|---|
| 125 | | - printk(KERN_DEBUG "%s: %s registered\n", __func__, elem->name); |
|---|
| 126 | | -#endif |
|---|
| 127 | | - |
|---|
| 128 | 105 | return 0; |
|---|
| 129 | 106 | |
|---|
| 130 | 107 | err2: |
|---|
| 131 | 108 | device_unregister(&entry->dev); |
|---|
| 132 | 109 | return ret; |
|---|
| 133 | 110 | err1: |
|---|
| 134 | | - kfree(entry); |
|---|
| 111 | + put_device(&entry->dev); |
|---|
| 135 | 112 | return ret; |
|---|
| 136 | 113 | } |
|---|
| 137 | 114 | EXPORT_SYMBOL(mISDN_dsp_element_register); |
|---|
| .. | .. |
|---|
| 146 | 123 | list_for_each_entry_safe(entry, n, &dsp_elements, list) |
|---|
| 147 | 124 | if (entry->elem == elem) { |
|---|
| 148 | 125 | device_unregister(&entry->dev); |
|---|
| 149 | | -#ifdef PIPELINE_DEBUG |
|---|
| 150 | | - printk(KERN_DEBUG "%s: %s unregistered\n", |
|---|
| 151 | | - __func__, elem->name); |
|---|
| 152 | | -#endif |
|---|
| 153 | 126 | return; |
|---|
| 154 | 127 | } |
|---|
| 155 | 128 | printk(KERN_ERR "%s: element %s not in list.\n", __func__, elem->name); |
|---|
| .. | .. |
|---|
| 161 | 134 | elements_class = class_create(THIS_MODULE, "dsp_pipeline"); |
|---|
| 162 | 135 | if (IS_ERR(elements_class)) |
|---|
| 163 | 136 | return PTR_ERR(elements_class); |
|---|
| 164 | | - |
|---|
| 165 | | -#ifdef PIPELINE_DEBUG |
|---|
| 166 | | - printk(KERN_DEBUG "%s: dsp pipeline module initialized\n", __func__); |
|---|
| 167 | | -#endif |
|---|
| 168 | 137 | |
|---|
| 169 | 138 | dsp_hwec_init(); |
|---|
| 170 | 139 | |
|---|
| .. | .. |
|---|
| 185 | 154 | __func__, entry->elem->name); |
|---|
| 186 | 155 | kfree(entry); |
|---|
| 187 | 156 | } |
|---|
| 188 | | - |
|---|
| 189 | | -#ifdef PIPELINE_DEBUG |
|---|
| 190 | | - printk(KERN_DEBUG "%s: dsp pipeline module exited\n", __func__); |
|---|
| 191 | | -#endif |
|---|
| 192 | 157 | } |
|---|
| 193 | 158 | |
|---|
| 194 | 159 | int dsp_pipeline_init(struct dsp_pipeline *pipeline) |
|---|
| .. | .. |
|---|
| 197 | 162 | return -EINVAL; |
|---|
| 198 | 163 | |
|---|
| 199 | 164 | INIT_LIST_HEAD(&pipeline->list); |
|---|
| 200 | | - |
|---|
| 201 | | -#ifdef PIPELINE_DEBUG |
|---|
| 202 | | - printk(KERN_DEBUG "%s: dsp pipeline ready\n", __func__); |
|---|
| 203 | | -#endif |
|---|
| 204 | 165 | |
|---|
| 205 | 166 | return 0; |
|---|
| 206 | 167 | } |
|---|
| .. | .. |
|---|
| 227 | 188 | return; |
|---|
| 228 | 189 | |
|---|
| 229 | 190 | _dsp_pipeline_destroy(pipeline); |
|---|
| 230 | | - |
|---|
| 231 | | -#ifdef PIPELINE_DEBUG |
|---|
| 232 | | - printk(KERN_DEBUG "%s: dsp pipeline destroyed\n", __func__); |
|---|
| 233 | | -#endif |
|---|
| 234 | 191 | } |
|---|
| 235 | 192 | |
|---|
| 236 | 193 | int dsp_pipeline_build(struct dsp_pipeline *pipeline, const char *cfg) |
|---|
| 237 | 194 | { |
|---|
| 238 | | - int incomplete = 0, found = 0; |
|---|
| 239 | | - char *dup, *tok, *name, *args; |
|---|
| 195 | + int found = 0; |
|---|
| 196 | + char *dup, *next, *tok, *name, *args; |
|---|
| 240 | 197 | struct dsp_element_entry *entry, *n; |
|---|
| 241 | 198 | struct dsp_pipeline_entry *pipeline_entry; |
|---|
| 242 | 199 | struct mISDN_dsp_element *elem; |
|---|
| .. | .. |
|---|
| 247 | 204 | if (!list_empty(&pipeline->list)) |
|---|
| 248 | 205 | _dsp_pipeline_destroy(pipeline); |
|---|
| 249 | 206 | |
|---|
| 250 | | - dup = kstrdup(cfg, GFP_ATOMIC); |
|---|
| 207 | + dup = next = kstrdup(cfg, GFP_ATOMIC); |
|---|
| 251 | 208 | if (!dup) |
|---|
| 252 | 209 | return 0; |
|---|
| 253 | | - while ((tok = strsep(&dup, "|"))) { |
|---|
| 210 | + while ((tok = strsep(&next, "|"))) { |
|---|
| 254 | 211 | if (!strlen(tok)) |
|---|
| 255 | 212 | continue; |
|---|
| 256 | 213 | name = strsep(&tok, "("); |
|---|
| .. | .. |
|---|
| 268 | 225 | printk(KERN_ERR "%s: failed to add " |
|---|
| 269 | 226 | "entry to pipeline: %s (out of " |
|---|
| 270 | 227 | "memory)\n", __func__, elem->name); |
|---|
| 271 | | - incomplete = 1; |
|---|
| 272 | 228 | goto _out; |
|---|
| 273 | 229 | } |
|---|
| 274 | 230 | pipeline_entry->elem = elem; |
|---|
| .. | .. |
|---|
| 285 | 241 | if (pipeline_entry->p) { |
|---|
| 286 | 242 | list_add_tail(&pipeline_entry-> |
|---|
| 287 | 243 | list, &pipeline->list); |
|---|
| 288 | | -#ifdef PIPELINE_DEBUG |
|---|
| 289 | | - printk(KERN_DEBUG "%s: created " |
|---|
| 290 | | - "instance of %s%s%s\n", |
|---|
| 291 | | - __func__, name, args ? |
|---|
| 292 | | - " with args " : "", args ? |
|---|
| 293 | | - args : ""); |
|---|
| 294 | | -#endif |
|---|
| 295 | 244 | } else { |
|---|
| 296 | 245 | printk(KERN_ERR "%s: failed " |
|---|
| 297 | 246 | "to add entry to pipeline: " |
|---|
| 298 | 247 | "%s (new() returned NULL)\n", |
|---|
| 299 | 248 | __func__, elem->name); |
|---|
| 300 | 249 | kfree(pipeline_entry); |
|---|
| 301 | | - incomplete = 1; |
|---|
| 302 | 250 | } |
|---|
| 303 | 251 | } |
|---|
| 304 | 252 | found = 1; |
|---|
| .. | .. |
|---|
| 307 | 255 | |
|---|
| 308 | 256 | if (found) |
|---|
| 309 | 257 | found = 0; |
|---|
| 310 | | - else { |
|---|
| 258 | + else |
|---|
| 311 | 259 | printk(KERN_ERR "%s: element not found, skipping: " |
|---|
| 312 | 260 | "%s\n", __func__, name); |
|---|
| 313 | | - incomplete = 1; |
|---|
| 314 | | - } |
|---|
| 315 | 261 | } |
|---|
| 316 | 262 | |
|---|
| 317 | 263 | _out: |
|---|
| .. | .. |
|---|
| 320 | 266 | else |
|---|
| 321 | 267 | pipeline->inuse = 0; |
|---|
| 322 | 268 | |
|---|
| 323 | | -#ifdef PIPELINE_DEBUG |
|---|
| 324 | | - printk(KERN_DEBUG "%s: dsp pipeline built%s: %s\n", |
|---|
| 325 | | - __func__, incomplete ? " incomplete" : "", cfg); |
|---|
| 326 | | -#endif |
|---|
| 327 | 269 | kfree(dup); |
|---|
| 328 | 270 | return 0; |
|---|
| 329 | 271 | } |
|---|