mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
firmware: cs_dsp: Cleanup debugfs for wmfw and bin
Merge series from Richard Fitzgerald <rf@opensource.cirrus.com>: These two patches improve the implementation of the debugfs files for the wmfw and bin file names. First patch removes duplicated code. Second patch replaces the old clunkiness of storing the filename with an appended \n. The \n can be appended when the file is read, to keep the stored string sane.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
* Cirrus Logic International Semiconductor Ltd.
|
||||
*/
|
||||
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/ctype.h>
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/delay.h>
|
||||
@@ -388,18 +389,14 @@ EXPORT_SYMBOL_NS_GPL(cs_dsp_mem_region_name, "FW_CS_DSP");
|
||||
#ifdef CONFIG_DEBUG_FS
|
||||
static void cs_dsp_debugfs_save_wmfwname(struct cs_dsp *dsp, const char *s)
|
||||
{
|
||||
char *tmp = kasprintf(GFP_KERNEL, "%s\n", s);
|
||||
|
||||
kfree(dsp->wmfw_file_name);
|
||||
dsp->wmfw_file_name = tmp;
|
||||
dsp->wmfw_file_name = kstrdup(s, GFP_KERNEL);
|
||||
}
|
||||
|
||||
static void cs_dsp_debugfs_save_binname(struct cs_dsp *dsp, const char *s)
|
||||
{
|
||||
char *tmp = kasprintf(GFP_KERNEL, "%s\n", s);
|
||||
|
||||
kfree(dsp->bin_file_name);
|
||||
dsp->bin_file_name = tmp;
|
||||
dsp->bin_file_name = kstrdup(s, GFP_KERNEL);
|
||||
}
|
||||
|
||||
static void cs_dsp_debugfs_clear(struct cs_dsp *dsp)
|
||||
@@ -410,24 +407,33 @@ static void cs_dsp_debugfs_clear(struct cs_dsp *dsp)
|
||||
dsp->bin_file_name = NULL;
|
||||
}
|
||||
|
||||
static ssize_t cs_dsp_debugfs_string_read(struct cs_dsp *dsp,
|
||||
char __user *user_buf,
|
||||
size_t count, loff_t *ppos,
|
||||
const char **pstr)
|
||||
{
|
||||
const char *str __free(kfree) = NULL;
|
||||
|
||||
scoped_guard(mutex, &dsp->pwr_lock) {
|
||||
if (!*pstr)
|
||||
return 0;
|
||||
|
||||
str = kasprintf(GFP_KERNEL, "%s\n", *pstr);
|
||||
if (!str)
|
||||
return -ENOMEM;
|
||||
|
||||
return simple_read_from_buffer(user_buf, count, ppos, str, strlen(str));
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t cs_dsp_debugfs_wmfw_read(struct file *file,
|
||||
char __user *user_buf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct cs_dsp *dsp = file->private_data;
|
||||
ssize_t ret;
|
||||
|
||||
mutex_lock(&dsp->pwr_lock);
|
||||
|
||||
if (!dsp->wmfw_file_name || !dsp->booted)
|
||||
ret = 0;
|
||||
else
|
||||
ret = simple_read_from_buffer(user_buf, count, ppos,
|
||||
dsp->wmfw_file_name,
|
||||
strlen(dsp->wmfw_file_name));
|
||||
|
||||
mutex_unlock(&dsp->pwr_lock);
|
||||
return ret;
|
||||
return cs_dsp_debugfs_string_read(dsp, user_buf, count, ppos,
|
||||
&dsp->wmfw_file_name);
|
||||
}
|
||||
|
||||
static ssize_t cs_dsp_debugfs_bin_read(struct file *file,
|
||||
@@ -435,19 +441,9 @@ static ssize_t cs_dsp_debugfs_bin_read(struct file *file,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct cs_dsp *dsp = file->private_data;
|
||||
ssize_t ret;
|
||||
|
||||
mutex_lock(&dsp->pwr_lock);
|
||||
|
||||
if (!dsp->bin_file_name || !dsp->booted)
|
||||
ret = 0;
|
||||
else
|
||||
ret = simple_read_from_buffer(user_buf, count, ppos,
|
||||
dsp->bin_file_name,
|
||||
strlen(dsp->bin_file_name));
|
||||
|
||||
mutex_unlock(&dsp->pwr_lock);
|
||||
return ret;
|
||||
return cs_dsp_debugfs_string_read(dsp, user_buf, count, ppos,
|
||||
&dsp->bin_file_name);
|
||||
}
|
||||
|
||||
static const struct {
|
||||
|
||||
@@ -188,8 +188,8 @@ struct cs_dsp {
|
||||
|
||||
#ifdef CONFIG_DEBUG_FS
|
||||
struct dentry *debugfs_root;
|
||||
char *wmfw_file_name;
|
||||
char *bin_file_name;
|
||||
const char *wmfw_file_name;
|
||||
const char *bin_file_name;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user