public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] firmware: cs_dsp: Cleanup debugfs for wmfw and bin file name
@ 2025-11-20 13:06 Richard Fitzgerald
  2025-11-20 13:06 ` [PATCH 1/2] firmware: cs_dsp: Factor out common debugfs string read Richard Fitzgerald
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Richard Fitzgerald @ 2025-11-20 13:06 UTC (permalink / raw)
  To: broonie; +Cc: linux-sound, linux-kernel, patches

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.

Richard Fitzgerald (2):
  firmware: cs_dsp: Factor out common debugfs string read
  firmware: cs_dsp: Append \n to debugfs string during read

 drivers/firmware/cirrus/cs_dsp.c       | 56 ++++++++++++--------------
 include/linux/firmware/cirrus/cs_dsp.h |  4 +-
 2 files changed, 28 insertions(+), 32 deletions(-)

-- 
2.47.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] firmware: cs_dsp: Factor out common debugfs string read
  2025-11-20 13:06 [PATCH 0/2] firmware: cs_dsp: Cleanup debugfs for wmfw and bin file name Richard Fitzgerald
@ 2025-11-20 13:06 ` Richard Fitzgerald
  2025-11-20 13:06 ` [PATCH 2/2] firmware: cs_dsp: Append \n to debugfs string during read Richard Fitzgerald
  2025-11-21 14:14 ` [PATCH 0/2] firmware: cs_dsp: Cleanup debugfs for wmfw and bin file name Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Fitzgerald @ 2025-11-20 13:06 UTC (permalink / raw)
  To: broonie; +Cc: linux-sound, linux-kernel, patches

cs_dsp_debugfs_wmfw_read() and cs_dsp_debugfs_bin_read() were identical
except for which struct member they printed. Move all this duplicated
code into a common function cs_dsp_debugfs_string_read().

The check for dsp->booted has been removed because this is redundant.
The two strings are set when the DSP is booted and cleared when the
DSP is powered-down.

Access to the string char * must be protected by the pwr_lock mutex. The
string is passed into cs_dsp_debugfs_string_read() as a pointer to the
char * so that the mutex lock can also be factored out into
cs_dsp_debugfs_string_read().

wmfw_file_name and bin_file_name members of struct cs_dsp have been
changed to const char *. It makes for a better API to pass a const
pointer into cs_dsp_debugfs_string_read().

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 drivers/firmware/cirrus/cs_dsp.c       | 45 ++++++++++++--------------
 include/linux/firmware/cirrus/cs_dsp.h |  4 +--
 2 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/drivers/firmware/cirrus/cs_dsp.c b/drivers/firmware/cirrus/cs_dsp.c
index f51047d8ea64..58e41751dbc1 100644
--- a/drivers/firmware/cirrus/cs_dsp.c
+++ b/drivers/firmware/cirrus/cs_dsp.c
@@ -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>
@@ -410,24 +411,30 @@ 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;
+
+	scoped_guard(mutex, &dsp->pwr_lock) {
+		str = *pstr;
+		if (!str)
+			return 0;
+
+		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 +442,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 {
diff --git a/include/linux/firmware/cirrus/cs_dsp.h b/include/linux/firmware/cirrus/cs_dsp.h
index a66eb7624730..69959032f8f5 100644
--- a/include/linux/firmware/cirrus/cs_dsp.h
+++ b/include/linux/firmware/cirrus/cs_dsp.h
@@ -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
 };
 
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] firmware: cs_dsp: Append \n to debugfs string during read
  2025-11-20 13:06 [PATCH 0/2] firmware: cs_dsp: Cleanup debugfs for wmfw and bin file name Richard Fitzgerald
  2025-11-20 13:06 ` [PATCH 1/2] firmware: cs_dsp: Factor out common debugfs string read Richard Fitzgerald
@ 2025-11-20 13:06 ` Richard Fitzgerald
  2025-11-21 14:14 ` [PATCH 0/2] firmware: cs_dsp: Cleanup debugfs for wmfw and bin file name Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Fitzgerald @ 2025-11-20 13:06 UTC (permalink / raw)
  To: broonie; +Cc: linux-sound, linux-kernel, patches

Append the terminating \n to the string during the debugfs file
read instead of creating a string that already has a trailing \n.

This avoids the ugly behaviour of having to include a trailing \n
in the filenames stored to wmfw_file_name and bin_file_name in
struct cs_dsp.

Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com>
---
 drivers/firmware/cirrus/cs_dsp.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/firmware/cirrus/cs_dsp.c b/drivers/firmware/cirrus/cs_dsp.c
index 58e41751dbc1..9acdcd75928a 100644
--- a/drivers/firmware/cirrus/cs_dsp.c
+++ b/drivers/firmware/cirrus/cs_dsp.c
@@ -389,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)
@@ -416,13 +412,16 @@ static ssize_t cs_dsp_debugfs_string_read(struct cs_dsp *dsp,
 					  size_t count, loff_t *ppos,
 					  const char **pstr)
 {
-	const char *str;
+	const char *str __free(kfree) = NULL;
 
 	scoped_guard(mutex, &dsp->pwr_lock) {
-		str = *pstr;
-		if (!str)
+		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));
 	}
 }
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] firmware: cs_dsp: Cleanup debugfs for wmfw and bin file name
  2025-11-20 13:06 [PATCH 0/2] firmware: cs_dsp: Cleanup debugfs for wmfw and bin file name Richard Fitzgerald
  2025-11-20 13:06 ` [PATCH 1/2] firmware: cs_dsp: Factor out common debugfs string read Richard Fitzgerald
  2025-11-20 13:06 ` [PATCH 2/2] firmware: cs_dsp: Append \n to debugfs string during read Richard Fitzgerald
@ 2025-11-21 14:14 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2025-11-21 14:14 UTC (permalink / raw)
  To: Richard Fitzgerald; +Cc: linux-sound, linux-kernel, patches

On Thu, 20 Nov 2025 13:06:38 +0000, Richard Fitzgerald wrote:
> 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.
> 
> Richard Fitzgerald (2):
>   firmware: cs_dsp: Factor out common debugfs string read
>   firmware: cs_dsp: Append \n to debugfs string during read
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/2] firmware: cs_dsp: Factor out common debugfs string read
      commit: 78cfd833bc04c0398ca4cfc64704350aebe4d4c2
[2/2] firmware: cs_dsp: Append \n to debugfs string during read
      commit: 3045e29d248bde2a68da425498a656093ee0df69

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-11-21 14:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-20 13:06 [PATCH 0/2] firmware: cs_dsp: Cleanup debugfs for wmfw and bin file name Richard Fitzgerald
2025-11-20 13:06 ` [PATCH 1/2] firmware: cs_dsp: Factor out common debugfs string read Richard Fitzgerald
2025-11-20 13:06 ` [PATCH 2/2] firmware: cs_dsp: Append \n to debugfs string during read Richard Fitzgerald
2025-11-21 14:14 ` [PATCH 0/2] firmware: cs_dsp: Cleanup debugfs for wmfw and bin file name Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox