Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ASoc: TAS2781: replace beXX_to_cpup with get_unaligned_beXX for potentially broken alignment

Use get_unaligned_be16 instead of be16_to_cpup and get_unaligned_be32
instead of be32_to_cpup for potentially broken alignment.

Signed-off-by: Shenghao Ding <shenghao-ding@ti.com>
Link: https://patch.msgid.link/20240707083011.98-1-shenghao-ding@ti.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Shenghao Ding and committed by
Mark Brown
1cc509ed ccb367c5

+35 -36
+35 -36
sound/soc/codecs/tas2781-fmwlib.c
··· 21 21 #include <sound/soc.h> 22 22 #include <sound/tlv.h> 23 23 #include <sound/tas2781.h> 24 - 24 + #include <asm/unaligned.h> 25 25 26 26 #define ERROR_PRAM_CRCCHK 0x0000000 27 27 #define ERROR_YRAM_CRCCHK 0x0000001 ··· 187 187 /* convert data[offset], data[offset + 1], data[offset + 2] and 188 188 * data[offset + 3] into host 189 189 */ 190 - cfg_info->nblocks = 191 - be32_to_cpup((__be32 *)&config_data[config_offset]); 190 + cfg_info->nblocks = get_unaligned_be32(&config_data[config_offset]); 192 191 config_offset += 4; 193 192 194 193 /* Several kinds of dsp/algorithm firmwares can run on tas2781, ··· 231 232 232 233 } 233 234 bk_da[i]->yram_checksum = 234 - be16_to_cpup((__be16 *)&config_data[config_offset]); 235 + get_unaligned_be16(&config_data[config_offset]); 235 236 config_offset += 2; 236 237 bk_da[i]->block_size = 237 - be32_to_cpup((__be32 *)&config_data[config_offset]); 238 + get_unaligned_be32(&config_data[config_offset]); 238 239 config_offset += 4; 239 240 240 241 bk_da[i]->n_subblks = 241 - be32_to_cpup((__be32 *)&config_data[config_offset]); 242 + get_unaligned_be32(&config_data[config_offset]); 242 243 243 244 config_offset += 4; 244 245 ··· 288 289 } 289 290 buf = (unsigned char *)fmw->data; 290 291 291 - fw_hdr->img_sz = be32_to_cpup((__be32 *)&buf[offset]); 292 + fw_hdr->img_sz = get_unaligned_be32(&buf[offset]); 292 293 offset += 4; 293 294 if (fw_hdr->img_sz != fmw->size) { 294 295 dev_err(tas_priv->dev, ··· 299 300 goto out; 300 301 } 301 302 302 - fw_hdr->checksum = be32_to_cpup((__be32 *)&buf[offset]); 303 + fw_hdr->checksum = get_unaligned_be32(&buf[offset]); 303 304 offset += 4; 304 - fw_hdr->binary_version_num = be32_to_cpup((__be32 *)&buf[offset]); 305 + fw_hdr->binary_version_num = get_unaligned_be32(&buf[offset]); 305 306 if (fw_hdr->binary_version_num < 0x103) { 306 307 dev_err(tas_priv->dev, "File version 0x%04x is too low", 307 308 fw_hdr->binary_version_num); ··· 310 311 goto out; 311 312 } 312 313 offset += 4; 313 - fw_hdr->drv_fw_version = be32_to_cpup((__be32 *)&buf[offset]); 314 + fw_hdr->drv_fw_version = get_unaligned_be32(&buf[offset]); 314 315 offset += 8; 315 316 fw_hdr->plat_type = buf[offset]; 316 317 offset += 1; ··· 338 339 for (i = 0; i < TASDEVICE_DEVICE_SUM; i++, offset++) 339 340 fw_hdr->devs[i] = buf[offset]; 340 341 341 - fw_hdr->nconfig = be32_to_cpup((__be32 *)&buf[offset]); 342 + fw_hdr->nconfig = get_unaligned_be32(&buf[offset]); 342 343 offset += 4; 343 344 344 345 for (i = 0; i < TASDEVICE_CONFIG_SUM; i++) { 345 - fw_hdr->config_size[i] = be32_to_cpup((__be32 *)&buf[offset]); 346 + fw_hdr->config_size[i] = get_unaligned_be32(&buf[offset]); 346 347 offset += 4; 347 348 total_config_sz += fw_hdr->config_size[i]; 348 349 } ··· 422 423 /* convert data[offset], data[offset + 1], data[offset + 2] and 423 424 * data[offset + 3] into host 424 425 */ 425 - block->type = be32_to_cpup((__be32 *)&data[offset]); 426 + block->type = get_unaligned_be32(&data[offset]); 426 427 offset += 4; 427 428 428 429 block->is_pchksum_present = data[offset]; ··· 437 438 block->ychksum = data[offset]; 438 439 offset++; 439 440 440 - block->blk_size = be32_to_cpup((__be32 *)&data[offset]); 441 + block->blk_size = get_unaligned_be32(&data[offset]); 441 442 offset += 4; 442 443 443 - block->nr_subblocks = be32_to_cpup((__be32 *)&data[offset]); 444 + block->nr_subblocks = get_unaligned_be32(&data[offset]); 444 445 offset += 4; 445 446 446 447 /* fixed m68k compiling issue: ··· 481 482 offset = -EINVAL; 482 483 goto out; 483 484 } 484 - img_data->nr_blk = be32_to_cpup((__be32 *)&data[offset]); 485 + img_data->nr_blk = get_unaligned_be32(&data[offset]); 485 486 offset += 4; 486 487 487 488 img_data->dev_blks = kcalloc(img_data->nr_blk, ··· 577 578 offset = -EINVAL; 578 579 goto out; 579 580 } 580 - fw_hdr->device_family = be16_to_cpup((__be16 *)&buf[offset]); 581 + fw_hdr->device_family = get_unaligned_be16(&buf[offset]); 581 582 if (fw_hdr->device_family != 0) { 582 583 dev_err(tas_priv->dev, "%s:not TAS device\n", __func__); 583 584 offset = -EINVAL; 584 585 goto out; 585 586 } 586 587 offset += 2; 587 - fw_hdr->device = be16_to_cpup((__be16 *)&buf[offset]); 588 + fw_hdr->device = get_unaligned_be16(&buf[offset]); 588 589 if (fw_hdr->device >= TASDEVICE_DSP_TAS_MAX_DEVICE || 589 590 fw_hdr->device == 6) { 590 591 dev_err(tas_priv->dev, "Unsupported dev %d\n", fw_hdr->device); ··· 602 603 goto out; 603 604 } 604 605 605 - tas_fmw->nr_programs = be32_to_cpup((__be32 *)&buf[offset]); 606 + tas_fmw->nr_programs = get_unaligned_be32(&buf[offset]); 606 607 offset += 4; 607 608 608 609 if (tas_fmw->nr_programs == 0 || tas_fmw->nr_programs > ··· 621 622 622 623 for (i = 0; i < tas_fmw->nr_programs; i++) { 623 624 program = &(tas_fmw->programs[i]); 624 - program->prog_size = be32_to_cpup((__be32 *)&buf[offset]); 625 + program->prog_size = get_unaligned_be32(&buf[offset]); 625 626 offset += 4; 626 627 } 627 628 628 629 /* Skip the unused prog_size */ 629 630 offset += 4 * (TASDEVICE_MAXPROGRAM_NUM_KERNEL - tas_fmw->nr_programs); 630 631 631 - tas_fmw->nr_configurations = be32_to_cpup((__be32 *)&buf[offset]); 632 + tas_fmw->nr_configurations = get_unaligned_be32(&buf[offset]); 632 633 offset += 4; 633 634 634 635 /* The max number of config in firmware greater than 4 pieces of ··· 660 661 661 662 for (i = 0; i < tas_fmw->nr_programs; i++) { 662 663 config = &(tas_fmw->configs[i]); 663 - config->cfg_size = be32_to_cpup((__be32 *)&buf[offset]); 664 + config->cfg_size = get_unaligned_be32(&buf[offset]); 664 665 offset += 4; 665 666 } 666 667 ··· 698 699 switch (subblk_typ) { 699 700 case TASDEVICE_CMD_SING_W: { 700 701 int i; 701 - unsigned short len = be16_to_cpup((__be16 *)&data[2]); 702 + unsigned short len = get_unaligned_be16(&data[2]); 702 703 703 704 subblk_offset += 2; 704 705 if (subblk_offset + 4 * len > sublocksize) { ··· 724 725 } 725 726 break; 726 727 case TASDEVICE_CMD_BURST: { 727 - unsigned short len = be16_to_cpup((__be16 *)&data[2]); 728 + unsigned short len = get_unaligned_be16(&data[2]); 728 729 729 730 subblk_offset += 2; 730 731 if (subblk_offset + 4 + len > sublocksize) { ··· 765 766 is_err = true; 766 767 break; 767 768 } 768 - sleep_time = be16_to_cpup((__be16 *)&data[2]) * 1000; 769 + sleep_time = get_unaligned_be16(&data[2]) * 1000; 769 770 usleep_range(sleep_time, sleep_time + 50); 770 771 subblk_offset += 2; 771 772 } ··· 909 910 910 911 offset += len; 911 912 912 - fw_hdr->device_family = be32_to_cpup((__be32 *)&buf[offset]); 913 + fw_hdr->device_family = get_unaligned_be32(&buf[offset]); 913 914 if (fw_hdr->device_family != 0) { 914 915 dev_err(tas_priv->dev, "%s: not TAS device\n", __func__); 915 916 offset = -EINVAL; ··· 917 918 } 918 919 offset += 4; 919 920 920 - fw_hdr->device = be32_to_cpup((__be32 *)&buf[offset]); 921 + fw_hdr->device = get_unaligned_be32(&buf[offset]); 921 922 if (fw_hdr->device >= TASDEVICE_DSP_TAS_MAX_DEVICE || 922 923 fw_hdr->device == 6) { 923 924 dev_err(tas_priv->dev, "Unsupported dev %d\n", fw_hdr->device); ··· 962 963 offset = -EINVAL; 963 964 goto out; 964 965 } 965 - block->type = be32_to_cpup((__be32 *)&data[offset]); 966 + block->type = get_unaligned_be32(&data[offset]); 966 967 offset += 4; 967 968 968 969 if (tas_fmw->fw_hdr.fixed_hdr.drv_ver >= PPC_DRIVER_CRCCHK) { ··· 987 988 block->is_ychksum_present = 0; 988 989 } 989 990 990 - block->nr_cmds = be32_to_cpup((__be32 *)&data[offset]); 991 + block->nr_cmds = get_unaligned_be32(&data[offset]); 991 992 offset += 4; 992 993 993 994 n = block->nr_cmds * 4; ··· 1038 1039 goto out; 1039 1040 } 1040 1041 offset += n; 1041 - img_data->nr_blk = be16_to_cpup((__be16 *)&data[offset]); 1042 + img_data->nr_blk = get_unaligned_be16(&data[offset]); 1042 1043 offset += 2; 1043 1044 1044 1045 img_data->dev_blks = kcalloc(img_data->nr_blk, ··· 1075 1076 offset = -EINVAL; 1076 1077 goto out; 1077 1078 } 1078 - tas_fmw->nr_programs = be16_to_cpup((__be16 *)&buf[offset]); 1079 + tas_fmw->nr_programs = get_unaligned_be16(&buf[offset]); 1079 1080 offset += 2; 1080 1081 1081 1082 if (tas_fmw->nr_programs == 0) { ··· 1142 1143 offset = -EINVAL; 1143 1144 goto out; 1144 1145 } 1145 - tas_fmw->nr_configurations = be16_to_cpup((__be16 *)&data[offset]); 1146 + tas_fmw->nr_configurations = get_unaligned_be16(&data[offset]); 1146 1147 offset += 2; 1147 1148 1148 1149 if (tas_fmw->nr_configurations == 0) { ··· 1774 1775 /* Convert data[offset], data[offset + 1], data[offset + 2] and 1775 1776 * data[offset + 3] into host 1776 1777 */ 1777 - fw_fixed_hdr->fwsize = be32_to_cpup((__be32 *)&buf[offset]); 1778 + fw_fixed_hdr->fwsize = get_unaligned_be32(&buf[offset]); 1778 1779 offset += 4; 1779 1780 if (fw_fixed_hdr->fwsize != fmw->size) { 1780 1781 dev_err(tas_priv->dev, "File size not match, %lu %u", ··· 1783 1784 goto out; 1784 1785 } 1785 1786 offset += 4; 1786 - fw_fixed_hdr->ppcver = be32_to_cpup((__be32 *)&buf[offset]); 1787 + fw_fixed_hdr->ppcver = get_unaligned_be32(&buf[offset]); 1787 1788 offset += 8; 1788 - fw_fixed_hdr->drv_ver = be32_to_cpup((__be32 *)&buf[offset]); 1789 + fw_fixed_hdr->drv_ver = get_unaligned_be32(&buf[offset]); 1789 1790 offset += 72; 1790 1791 1791 1792 out: ··· 1827 1828 offset = -EINVAL; 1828 1829 goto out; 1829 1830 } 1830 - tas_fmw->nr_calibrations = be16_to_cpup((__be16 *)&data[offset]); 1831 + tas_fmw->nr_calibrations = get_unaligned_be16(&data[offset]); 1831 1832 offset += 2; 1832 1833 1833 1834 if (tas_fmw->nr_calibrations != 1) {