CC: [email protected]
CC: [email protected]
BCC: [email protected]
CC: [email protected]
TO: Simon Trimmer <[email protected]>
CC: Mark Brown <[email protected]>
CC: Charles Keepax <[email protected]>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
master
head:   e729dbe8ea1c6145ae7b9efd6a00a5613746d3b0
commit: f6bc909e7673c30abcbdb329e7d0aa2e83c103d7 firmware: cs_dsp: add driver 
to support firmware loading on Cirrus Logic DSPs
date:   6 months ago
:::::: branch date: 2 hours ago
:::::: commit date: 6 months ago
config: mips-randconfig-c004-20220331 
(https://download.01.org/0day-ci/archive/20220401/[email protected]/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project 
0f6d9501cf49ce02937099350d08f20c4af86f3d)
reproduce (this is a W=1 build):
        wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install mips cross compiling tool for clang build
        # apt-get install binutils-mips-linux-gnu
        # 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f6bc909e7673c30abcbdb329e7d0aa2e83c103d7
        git remote add linus 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
        git fetch --no-tags linus master
        git checkout f6bc909e7673c30abcbdb329e7d0aa2e83c103d7
        # save the config file to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips 
clang-analyzer 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>


clang-analyzer warnings: (new ones prefixed by >>)
           ^
   include/linux/uaccess.h:193:2: note: Returning zero (loaded from 'n'), which 
participates in a condition later
           return n;
           ^~~~~~~~
   drivers/hwtracing/stm/core.c:736:6: note: Returning from 'copy_from_user'
           if (copy_from_user(&size, arg, sizeof(size)))
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/hwtracing/stm/core.c:736:2: note: Taking false branch
           if (copy_from_user(&size, arg, sizeof(size)))
           ^
   drivers/hwtracing/stm/core.c:739:11: note: The left operand of '<' is a 
garbage value
           if (size < sizeof(*id) || size >= PATH_MAX + sizeof(*id))
               ~~~~ ^
   drivers/hwtracing/stm/core.c:821:10: warning: 5th function call argument is 
