Skip to content

Commit 6d06b8c

Browse files
committed
ASoC: SOF: sof-client-dma-trace: Add protection against file/module removal
Based on debugging the following issues were identified: if the snd_sof_dma_trace module is removed while the sof-logger keeps the trace file open: The module's remove will block on the debugfs_remove() until the sof-logger is stopped (w/ C-c). The sof_dfsentry_trace_read() will return and the debugfs file is removed, the module remove completes. Then the debugfs file's release callback got called but the file itself was already removed! The second issue is that while the client driver is loaded and sof-logger keeps the trace file open, the user can rmmod the parent driver for the DSP itself which will removes the SOF client devices and the same chain of events will happen. With this patch we protect the debugfs file from removal with the debugfs_file_get/put and we protect the parent device against removal while the module is in active use (the debugfs file is open). Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent 050e5a7 commit 6d06b8c

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

sound/soc/sof/sof-client-dma-trace.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,32 @@ static size_t sof_wait_trace_avail(struct sof_client_dev *cdev,
291291
return sof_trace_avail(cdev, pos, buffer_size);
292292
}
293293

294+
static int sof_dfsentry_trace_open(struct inode *inode, struct file *file)
295+
{
296+
struct sof_client_dev *cdev;
297+
int ret;
298+
299+
ret = debugfs_file_get(file->f_path.dentry);
300+
if (unlikely(ret))
301+
return ret;
302+
303+
cdev = inode->i_private;
304+
305+
ret = sof_client_core_module_get(cdev);
306+
if (ret) {
307+
debugfs_file_put(file->f_path.dentry);
308+
return ret;
309+
}
310+
311+
ret = simple_open(inode, file);
312+
if (ret) {
313+
debugfs_file_put(file->f_path.dentry);
314+
sof_client_core_module_put(cdev);
315+
}
316+
317+
return ret;
318+
}
319+
294320
static ssize_t sof_dfsentry_trace_read(struct file *file, char __user *buffer,
295321
size_t count, loff_t *ppos)
296322
{
@@ -348,11 +374,13 @@ static int sof_dfsentry_trace_release(struct inode *inode, struct file *file)
348374
if (!priv->dtrace_is_enabled)
349375
priv->host_offset = 0;
350376

377+
debugfs_file_put(file->f_path.dentry);
378+
sof_client_core_module_put(cdev);
351379
return 0;
352380
}
353381

354382
static const struct file_operations sof_dtrace_trace_fops = {
355-
.open = simple_open,
383+
.open = sof_dfsentry_trace_open,
356384
.read = sof_dfsentry_trace_read,
357385
.llseek = default_llseek,
358386
.release = sof_dfsentry_trace_release,

0 commit comments

Comments
 (0)