Skip to content

Commit 5c75bc5

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 e8bab41 commit 5c75bc5

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,21 @@ 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+
int ret;
297+
298+
ret = debugfs_file_get(file->f_path.dentry);
299+
if (unlikely(ret))
300+
return ret;
301+
302+
ret = simple_open(inode, file);
303+
if (ret)
304+
debugfs_file_put(file->f_path.dentry);
305+
306+
return ret;
307+
}
308+
294309
static ssize_t sof_dfsentry_trace_read(struct file *file, char __user *buffer,
295310
size_t count, loff_t *ppos)
296311
{
@@ -348,11 +363,12 @@ static int sof_dfsentry_trace_release(struct inode *inode, struct file *file)
348363
if (!priv->dtrace_is_enabled)
349364
priv->host_offset = 0;
350365

366+
debugfs_file_put(file->f_path.dentry);
351367
return 0;
352368
}
353369

354370
static const struct file_operations sof_dtrace_trace_fops = {
355-
.open = simple_open,
371+
.open = sof_dfsentry_trace_open,
356372
.read = sof_dfsentry_trace_read,
357373
.llseek = default_llseek,
358374
.release = sof_dfsentry_trace_release,

0 commit comments

Comments
 (0)