an uninitialized value [clang-analyzer-core.CallAndMessage]
                           err = stm_data->set_options(stm_data,
                                 ^
   drivers/hwtracing/stm/core.c:803:2: note: 'options' declared without an 
initial value
           u64 options;
           ^~~~~~~~~~~
   drivers/hwtracing/stm/core.c:805:2: note: Control jumps to 'case 
2148017410:'  at line 816
           switch (cmd) {
           ^
   drivers/hwtracing/stm/core.c:817:7: note: Calling 'copy_from_user'
                   if (copy_from_user(&options, (u64 __user *)arg, sizeof(u64)))
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/uaccess.h:191:2: note: Taking true branch
           if (likely(check_copy_size(to, n, false)))
           ^
   include/linux/uaccess.h:192:7: note: Calling '_copy_from_user'
                   n = _copy_from_user(to, from, n);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/uaccess.h:157:7: note: Calling 'should_fail_usercopy'
           if (!should_fail_usercopy() && likely(access_ok(from, n))) {
                ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/fault-inject-usercopy.h:18:49: note: Returning zero, which 
participates in a condition later
   static inline bool should_fail_usercopy(void) { return false; }
                                                   ^~~~~~~~~~~~
   include/linux/uaccess.h:157:7: note: Returning from 'should_fail_usercopy'
           if (!should_fail_usercopy() && likely(access_ok(from, n))) {
                ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/uaccess.h:157:6: note: Left side of '&&' is true
           if (!should_fail_usercopy() && likely(access_ok(from, n))) {
               ^
   include/linux/uaccess.h:157:2: note: Taking true branch
           if (!should_fail_usercopy() && likely(access_ok(from, n))) {
           ^
   include/linux/uaccess.h:159:9: note: Calling 'raw_copy_from_user'
                   res = raw_copy_from_user(to, from, n);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/mips/include/asm/uaccess.h:455:2: note: Returning without writing to 
'*to'
           return __cu_len_r;
           ^
   include/linux/uaccess.h:159:9: note: Returning from 'raw_copy_from_user'
                   res = raw_copy_from_user(to, from, n);
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/uaccess.h:161:6: note: Assuming 'res' is 0, which participates 
in a condition later
           if (unlikely(res))
               ^
   include/linux/compiler.h:78:40: note: expanded from macro 'unlikely'
   # define unlikely(x)    __builtin_expect(!!(x), 0)
                                             ^~~~
   include/linux/uaccess.h:161:2: note: Taking false branch
           if (unlikely(res))
           ^
   include/linux/uaccess.h:163:2: note: Returning without writing to '*to'
           return res;
           ^
   include/linux/uaccess.h:163:2: note: Returning zero (loaded from 'res'), 
which participates in a condition later
           return res;
           ^~~~~~~~~~
   include/linux/uaccess.h:192:7: note: Returning from '_copy_from_user'
                   n = _copy_from_user(to, from, n);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/uaccess.h:193:2: note: Returning without writing to '*to'
           return n;
           ^
   include/linux/uaccess.h:193:2: note: Returning zero (loaded from 'n'), which 
participates in a condition later
           return n;
           ^~~~~~~~
   drivers/hwtracing/stm/core.c:817:7: note: Returning from 'copy_from_user'
                   if (copy_from_user(&options, (u64 __user *)arg, sizeof(u64)))
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/hwtracing/stm/core.c:817:3: note: Taking false branch
                   if (copy_from_user(&options, (u64 __user *)arg, sizeof(u64)))
                   ^
   drivers/hwtracing/stm/core.c:820:7: note: Assuming field 'set_options' is 
non-null
                   if (stm_data->set_options)
                       ^~~~~~~~~~~~~~~~~~~~~
   drivers/hwtracing/stm/core.c:820:3: note: Taking true branch
                   if (stm_data->set_options)
                   ^
   drivers/hwtracing/stm/core.c:821:10: note: 5th function call argument is an 
uninitialized value
                           err = stm_data->set_options(stm_data,
                                 ^
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use 
-system-headers to display errors from system headers as well.
   4 warnings generated.
   Suppressed 4 warnings (4 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use 
-system-headers to display errors from system headers as well.
   9 warnings generated.
>> drivers/firmware/cirrus/cs_dsp.c:1211:2: warning: Value stored to 
>> 'adsp1_sizes' is never read [clang-analyzer-deadcode.DeadStores]
           adsp1_sizes = (void *)&firmware->data[pos];
           ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/firmware/cirrus/cs_dsp.c:1211:2: note: Value stored to 'adsp1_sizes' 
is never read
           adsp1_sizes = (void *)&firmware->data[pos];
           ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/firmware/cirrus/cs_dsp.c:1227:2: warning: Value stored to 
>> 'adsp2_sizes' is never read [clang-analyzer-deadcode.DeadStores]
           adsp2_sizes = (void *)&firmware->data[pos];
           ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/firmware/cirrus/cs_dsp.c:1227:2: note: Value stored to 'adsp2_sizes' 
is never read
           adsp2_sizes = (void *)&firmware->data[pos];
           ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/firmware/cirrus/cs_dsp.c:1312:2: warning: Value stored to 'footer' 
>> is never read [clang-analyzer-deadcode.DeadStores]
           footer = (void *)&firmware->data[pos];
           ^        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/firmware/cirrus/cs_dsp.c:1312:2: note: Value stored to 'footer' is 
never read
           footer = (void *)&firmware->data[pos];
           ^        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/list.h:135:13: warning: Use of memory after it is freed 
[clang-analyzer-unix.Malloc]
           __list_del(entry->prev, entry->next);
                      ^
   drivers/firmware/cirrus/cs_dsp.c:2759:2: note: Loop condition is true.  
Entering loop body
           while (!list_empty(&dsp->ctl_list)) {
           ^
   drivers/firmware/cirrus/cs_dsp.c:2760:9: note: Left side of '&&' is false
                   ctl = list_first_entry(&dsp->ctl_list, struct 
cs_dsp_coeff_ctl, list);
                         ^
   include/linux/list.h:522:2: note: expanded from macro 'list_first_entry'
           list_entry((ptr)->next, type, member)
           ^
   include/linux/list.h:511:2: note: expanded from macro 'list_entry'
           container_of(ptr, type, member)
           ^
   include/linux/kernel.h:495:61: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
                                                                      ^
   drivers/firmware/cirrus/cs_dsp.c:2760:9: note: Taking false branch
                   ctl = list_first_entry(&dsp->ctl_list, struct 
cs_dsp_coeff_ctl, list);
                         ^
   include/linux/list.h:522:2: note: expanded from macro 'list_first_entry'
           list_entry((ptr)->next, type, member)
           ^
   include/linux/list.h:511:2: note: expanded from macro 'list_entry'
           container_of(ptr, type, member)
           ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to 
see all)
   include/linux/compiler_types.h:322:2: note: expanded from macro 
'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, 
__COUNTER__)
           ^
   include/linux/compiler_types.h:310:2: note: expanded from macro 
'_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:302:3: note: expanded from macro 
'__compiletime_assert'
                   if (!(condition))                                       \
                   ^
   drivers/firmware/cirrus/cs_dsp.c:2760:9: note: Loop condition is false.  
Exiting loop
                   ctl = list_first_entry(&dsp->ctl_list, struct 
cs_dsp_coeff_ctl, list);
                         ^
   include/linux/list.h:522:2: note: expanded from macro 'list_first_entry'
           list_entry((ptr)->next, type, member)
           ^
   include/linux/list.h:511:2: note: expanded from macro 'list_entry'
           container_of(ptr, type, member)
           ^
   include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
           ^
   note: (skipping 1 expansions in backtrace; use -fmacro-backtrace-limit=0 to 
see all)
   include/linux/compiler_types.h:322:2: note: expanded from macro 
'compiletime_assert'
           _compiletime_assert(condition, msg, __compiletime_assert_, 
__COUNTER__)
           ^
   include/linux/compiler_types.h:310:2: note: expanded from macro 
'_compiletime_assert'
           __compiletime_assert(condition, msg, prefix, suffix)
           ^
   include/linux/compiler_types.h:300:2: note: expanded from macro 
'__compiletime_assert'
           do {                                                            \
           ^
   drivers/firmware/cirrus/cs_dsp.c:2762:7: note: Assuming field 
'control_remove' is null
                   if (dsp->client_ops->control_remove)
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/firmware/cirrus/cs_dsp.c:2762:3: note: Taking false branch
                   if (dsp->client_ops->control_remove)
                   ^
   drivers/firmware/cirrus/cs_dsp.c:2766:3: note: Calling 'cs_dsp_free_ctl_blk'
                   cs_dsp_free_ctl_blk(ctl);
                   ^~~~~~~~~~~~~~~~~~~~~~~~
   drivers/firmware/cirrus/cs_dsp.c:907:2: note: Memory is released
           kfree(ctl);
           ^~~~~~~~~~
   drivers/firmware/cirrus/cs_dsp.c:2766:3: note: Returning; memory was released
                   cs_dsp_free_ctl_blk(ctl);
                   ^~~~~~~~~~~~~~~~~~~~~~~~
   drivers/firmware/cirrus/cs_dsp.c:2759:2: note: Loop condition is true.  
Entering loop body
           while (!list_empty(&dsp->ctl_list)) {
           ^
   drivers/firmware/cirrus/cs_dsp.c:2760:9: note: Left side of '&&' is false
                   ctl = list_first_entry(&dsp->ctl_list, struct 
cs_dsp_coeff_ctl, list);
                         ^
   include/linux/list.h:522:2: note: expanded from macro 'list_first_entry'
           list_entry((ptr)->next, type, member)
           ^
   include/linux/list.h:511:2: note: expanded from macro 'list_entry'
           container_of(ptr, type, member)
           ^
   include/linux/kernel.h:495:61: note: expanded from macro 'container_of'
           BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) &&   \
                                                                      ^
   drivers/firmware/cirrus/cs_dsp.c:2760:9: note: Taking false branch
                   ctl = list_first_entry(&dsp->ctl_list, struct 
cs_dsp_coeff_ctl, list);
                         ^

vim +/adsp1_sizes +1211 drivers/firmware/cirrus/cs_dsp.c

f6bc909e7673c3 Simon Trimmer 2021-09-13  1203  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1204  static unsigned int 
cs_dsp_adsp1_parse_sizes(struct cs_dsp *dsp,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1205                                   
     const char * const file,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1206                                   
     unsigned int pos,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1207                                   
     const struct firmware *firmware)
f6bc909e7673c3 Simon Trimmer 2021-09-13  1208  {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1209   const struct wmfw_adsp1_sizes 
*adsp1_sizes;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1210  
f6bc909e7673c3 Simon Trimmer 2021-09-13 @1211   adsp1_sizes = (void 
*)&firmware->data[pos];
f6bc909e7673c3 Simon Trimmer 2021-09-13  1212  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1213   cs_dsp_dbg(dsp, "%s: %d DM, %d 
PM, %d ZM\n", file,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1214              
le32_to_cpu(adsp1_sizes->dm), le32_to_cpu(adsp1_sizes->pm),
f6bc909e7673c3 Simon Trimmer 2021-09-13  1215              
le32_to_cpu(adsp1_sizes->zm));
f6bc909e7673c3 Simon Trimmer 2021-09-13  1216  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1217   return pos + 
sizeof(*adsp1_sizes);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1218  }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1219  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1220  static unsigned int 
cs_dsp_adsp2_parse_sizes(struct cs_dsp *dsp,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1221                                   
     const char * const file,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1222                                   
     unsigned int pos,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1223                                   
     const struct firmware *firmware)
f6bc909e7673c3 Simon Trimmer 2021-09-13  1224  {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1225   const struct wmfw_adsp2_sizes 
*adsp2_sizes;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1226  
f6bc909e7673c3 Simon Trimmer 2021-09-13 @1227   adsp2_sizes = (void 
*)&firmware->data[pos];
f6bc909e7673c3 Simon Trimmer 2021-09-13  1228  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1229   cs_dsp_dbg(dsp, "%s: %d XM, %d 
YM %d PM, %d ZM\n", file,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1230              
le32_to_cpu(adsp2_sizes->xm), le32_to_cpu(adsp2_sizes->ym),
f6bc909e7673c3 Simon Trimmer 2021-09-13  1231              
le32_to_cpu(adsp2_sizes->pm), le32_to_cpu(adsp2_sizes->zm));
f6bc909e7673c3 Simon Trimmer 2021-09-13  1232  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1233   return pos + 
sizeof(*adsp2_sizes);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1234  }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1235  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1236  static bool 
cs_dsp_validate_version(struct cs_dsp *dsp, unsigned int version)
f6bc909e7673c3 Simon Trimmer 2021-09-13  1237  {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1238   switch (version) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1239   case 0:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1240           cs_dsp_warn(dsp, 
"Deprecated file format %d\n", version);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1241           return true;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1242   case 1:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1243   case 2:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1244           return true;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1245   default:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1246           return false;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1247   }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1248  }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1249  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1250  static bool 
cs_dsp_halo_validate_version(struct cs_dsp *dsp, unsigned int version)
f6bc909e7673c3 Simon Trimmer 2021-09-13  1251  {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1252   switch (version) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1253   case 3:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1254           return true;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1255   default:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1256           return false;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1257   }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1258  }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1259  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1260  static int cs_dsp_load(struct 
cs_dsp *dsp, const struct firmware *firmware,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1261                  const char *file)
f6bc909e7673c3 Simon Trimmer 2021-09-13  1262  {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1263   LIST_HEAD(buf_list);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1264   struct regmap *regmap = 
dsp->regmap;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1265   unsigned int pos = 0;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1266   const struct wmfw_header 
*header;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1267   const struct wmfw_adsp1_sizes 
*adsp1_sizes;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1268   const struct wmfw_footer 
*footer;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1269   const struct wmfw_region 
*region;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1270   const struct cs_dsp_region *mem;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1271   const char *region_name;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1272   char *text = NULL;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1273   struct cs_dsp_buf *buf;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1274   unsigned int reg;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1275   int regions = 0;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1276   int ret, offset, type;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1277  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1278   ret = -EINVAL;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1279  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1280   pos = sizeof(*header) + 
sizeof(*adsp1_sizes) + sizeof(*footer);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1281   if (pos >= firmware->size) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1282           cs_dsp_err(dsp, "%s: 
file too short, %zu bytes\n",
f6bc909e7673c3 Simon Trimmer 2021-09-13  1283                      file, 
firmware->size);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1284           goto out_fw;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1285   }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1286  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1287   header = (void 
*)&firmware->data[0];
f6bc909e7673c3 Simon Trimmer 2021-09-13  1288  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1289   if (memcmp(&header->magic[0], 
"WMFW", 4) != 0) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1290           cs_dsp_err(dsp, "%s: 
invalid magic\n", file);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1291           goto out_fw;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1292   }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1293  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1294   if 
(!dsp->ops->validate_version(dsp, header->ver)) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1295           cs_dsp_err(dsp, "%s: 
unknown file format %d\n",
f6bc909e7673c3 Simon Trimmer 2021-09-13  1296                      file, 
header->ver);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1297           goto out_fw;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1298   }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1299  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1300   cs_dsp_info(dsp, "Firmware 
version: %d\n", header->ver);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1301   dsp->fw_ver = header->ver;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1302  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1303   if (header->core != dsp->type) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1304           cs_dsp_err(dsp, "%s: 
invalid core %d != %d\n",
f6bc909e7673c3 Simon Trimmer 2021-09-13  1305                      file, 
header->core, dsp->type);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1306           goto out_fw;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1307   }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1308  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1309   pos = sizeof(*header);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1310   pos = 
dsp->ops->parse_sizes(dsp, file, pos, firmware);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1311  
f6bc909e7673c3 Simon Trimmer 2021-09-13 @1312   footer = (void 
*)&firmware->data[pos];
f6bc909e7673c3 Simon Trimmer 2021-09-13  1313   pos += sizeof(*footer);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1314  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1315   if (le32_to_cpu(header->len) != 
pos) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1316           cs_dsp_err(dsp, "%s: 
unexpected header length %d\n",
f6bc909e7673c3 Simon Trimmer 2021-09-13  1317                      file, 
le32_to_cpu(header->len));
f6bc909e7673c3 Simon Trimmer 2021-09-13  1318           goto out_fw;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1319   }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1320  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1321   cs_dsp_dbg(dsp, "%s: timestamp 
%llu\n", file,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1322              
le64_to_cpu(footer->timestamp));
f6bc909e7673c3 Simon Trimmer 2021-09-13  1323  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1324   while (pos < firmware->size &&
f6bc909e7673c3 Simon Trimmer 2021-09-13  1325          sizeof(*region) < 
firmware->size - pos) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1326           region = (void 
*)&(firmware->data[pos]);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1327           region_name = "Unknown";
f6bc909e7673c3 Simon Trimmer 2021-09-13  1328           reg = 0;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1329           text = NULL;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1330           offset = 
le32_to_cpu(region->offset) & 0xffffff;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1331           type = 
be32_to_cpu(region->type) & 0xff;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1332  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1333           switch (type) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1334           case WMFW_NAME_TEXT:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1335                   region_name = 
"Firmware name";
f6bc909e7673c3 Simon Trimmer 2021-09-13  1336                   text = 
kzalloc(le32_to_cpu(region->len) + 1,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1337                                  
GFP_KERNEL);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1338                   break;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1339           case 
WMFW_ALGORITHM_DATA:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1340                   region_name = 
"Algorithm";
f6bc909e7673c3 Simon Trimmer 2021-09-13  1341                   ret = 
cs_dsp_parse_coeff(dsp, region);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1342                   if (ret != 0)
f6bc909e7673c3 Simon Trimmer 2021-09-13  1343                           goto 
out_fw;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1344                   break;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1345           case WMFW_INFO_TEXT:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1346                   region_name = 
"Information";
f6bc909e7673c3 Simon Trimmer 2021-09-13  1347                   text = 
kzalloc(le32_to_cpu(region->len) + 1,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1348                                  
GFP_KERNEL);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1349                   break;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1350           case WMFW_ABSOLUTE:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1351                   region_name = 
"Absolute";
f6bc909e7673c3 Simon Trimmer 2021-09-13  1352                   reg = offset;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1353                   break;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1354           case WMFW_ADSP1_PM:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1355           case WMFW_ADSP1_DM:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1356           case WMFW_ADSP2_XM:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1357           case WMFW_ADSP2_YM:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1358           case WMFW_ADSP1_ZM:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1359           case 
WMFW_HALO_PM_PACKED:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1360           case 
WMFW_HALO_XM_PACKED:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1361           case 
WMFW_HALO_YM_PACKED:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1362                   mem = 
cs_dsp_find_region(dsp, type);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1363                   if (!mem) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1364                           
cs_dsp_err(dsp, "No region of type: %x\n", type);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1365                           ret = 
-EINVAL;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1366                           goto 
out_fw;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1367                   }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1368  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1369                   region_name = 
cs_dsp_mem_region_name(type);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1370                   reg = 
dsp->ops->region_to_reg(mem, offset);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1371                   break;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1372           default:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1373                   cs_dsp_warn(dsp,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1374                               
"%s.%d: Unknown region type %x at %d(%x)\n",
f6bc909e7673c3 Simon Trimmer 2021-09-13  1375                               
file, regions, type, pos, pos);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1376                   break;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1377           }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1378  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1379           cs_dsp_dbg(dsp, "%s.%d: 
%d bytes at %d in %s\n", file,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1380                      regions, 
le32_to_cpu(region->len), offset,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1381                      region_name);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1382  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1383           if 
(le32_to_cpu(region->len) >
f6bc909e7673c3 Simon Trimmer 2021-09-13  1384               firmware->size - 
pos - sizeof(*region)) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1385                   cs_dsp_err(dsp,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1386                              
"%s.%d: %s region len %d bytes exceeds file length %zu\n",
f6bc909e7673c3 Simon Trimmer 2021-09-13  1387                              
file, regions, region_name,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1388                              
le32_to_cpu(region->len), firmware->size);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1389                   ret = -EINVAL;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1390                   goto out_fw;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1391           }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1392  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1393           if (text) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1394                   memcpy(text, 
region->data, le32_to_cpu(region->len));
f6bc909e7673c3 Simon Trimmer 2021-09-13  1395                   
cs_dsp_info(dsp, "%s: %s\n", file, text);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1396                   kfree(text);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1397                   text = NULL;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1398           }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1399  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1400           if (reg) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1401                   buf = 
cs_dsp_buf_alloc(region->data,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1402                                   
       le32_to_cpu(region->len),
f6bc909e7673c3 Simon Trimmer 2021-09-13  1403                                   
       &buf_list);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1404                   if (!buf) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1405                           
