CC: [email protected]
CC: [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:   23a46422c56144939c091c76cf389aa863ce9c18
commit: f6bc909e7673c30abcbdb329e7d0aa2e83c103d7 firmware: cs_dsp: add driver 
to support firmware loading on Cirrus Logic DSPs
date:   4 months ago
:::::: branch date: 7 hours ago
:::::: commit date: 4 months ago
config: arm-randconfig-c002-20220123 
(https://download.01.org/0day-ci/archive/20220128/[email protected]/config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 
7b3d30728816403d1fd73cc5082e9fb761262bce)
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 arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # 
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=arm 
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 >>)
               ^~~~~~~~~
   drivers/media/i2c/tvp7002.c:627:2: note: Taking false branch
           if (error < 0)
           ^
   drivers/media/i2c/tvp7002.c:633:6: note: 'error' is >= 0
           if (error < 0)
               ^~~~~
   drivers/media/i2c/tvp7002.c:633:2: note: Taking false branch
           if (error < 0)
           ^
   drivers/media/i2c/tvp7002.c:637:37: note: The right operand of '&' is a 
garbage value
           lpfr = lpf_lsb | ((TVP7002_CL_MASK & lpf_msb) << TVP7002_CL_SHIFT);
                                              ^ ~~~~~~~
   drivers/media/i2c/tvp7002.c:638:37: warning: The right operand of '&' is a 
garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult]
           cpln = cpl_lsb | ((TVP7002_CL_MASK & cpl_msb) << TVP7002_CL_SHIFT);
                                              ^
   drivers/media/i2c/tvp7002.c:753:2: note: Calling 'tvp7002_query_dv'
           tvp7002_query_dv(sd, &detected);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/media/i2c/tvp7002.c:618:2: note: 'cpl_msb' declared without an 
initial value
           u8 cpl_msb;
           ^~~~~~~~~~
   drivers/media/i2c/tvp7002.c:627:6: note: Assuming 'error' is >= 0
           if (error < 0)
               ^~~~~~~~~
   drivers/media/i2c/tvp7002.c:627:2: note: Taking false branch
           if (error < 0)
           ^
   drivers/media/i2c/tvp7002.c:631:2: note: Calling 'tvp7002_read_err'
           tvp7002_read_err(sd, TVP7002_CLK_L_STAT_MSBS, &cpl_msb, &error);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/media/i2c/tvp7002.c:475:2: note: Taking false branch
           if (!*err)
           ^
   drivers/media/i2c/tvp7002.c:477:1: note: Returning without writing to '*dst'
   }
   ^
   drivers/media/i2c/tvp7002.c:631:2: note: Returning from 'tvp7002_read_err'
           tvp7002_read_err(sd, TVP7002_CLK_L_STAT_MSBS, &cpl_msb, &error);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/media/i2c/tvp7002.c:633:6: note: 'error' is >= 0
           if (error < 0)
               ^~~~~
   drivers/media/i2c/tvp7002.c:633:2: note: Taking false branch
           if (error < 0)
           ^
   drivers/media/i2c/tvp7002.c:638:37: note: The right operand of '&' is a 
garbage value
           cpln = cpl_lsb | ((TVP7002_CL_MASK & cpl_msb) << TVP7002_CL_SHIFT);
                                              ^ ~~~~~~~
   drivers/media/i2c/tvp7002.c:1004:2: warning: Value stored to 'error' is 
never read [clang-analyzer-deadcode.DeadStores]
           error = tvp7002_s_dv_timings(sd, &timings);
           ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/media/i2c/tvp7002.c:1004:2: note: Value stored to 'error' is never 
read
           error = tvp7002_s_dv_timings(sd, &timings);
           ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Suppressed 10 warnings (9 in non-user code, 1 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use 
-system-headers to display errors from system headers as well.
   8 warnings generated.
   Suppressed 8 warnings (8 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.
   8 warnings generated.
   Suppressed 8 warnings (8 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.
   8 warnings generated.
   Suppressed 8 warnings (8 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.
   8 warnings generated.
   Suppressed 8 warnings (8 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.
   3 warnings generated.
   Suppressed 3 warnings (3 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.
   3 warnings generated.
   Suppressed 3 warnings (3 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.
   3 warnings generated.
   Suppressed 3 warnings (3 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.
   3 warnings generated.
   Suppressed 3 warnings (3 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.
   3 warnings generated.
   Suppressed 3 warnings (3 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.
   3 warnings generated.
   Suppressed 3 warnings (3 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.
   3 warnings generated.
   Suppressed 3 warnings (3 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.
   3 warnings generated.
   Suppressed 3 warnings (3 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.
   3 warnings generated.
   Suppressed 3 warnings (3 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.
   3 warnings generated.
   Suppressed 3 warnings (3 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.
   8 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

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

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

Reply via email to