From nobody Sun Feb 8 05:37:35 2026 Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE22C5227 for ; Sun, 7 Jul 2024 08:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720341269; cv=none; b=Pc23Y9Wlhf6KCFqtEMn7LKfprVjGeUxAAqKJQ2p4VmOYSvgaYehNAfE2Q1YW4oDTuer5plm5vj3EAa0lvJpF1aPY5AtzbSGCV7OhSngzCz+ioC7dXVnz964iT4BFGySH+KQUHq6Js5Ojk8EOwLyrAmIgAeh0bF6HGaQbt6z7l9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720341269; c=relaxed/simple; bh=YhFbHainyYeyciT6pc1KvK3diNomH6u/4XzJ0ctmYLM=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=aF7oO5rhhUZU3fOIfgodI124Wyhs/7UQPAoPc6LmD+iLU6i8x6IbbBkNqWzB8ukPuds/thC9cPMZjvdXQ3wmr+Yze3gIRl8rnBwI2FDUnIdC6J9jkpabS1Dmj5+wl4jWDT7QtHpXDvxodm3dt0hphZzXHr+l+1hvkztdaFkKh8Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=BUEdqSZX; arc=none smtp.client-ip=198.47.19.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="BUEdqSZX" Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 4678UOcB006842; Sun, 7 Jul 2024 03:30:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1720341024; bh=yLpZSA+/kNe6Eaz8hHjEs6HoSIzToxZRAf/a0PLG8MM=; h=From:To:CC:Subject:Date; b=BUEdqSZXd5yMVxpXRjrHvbi8NWNJZ+8b8ld4k+kpTqag/wh/HnZN/pzAXC+ZVNbKa b1ZaWDUo8J9+E9AdTbNZP8WeDjFbwu69N8RihKITc4z+rs3UfCodDykMOdNjutEzG4 0ix4MaW6u9hAHDXmqu7pBTST5HClnbAyERo6FCUM= Received: from DFLE100.ent.ti.com (dfle100.ent.ti.com [10.64.6.21]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 4678UOdS121327 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Sun, 7 Jul 2024 03:30:24 -0500 Received: from DFLE111.ent.ti.com (10.64.6.32) by DFLE100.ent.ti.com (10.64.6.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Sun, 7 Jul 2024 03:30:24 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DFLE111.ent.ti.com (10.64.6.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Sun, 7 Jul 2024 03:30:24 -0500 Received: from LT5CG31242FY.dhcp.ti.com ([10.250.160.158]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 4678UERh011105; Sun, 7 Jul 2024 03:30:15 -0500 From: Shenghao Ding To: CC: , , , , <13916275206@139.com>, , , , , , , , , , , , , , , , , , , , , , , , , Shenghao Ding Subject: [PATCH v1] ASoc: TAS2781: replace beXX_to_cpup with get_unaligned_beXX for potentially broken alignment Date: Sun, 7 Jul 2024 16:30:07 +0800 Message-ID: <20240707083011.98-1-shenghao-ding@ti.com> X-Mailer: git-send-email 2.33.0.windows.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Content-Type: text/plain; charset="utf-8" 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 --- v1: - Add "#include " for the declaration of get_unaligned_beXX --- sound/soc/codecs/tas2781-fmwlib.c | 71 +++++++++++++++---------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/sound/soc/codecs/tas2781-fmwlib.c b/sound/soc/codecs/tas2781-f= mwlib.c index 838d29fead96..63626b982d04 100644 --- a/sound/soc/codecs/tas2781-fmwlib.c +++ b/sound/soc/codecs/tas2781-fmwlib.c @@ -21,7 +21,7 @@ #include #include #include - +#include =20 #define ERROR_PRAM_CRCCHK 0x0000000 #define ERROR_YRAM_CRCCHK 0x0000001 @@ -187,8 +187,7 @@ static struct tasdevice_config_info *tasdevice_add_conf= ig( /* convert data[offset], data[offset + 1], data[offset + 2] and * data[offset + 3] into host */ - cfg_info->nblocks =3D - be32_to_cpup((__be32 *)&config_data[config_offset]); + cfg_info->nblocks =3D get_unaligned_be32(&config_data[config_offset]); config_offset +=3D 4; =20 /* Several kinds of dsp/algorithm firmwares can run on tas2781, @@ -232,14 +231,14 @@ static struct tasdevice_config_info *tasdevice_add_co= nfig( =20 } bk_da[i]->yram_checksum =3D - be16_to_cpup((__be16 *)&config_data[config_offset]); + get_unaligned_be16(&config_data[config_offset]); config_offset +=3D 2; bk_da[i]->block_size =3D - be32_to_cpup((__be32 *)&config_data[config_offset]); + get_unaligned_be32(&config_data[config_offset]); config_offset +=3D 4; =20 bk_da[i]->n_subblks =3D - be32_to_cpup((__be32 *)&config_data[config_offset]); + get_unaligned_be32(&config_data[config_offset]); =20 config_offset +=3D 4; =20 @@ -289,7 +288,7 @@ int tasdevice_rca_parser(void *context, const struct fi= rmware *fmw) } buf =3D (unsigned char *)fmw->data; =20 - fw_hdr->img_sz =3D be32_to_cpup((__be32 *)&buf[offset]); + fw_hdr->img_sz =3D get_unaligned_be32(&buf[offset]); offset +=3D 4; if (fw_hdr->img_sz !=3D fmw->size) { dev_err(tas_priv->dev, @@ -300,9 +299,9 @@ int tasdevice_rca_parser(void *context, const struct fi= rmware *fmw) goto out; } =20 - fw_hdr->checksum =3D be32_to_cpup((__be32 *)&buf[offset]); + fw_hdr->checksum =3D get_unaligned_be32(&buf[offset]); offset +=3D 4; - fw_hdr->binary_version_num =3D be32_to_cpup((__be32 *)&buf[offset]); + fw_hdr->binary_version_num =3D get_unaligned_be32(&buf[offset]); if (fw_hdr->binary_version_num < 0x103) { dev_err(tas_priv->dev, "File version 0x%04x is too low", fw_hdr->binary_version_num); @@ -311,7 +310,7 @@ int tasdevice_rca_parser(void *context, const struct fi= rmware *fmw) goto out; } offset +=3D 4; - fw_hdr->drv_fw_version =3D be32_to_cpup((__be32 *)&buf[offset]); + fw_hdr->drv_fw_version =3D get_unaligned_be32(&buf[offset]); offset +=3D 8; fw_hdr->plat_type =3D buf[offset]; offset +=3D 1; @@ -339,11 +338,11 @@ int tasdevice_rca_parser(void *context, const struct = firmware *fmw) for (i =3D 0; i < TASDEVICE_DEVICE_SUM; i++, offset++) fw_hdr->devs[i] =3D buf[offset]; =20 - fw_hdr->nconfig =3D be32_to_cpup((__be32 *)&buf[offset]); + fw_hdr->nconfig =3D get_unaligned_be32(&buf[offset]); offset +=3D 4; =20 for (i =3D 0; i < TASDEVICE_CONFIG_SUM; i++) { - fw_hdr->config_size[i] =3D be32_to_cpup((__be32 *)&buf[offset]); + fw_hdr->config_size[i] =3D get_unaligned_be32(&buf[offset]); offset +=3D 4; total_config_sz +=3D fw_hdr->config_size[i]; } @@ -423,7 +422,7 @@ static int fw_parse_block_data_kernel(struct tasdevice_= fw *tas_fmw, /* convert data[offset], data[offset + 1], data[offset + 2] and * data[offset + 3] into host */ - block->type =3D be32_to_cpup((__be32 *)&data[offset]); + block->type =3D get_unaligned_be32(&data[offset]); offset +=3D 4; =20 block->is_pchksum_present =3D data[offset]; @@ -438,10 +437,10 @@ static int fw_parse_block_data_kernel(struct tasdevic= e_fw *tas_fmw, block->ychksum =3D data[offset]; offset++; =20 - block->blk_size =3D be32_to_cpup((__be32 *)&data[offset]); + block->blk_size =3D get_unaligned_be32(&data[offset]); offset +=3D 4; =20 - block->nr_subblocks =3D be32_to_cpup((__be32 *)&data[offset]); + block->nr_subblocks =3D get_unaligned_be32(&data[offset]); offset +=3D 4; =20 /* fixed m68k compiling issue: @@ -482,7 +481,7 @@ static int fw_parse_data_kernel(struct tasdevice_fw *ta= s_fmw, offset =3D -EINVAL; goto out; } - img_data->nr_blk =3D be32_to_cpup((__be32 *)&data[offset]); + img_data->nr_blk =3D get_unaligned_be32(&data[offset]); offset +=3D 4; =20 img_data->dev_blks =3D kcalloc(img_data->nr_blk, @@ -578,14 +577,14 @@ static int fw_parse_variable_header_kernel( offset =3D -EINVAL; goto out; } - fw_hdr->device_family =3D be16_to_cpup((__be16 *)&buf[offset]); + fw_hdr->device_family =3D get_unaligned_be16(&buf[offset]); if (fw_hdr->device_family !=3D 0) { dev_err(tas_priv->dev, "%s:not TAS device\n", __func__); offset =3D -EINVAL; goto out; } offset +=3D 2; - fw_hdr->device =3D be16_to_cpup((__be16 *)&buf[offset]); + fw_hdr->device =3D get_unaligned_be16(&buf[offset]); if (fw_hdr->device >=3D TASDEVICE_DSP_TAS_MAX_DEVICE || fw_hdr->device =3D=3D 6) { dev_err(tas_priv->dev, "Unsupported dev %d\n", fw_hdr->device); @@ -603,7 +602,7 @@ static int fw_parse_variable_header_kernel( goto out; } =20 - tas_fmw->nr_programs =3D be32_to_cpup((__be32 *)&buf[offset]); + tas_fmw->nr_programs =3D get_unaligned_be32(&buf[offset]); offset +=3D 4; =20 if (tas_fmw->nr_programs =3D=3D 0 || tas_fmw->nr_programs > @@ -622,14 +621,14 @@ static int fw_parse_variable_header_kernel( =20 for (i =3D 0; i < tas_fmw->nr_programs; i++) { program =3D &(tas_fmw->programs[i]); - program->prog_size =3D be32_to_cpup((__be32 *)&buf[offset]); + program->prog_size =3D get_unaligned_be32(&buf[offset]); offset +=3D 4; } =20 /* Skip the unused prog_size */ offset +=3D 4 * (TASDEVICE_MAXPROGRAM_NUM_KERNEL - tas_fmw->nr_programs); =20 - tas_fmw->nr_configurations =3D be32_to_cpup((__be32 *)&buf[offset]); + tas_fmw->nr_configurations =3D get_unaligned_be32(&buf[offset]); offset +=3D 4; =20 /* The max number of config in firmware greater than 4 pieces of @@ -661,7 +660,7 @@ static int fw_parse_variable_header_kernel( =20 for (i =3D 0; i < tas_fmw->nr_programs; i++) { config =3D &(tas_fmw->configs[i]); - config->cfg_size =3D be32_to_cpup((__be32 *)&buf[offset]); + config->cfg_size =3D get_unaligned_be32(&buf[offset]); offset +=3D 4; } =20 @@ -699,7 +698,7 @@ static int tasdevice_process_block(void *context, unsig= ned char *data, switch (subblk_typ) { case TASDEVICE_CMD_SING_W: { int i; - unsigned short len =3D be16_to_cpup((__be16 *)&data[2]); + unsigned short len =3D get_unaligned_be16(&data[2]); =20 subblk_offset +=3D 2; if (subblk_offset + 4 * len > sublocksize) { @@ -725,7 +724,7 @@ static int tasdevice_process_block(void *context, unsig= ned char *data, } break; case TASDEVICE_CMD_BURST: { - unsigned short len =3D be16_to_cpup((__be16 *)&data[2]); + unsigned short len =3D get_unaligned_be16(&data[2]); =20 subblk_offset +=3D 2; if (subblk_offset + 4 + len > sublocksize) { @@ -766,7 +765,7 @@ static int tasdevice_process_block(void *context, unsig= ned char *data, is_err =3D true; break; } - sleep_time =3D be16_to_cpup((__be16 *)&data[2]) * 1000; + sleep_time =3D get_unaligned_be16(&data[2]) * 1000; usleep_range(sleep_time, sleep_time + 50); subblk_offset +=3D 2; } @@ -910,7 +909,7 @@ static int fw_parse_variable_hdr(struct tasdevice_priv =20 offset +=3D len; =20 - fw_hdr->device_family =3D be32_to_cpup((__be32 *)&buf[offset]); + fw_hdr->device_family =3D get_unaligned_be32(&buf[offset]); if (fw_hdr->device_family !=3D 0) { dev_err(tas_priv->dev, "%s: not TAS device\n", __func__); offset =3D -EINVAL; @@ -918,7 +917,7 @@ static int fw_parse_variable_hdr(struct tasdevice_priv } offset +=3D 4; =20 - fw_hdr->device =3D be32_to_cpup((__be32 *)&buf[offset]); + fw_hdr->device =3D get_unaligned_be32(&buf[offset]); if (fw_hdr->device >=3D TASDEVICE_DSP_TAS_MAX_DEVICE || fw_hdr->device =3D=3D 6) { dev_err(tas_priv->dev, "Unsupported dev %d\n", fw_hdr->device); @@ -963,7 +962,7 @@ static int fw_parse_block_data(struct tasdevice_fw *tas= _fmw, offset =3D -EINVAL; goto out; } - block->type =3D be32_to_cpup((__be32 *)&data[offset]); + block->type =3D get_unaligned_be32(&data[offset]); offset +=3D 4; =20 if (tas_fmw->fw_hdr.fixed_hdr.drv_ver >=3D PPC_DRIVER_CRCCHK) { @@ -988,7 +987,7 @@ static int fw_parse_block_data(struct tasdevice_fw *tas= _fmw, block->is_ychksum_present =3D 0; } =20 - block->nr_cmds =3D be32_to_cpup((__be32 *)&data[offset]); + block->nr_cmds =3D get_unaligned_be32(&data[offset]); offset +=3D 4; =20 n =3D block->nr_cmds * 4; @@ -1039,7 +1038,7 @@ static int fw_parse_data(struct tasdevice_fw *tas_fmw, goto out; } offset +=3D n; - img_data->nr_blk =3D be16_to_cpup((__be16 *)&data[offset]); + img_data->nr_blk =3D get_unaligned_be16(&data[offset]); offset +=3D 2; =20 img_data->dev_blks =3D kcalloc(img_data->nr_blk, @@ -1076,7 +1075,7 @@ static int fw_parse_program_data(struct tasdevice_pri= v *tas_priv, offset =3D -EINVAL; goto out; } - tas_fmw->nr_programs =3D be16_to_cpup((__be16 *)&buf[offset]); + tas_fmw->nr_programs =3D get_unaligned_be16(&buf[offset]); offset +=3D 2; =20 if (tas_fmw->nr_programs =3D=3D 0) { @@ -1143,7 +1142,7 @@ static int fw_parse_configuration_data( offset =3D -EINVAL; goto out; } - tas_fmw->nr_configurations =3D be16_to_cpup((__be16 *)&data[offset]); + tas_fmw->nr_configurations =3D get_unaligned_be16(&data[offset]); offset +=3D 2; =20 if (tas_fmw->nr_configurations =3D=3D 0) { @@ -1775,7 +1774,7 @@ static int fw_parse_header(struct tasdevice_priv *tas= _priv, /* Convert data[offset], data[offset + 1], data[offset + 2] and * data[offset + 3] into host */ - fw_fixed_hdr->fwsize =3D be32_to_cpup((__be32 *)&buf[offset]); + fw_fixed_hdr->fwsize =3D get_unaligned_be32(&buf[offset]); offset +=3D 4; if (fw_fixed_hdr->fwsize !=3D fmw->size) { dev_err(tas_priv->dev, "File size not match, %lu %u", @@ -1784,9 +1783,9 @@ static int fw_parse_header(struct tasdevice_priv *tas= _priv, goto out; } offset +=3D 4; - fw_fixed_hdr->ppcver =3D be32_to_cpup((__be32 *)&buf[offset]); + fw_fixed_hdr->ppcver =3D get_unaligned_be32(&buf[offset]); offset +=3D 8; - fw_fixed_hdr->drv_ver =3D be32_to_cpup((__be32 *)&buf[offset]); + fw_fixed_hdr->drv_ver =3D get_unaligned_be32(&buf[offset]); offset +=3D 72; =20 out: @@ -1828,7 +1827,7 @@ static int fw_parse_calibration_data(struct tasdevice= _priv *tas_priv, offset =3D -EINVAL; goto out; } - tas_fmw->nr_calibrations =3D be16_to_cpup((__be16 *)&data[offset]); + tas_fmw->nr_calibrations =3D get_unaligned_be16(&data[offset]); offset +=3D 2; =20 if (tas_fmw->nr_calibrations !=3D 1) { --=20 2.34.1