cs_dsp_err(dsp, "Out of memory\n");
f6bc909e7673c3 Simon Trimmer 2021-09-13  1406                           ret = 
-ENOMEM;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1407                           goto 
out_fw;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1408                   }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1409  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1410                   ret = 
regmap_raw_write_async(regmap, reg, buf->buf,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1411                                   
             le32_to_cpu(region->len));
f6bc909e7673c3 Simon Trimmer 2021-09-13  1412                   if (ret != 0) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1413                           
cs_dsp_err(dsp,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1414                                   
   "%s.%d: Failed to write %d bytes at %d in %s: %d\n",
f6bc909e7673c3 Simon Trimmer 2021-09-13  1415                                   
   file, regions,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1416                                   
   le32_to_cpu(region->len), offset,
f6bc909e7673c3 Simon Trimmer 2021-09-13  1417                                   
   region_name, ret);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1418                           goto 
out_fw;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1419                   }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1420           }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1421  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1422           pos += 
le32_to_cpu(region->len) + sizeof(*region);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1423           regions++;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1424   }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1425  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1426   ret = 
regmap_async_complete(regmap);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1427   if (ret != 0) {
f6bc909e7673c3 Simon Trimmer 2021-09-13  1428           cs_dsp_err(dsp, "Failed 
to complete async write: %d\n", ret);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1429           goto out_fw;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1430   }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1431  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1432   if (pos > firmware->size)
f6bc909e7673c3 Simon Trimmer 2021-09-13  1433           cs_dsp_warn(dsp, 
"%s.%d: %zu bytes at end of file\n",
f6bc909e7673c3 Simon Trimmer 2021-09-13  1434                       file, 
regions, pos - firmware->size);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1435  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1436   
cs_dsp_debugfs_save_wmfwname(dsp, file);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1437  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1438  out_fw:
f6bc909e7673c3 Simon Trimmer 2021-09-13  1439   regmap_async_complete(regmap);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1440   cs_dsp_buf_free(&buf_list);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1441   kfree(text);
f6bc909e7673c3 Simon Trimmer 2021-09-13  1442  
f6bc909e7673c3 Simon Trimmer 2021-09-13  1443   return ret;
f6bc909e7673c3 Simon Trimmer 2021-09-13  1444  }
f6bc909e7673c3 Simon Trimmer 2021-09-13  1445  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp
_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to