firmware: cs_dsp: Some small coding improvements
Richard Fitzgerald
maintainercover firmware: cs_dsp: Some small coding improvements
Commit series that makes some small improvements to code and the kernel log messages.
Richard Fitzgerald (4):
firmware: cs_dsp: Don't allocate temporary buffer for info text
firmware: cs_dsp: Make wmfw and bin filename arguments const char *
firmware: cs_dsp: Merge wmfw format log message into INFO message
firmware: cs_dsp: Rename fw_ver to wmfw_ver
drivers/firmware/cirrus/cs_dsp.c | 64 +++++++++----------------- include/linux/firmware/cirrus/cs_dsp.h | 10 ++-- sound/soc/codecs/wm_adsp.c | 2 +- 3 files changed, 27 insertions(+), 49 deletions(-)
Signature · 1 line
2.39.2
Richard Fitzgerald
maintainerPATCH 1/4 firmware: cs_dsp: Don't allocate temporary buffer for info text
Don't allocate a temporary buffer to hold a NUL-terminated copy of the NAME/INFO string from the wmfw/bin. It can be printed directly to the log. Also limit the maximum number of characters that will be logged from this string.
The NAME/INFO blocks in the firmware files are an array of characters with a length, not a NUL-terminated C string. The original code allocated a temporary buffer to make a NUL-terminated copy of the string and then passed that to dev_info(). There's no need for this: printf formatting can use "%.*s" to print a character array of a given length.
--- drivers/firmware/cirrus/cs_dsp.c | 35 +++++++------------------------- 1 file changed, 7 insertions(+), 28 deletions(-)
drivers/firmware/cirrus/cs_dsp.c +7 -28
@@ -12,6 +12,7 @@#include <linux/ctype.h> #include <linux/debugfs.h> #include <linux/delay.h> +#include <linux/minmax.h> #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/seq_file.h>
@@ -1473,7 +1474,6 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware,const struct wmfw_region *region;const struct cs_dsp_region *mem;const char *region_name; -char *text =NULL ;struct cs_dsp_buf *buf;unsigned int reg;int regions =0 ;
@@ -1545,15 +1545,15 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware, region_name ="Unknown" ; reg =0 ; - text =NULL ; offset =le32_to_cpu (region->offset) &0xffffff ; type =be32_to_cpu (region->type) &0xff ;switch (type) { +case WMFW_INFO_TEXT :case WMFW_NAME_TEXT : - region_name ="Firmware name" ; - text =kzalloc (le32_to_cpu (region->len) +1 , -GFP_KERNEL ); + region_name ="Info/Name" ; +cs_dsp_info (dsp,"%s: %.*s\n" , file, +min (le32_to_cpu (region->len),100 ), region->data);break ;case WMFW_ALGORITHM_DATA : region_name ="Algorithm" ;
@@ -1561,11 +1561,6 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware,if (ret !=0 ) goto out_fw;break ; -case WMFW_INFO_TEXT : - region_name ="Information" ; - text =kzalloc (le32_to_cpu (region->len) +1 , -GFP_KERNEL ); -break ;case WMFW_ABSOLUTE : region_name ="Absolute" ; reg = offset;
@@ -1599,13 +1594,6 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware, regions,le32_to_cpu (region->len), offset, region_name); -if (text) { -memcpy (text, region->data,le32_to_cpu (region->len)); -cs_dsp_info (dsp,"%s: %s\n" , file, text); -kfree (text); - text =NULL ; - } -if (reg) { buf = cs_dsp_buf_alloc(region->data, le32_to_cpu(region->len),
@@ -1647,7 +1635,6 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware, out_fw:regmap_async_complete (regmap);cs_dsp_buf_free (&buf_list); -kfree (text);if (ret == -EOVERFLOW )cs_dsp_err (dsp,"%s: file content overflows file data\n" , file);
@@ -2180,7 +2167,6 @@ static int cs_dsp_load_coeff(struct cs_dsp *dsp, const struct firmware *firmwarestruct cs_dsp_alg_region *alg_region;const char *region_name;int ret, pos, blocks, type, offset, reg, version; -char *text =NULL ;struct cs_dsp_buf *buf;if (!firmware)
@@ -2249,7 +2235,8 @@ static int cs_dsp_load_coeff(struct cs_dsp *dsp, const struct firmware *firmware region_name ="Unknown" ;switch (type) {case (WMFW_NAME_TEXT <<8 ): - text =kzalloc (le32_to_cpu (blk->len) +1 ,GFP_KERNEL ); +cs_dsp_info (dsp,"%s: %.*s\n" , dsp->fw_name, +min (le32_to_cpu (blk->len),100 ), blk->data);break ;case (WMFW_INFO_TEXT <<8 ):case (WMFW_METADATA <<8 ):
@@ -2321,13 +2308,6 @@ static int cs_dsp_load_coeff(struct cs_dsp *dsp, const struct firmware *firmwarebreak ; } -if (text) { -memcpy (text, blk->data,le32_to_cpu (blk->len)); -cs_dsp_info (dsp,"%s: %s\n" , dsp->fw_name, text); -kfree (text); - text =NULL ; - } -if (reg) { buf = cs_dsp_buf_alloc(blk->data, le32_to_cpu(blk->len),
@@ -2367,7 +2347,6 @@ static int cs_dsp_load_coeff(struct cs_dsp *dsp, const struct firmware *firmware out_fw:regmap_async_complete (regmap);cs_dsp_buf_free (&buf_list); -kfree (text);if (ret == -EOVERFLOW )cs_dsp_err (dsp,"%s: file content overflows file data\n" , file);
Signature · 1 line
2.39.2
Richard Fitzgerald
maintainerPATCH 2/4 firmware: cs_dsp: Make wmfw and bin filename arguments const char *
In reply to Richard FitzgeraldThe wmfw_filename and bin_filename strings passed into cs_dsp_power_up() and cs_dsp_adsp1_power_up() should be const char *.
--- drivers/firmware/cirrus/cs_dsp.c | 8 ++++---- include/linux/firmware/cirrus/cs_dsp.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/firmware/cirrus/cs_dsp.c +4 -4
@@ -2413,8 +2413,8 @@ EXPORT_SYMBOL_NS_GPL(cs_dsp_adsp1_init, FW_CS_DSP);* Return: Zero for success, a negative number on error. */ int cs_dsp_adsp1_power_up (struct cs_dsp *dsp, -const struct firmware *wmfw_firmware,char *wmfw_filename, -const struct firmware *coeff_firmware,char *coeff_filename, +const struct firmware *wmfw_firmware,const char *wmfw_filename, +const struct firmware *coeff_firmware,const char *coeff_filename,const char *fw_name) {unsigned int val;
@@ -2707,8 +2707,8 @@ static void cs_dsp_halo_stop_watchdog(struct cs_dsp *dsp)* Return: Zero for success, a negative number on error. */ int cs_dsp_power_up (struct cs_dsp *dsp, -const struct firmware *wmfw_firmware,char *wmfw_filename, -const struct firmware *coeff_firmware,char *coeff_filename, +const struct firmware *wmfw_firmware,const char *wmfw_filename, +const struct firmware *coeff_firmware,const char *coeff_filename,const char *fw_name) {int ret;
include/linux/firmware/cirrus/cs_dsp.h +4 -4
@@ -213,13 +213,13 @@ int cs_dsp_adsp2_init(struct cs_dsp *dsp);int cs_dsp_halo_init (struct cs_dsp *dsp);int cs_dsp_adsp1_power_up (struct cs_dsp *dsp, -const struct firmware *wmfw_firmware,char *wmfw_filename, -const struct firmware *coeff_firmware,char *coeff_filename, +const struct firmware *wmfw_firmware,const char *wmfw_filename, +const struct firmware *coeff_firmware,const char *coeff_filename,const char *fw_name);void cs_dsp_adsp1_power_down (struct cs_dsp *dsp);int cs_dsp_power_up (struct cs_dsp *dsp, -const struct firmware *wmfw_firmware,char *wmfw_filename, -const struct firmware *coeff_firmware,char *coeff_filename, +const struct firmware *wmfw_firmware,const char *wmfw_filename, +const struct firmware *coeff_firmware,const char *coeff_filename,const char *fw_name);void cs_dsp_power_down (struct cs_dsp *dsp);int cs_dsp_run (struct cs_dsp *dsp);
Signature · 1 line
2.39.2
Richard Fitzgerald
maintainerPATCH 3/4 firmware: cs_dsp: Merge wmfw format log message into INFO message
In reply to Richard FitzgeraldLog the WMFW file format version with the INFO_TEST message.
The behaviour of firmware controls depends on the WMFW format version, so this is useful information to log for debugging. But there's no need to use a separate log line just for this value.
--- drivers/firmware/cirrus/cs_dsp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/firmware/cirrus/cs_dsp.c +1 -2
@@ -1502,7 +1502,6 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware, goto out_fw; } -cs_dsp_info (dsp,"Firmware version: %d\n" , header->ver); dsp->fw_ver = header->ver;if (header->core != dsp->type) {
@@ -1552,7 +1551,7 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware,case WMFW_INFO_TEXT :case WMFW_NAME_TEXT : region_name ="Info/Name" ; -cs_dsp_info (dsp,"%s: %.*s\n" , file, +cs_dsp_info (dsp,"%s (rev %d): %.*s\n" , file, dsp->fw_ver,min (le32_to_cpu (region->len),100 ), region->data);break ;case WMFW_ALGORITHM_DATA :
Signature · 1 line
2.39.2
Charles Keepax
maintainerRe: [PATCH 3/4] firmware: cs_dsp: Merge wmfw format log message into INFO message
Quoted 24 lines · Richard Fitzgerald
Log the WMFW file format version with the
INFO_TESTmessage.The behaviour of firmware controls depends on the WMFW format version, so this is useful information to log for debugging. But there's no need to use a separate log line just for this value.
Signed-off-by Richard Fitzgerald <[email protected]>--- drivers/firmware/cirrus/cs_dsp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/firmware/cirrus/cs_dsp.c +0
-1@@ -1502,7 +1502,6 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware, goto out_fw; } -cs_dsp_info (dsp,"Firmware version: %d\n" , header->ver); dsp->fw_ver = header->ver;if (header->core != dsp->type) {
drivers/firmware/cirrus/cs_dsp.c static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware, · line 1555
Quoted 6 lines
drivers/firmware/cirrus/cs_dsp.c +1
-1@@ -1552,7 +1551,7 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware,case WMFW_INFO_TEXT :case WMFW_NAME_TEXT : region_name ="Info/Name" ; -cs_dsp_info (dsp,"%s: %.*s\n" , file, +cs_dsp_info (dsp,"%s (rev %d): %.*s\n" , file, dsp->fw_ver,min (le32_to_cpu (region->len),100 ), region->data);
Are we sure on this one? I don't think a WMFW is required to include an INFO/NAME block so it is now possible for this to not get printed. Granted I have not seen one that doesn't include at least one of these blocks but it isn't required. I think I would lean towards keening the separate print personally.
Thanks,
Charles
Richard Fitzgerald
maintainerRe: [PATCH 3/4] firmware: cs_dsp: Merge wmfw format log message into INFO message
Quoted 38 lines · Charles Keepax
Quoted 24 lines · Richard Fitzgerald
Log the WMFW file format version with the
INFO_TESTmessage.The behaviour of firmware controls depends on the WMFW format version, so this is useful information to log for debugging. But there's no need to use a separate log line just for this value.
Signed-off-by Richard Fitzgerald <[email protected]>--- drivers/firmware/cirrus/cs_dsp.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/firmware/cirrus/cs_dsp.c +0
-1@@ -1502,7 +1502,6 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware, goto out_fw; } -cs_dsp_info (dsp,"Firmware version: %d\n" , header->ver); dsp->fw_ver = header->ver;if (header->core != dsp->type) {drivers/firmware/cirrus/cs_dsp.c static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware, · line 1555
Quoted 6 lines
drivers/firmware/cirrus/cs_dsp.c +1
-1@@ -1552,7 +1551,7 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware,case WMFW_INFO_TEXT :case WMFW_NAME_TEXT : region_name ="Info/Name" ; -cs_dsp_info (dsp,"%s: %.*s\n" , file, +cs_dsp_info (dsp,"%s (rev %d): %.*s\n" , file, dsp->fw_ver,min (le32_to_cpu (region->len),100 ), region->data);Are we sure on this one? I don't think a WMFW is required to include an INFO/NAME block so it is now possible for this to not get printed. Granted I have not seen one that doesn't include at least one of these blocks but it isn't required. I think I would lean towards keening the separate print personally.
Quoted 2 lines
Thanks,
Charles
The specification says that the first INFO block is mandatory, but specifications can change so I don't mind leaving it on its own line.
I've just noticed a typo in the commit description (INFO_TEST should be INFO_TEXT) so I want to send a V2 chain anyway.
Richard Fitzgerald
maintainerPATCH 4/4 firmware: cs_dsp: Rename fw_ver to wmfw_ver
In reply to Richard FitzgeraldRename the confusingly named struct member fw_ver to wmfw_ver. It contains the wmfw format version of the loaded wmfw file.
This commit also contains an update to wm_adsp for the new name.
--- drivers/firmware/cirrus/cs_dsp.c | 22 +++++++++++----------- include/linux/firmware/cirrus/cs_dsp.h | 2 +- sound/soc/codecs/wm_adsp.c | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-)
drivers/firmware/cirrus/cs_dsp.c +11 -11
@@ -1051,7 +1051,7 @@ static int cs_dsp_create_control(struct cs_dsp *dsp, ctl->fw_name = dsp->fw_name; ctl->alg_region = *alg_region; -if (subname && dsp->fw_ver >=2 ) { +if (subname && dsp->wmfw_ver >=2 ) { ctl->subname_len = subname_len; ctl->subname =kasprintf (GFP_KERNEL ,"%.*s" , subname_len, subname);if (!ctl->subname) {
@@ -1178,7 +1178,7 @@ static int cs_dsp_coeff_parse_alg(struct cs_dsp *dsp, raw = (const struct wmfw_adsp_alg_data *)region->data; -switch (dsp->fw_ver) { +switch (dsp->wmfw_ver) {case 0 :case 1 :if (sizeof (*raw) > data_len)
@@ -1255,7 +1255,7 @@ static int cs_dsp_coeff_parse_coeff(struct cs_dsp *dsp, blk->offset =le16_to_cpu (raw->hdr.offset); blk->mem_type =le16_to_cpu (raw->hdr.type); -switch (dsp->fw_ver) { +switch (dsp->wmfw_ver) {case 0 :case 1 :if (sizeof (*raw) > (data_len - pos))
@@ -1502,7 +1502,7 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware, goto out_fw; } - dsp->fw_ver = header->ver; + dsp->wmfw_ver = header->ver;if (header->core != dsp->type) { cs_dsp_err(dsp, "%s: invalid core %d != %d\n",
@@ -1551,7 +1551,7 @@ static int cs_dsp_load(struct cs_dsp *dsp, const struct firmware *firmware,case WMFW_INFO_TEXT :case WMFW_NAME_TEXT : region_name ="Info/Name" ; -cs_dsp_info (dsp,"%s (rev %d): %.*s\n" , file, dsp->fw_ver, +cs_dsp_info (dsp,"%s (rev %d): %.*s\n" , file, dsp->wmfw_ver,min (le32_to_cpu (region->len),100 ), region->data);break ;case WMFW_ALGORITHM_DATA :
@@ -1782,7 +1782,7 @@ static struct cs_dsp_alg_region *cs_dsp_create_region(struct cs_dsp *dsp,list_add_tail (&alg_region->list, &dsp->alg_regions); -if (dsp->fw_ver >0 ) +if (dsp->wmfw_ver >0 )cs_dsp_ctl_fixup_base (dsp, alg_region);return alg_region;
@@ -1905,7 +1905,7 @@ static int cs_dsp_adsp1_setup_algs(struct cs_dsp *dsp) ret =PTR_ERR (alg_region); goto out; } -if (dsp->fw_ver ==0 ) { +if (dsp->wmfw_ver ==0 ) {if (i +1 < n_algs) { len =be32_to_cpu (adsp1_alg[i +1 ].dm); len -=be32_to_cpu (adsp1_alg[i].dm);
@@ -1927,7 +1927,7 @@ static int cs_dsp_adsp1_setup_algs(struct cs_dsp *dsp) ret =PTR_ERR (alg_region); goto out; } -if (dsp->fw_ver ==0 ) { +if (dsp->wmfw_ver ==0 ) {if (i +1 < n_algs) { len =be32_to_cpu (adsp1_alg[i +1 ].zm); len -=be32_to_cpu (adsp1_alg[i].zm);
@@ -2018,7 +2018,7 @@ static int cs_dsp_adsp2_setup_algs(struct cs_dsp *dsp) ret =PTR_ERR (alg_region); goto out; } -if (dsp->fw_ver ==0 ) { +if (dsp->wmfw_ver ==0 ) {if (i +1 < n_algs) { len =be32_to_cpu (adsp2_alg[i +1 ].xm); len -=be32_to_cpu (adsp2_alg[i].xm);
@@ -2040,7 +2040,7 @@ static int cs_dsp_adsp2_setup_algs(struct cs_dsp *dsp) ret =PTR_ERR (alg_region); goto out; } -if (dsp->fw_ver ==0 ) { +if (dsp->wmfw_ver ==0 ) {if (i +1 < n_algs) { len =be32_to_cpu (adsp2_alg[i +1 ].ym); len -=be32_to_cpu (adsp2_alg[i].ym);
@@ -2062,7 +2062,7 @@ static int cs_dsp_adsp2_setup_algs(struct cs_dsp *dsp) ret =PTR_ERR (alg_region); goto out; } -if (dsp->fw_ver ==0 ) { +if (dsp->wmfw_ver ==0 ) {if (i +1 < n_algs) { len =be32_to_cpu (adsp2_alg[i +1 ].zm); len -=be32_to_cpu (adsp2_alg[i].zm);
include/linux/firmware/cirrus/cs_dsp.h +1 -1
@@ -167,7 +167,7 @@ struct cs_dsp {const struct cs_dsp_region *mem;int num_mems; -int fw_ver; +int wmfw_ver;bool booted;bool running;
sound/soc/codecs/wm_adsp.c +1 -1
@@ -601,7 +601,7 @@ static int wm_adsp_control_add(struct cs_dsp_coeff_ctl *cs_ctl)return -EINVAL ; } -switch (cs_dsp->fw_ver) { +switch (cs_dsp->wmfw_ver) {case 0 :case 1 : ret = scnprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN,
Signature · 1 line
2.39.2