From: Richard Fitzgerald Date: Thu, 20 Nov 2025 13:06:40 +0000 (+0000) Subject: firmware: cs_dsp: Append \n to debugfs string during read X-Git-Tag: v6.19-rc1~156^2~3^2~25^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3045e29d248bde2a68da425498a656093ee0df69;p=thirdparty%2Fkernel%2Flinux.git firmware: cs_dsp: Append \n to debugfs string during read 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 Link: https://patch.msgid.link/20251120130640.1169780-3-rf@opensource.cirrus.com Signed-off-by: Mark Brown --- diff --git a/drivers/firmware/cirrus/cs_dsp.c b/drivers/firmware/cirrus/cs_dsp.c index 58e41751dbc19..9acdcd75928a9 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)); } }