ASoC: nau8810: Fix incorrect type in assignment and cast to restricted __be16
authorDavid Lin <CTLIN0@nuvoton.com>
Mon, 20 Nov 2023 08:42:28 +0000 (16:42 +0800)
committerMark Brown <broonie@kernel.org>
Mon, 20 Nov 2023 17:19:08 +0000 (17:19 +0000)
This issue is reproduced when W=1 build in compiler gcc-12.
The following are sparse warnings:

sound/soc/codecs/nau8810.c:183:25: sparse: warning: incorrect type in assignment
sound/soc/codecs/nau8810.c:183:25: sparse: expected int
sound/soc/codecs/nau8810.c:183:25: sparse: got restricted __be16
sound/soc/codecs/nau8810.c:219:25: sparse: warning: cast to restricted __be16
sound/soc/codecs/nau8810.c:219:25: sparse: warning: cast to restricted __be16
sound/soc/codecs/nau8810.c:219:25: sparse: warning: cast to restricted __be16
sound/soc/codecs/nau8810.c:219:25: sparse: warning: cast to restricted __be16

This issue is not still actively checked by kernel test robot.
Actually, it is same with nau8822's sparse warnings issue.

Signed-off-by: David Lin <CTLIN0@nuvoton.com>
Link: https://lore.kernel.org/r/20231120084227.1766633-1-CTLIN0@nuvoton.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/nau8810.c

index 47f000cd4d9971ce8d1a15ead88e23bc8b7b35ad..97a54059474c6677cedd12a855fd4a295956383c 100644 (file)
@@ -169,6 +169,7 @@ static int nau8810_eq_get(struct snd_kcontrol *kcontrol,
        struct soc_bytes_ext *params = (void *)kcontrol->private_value;
        int i, reg, reg_val;
        u16 *val;
+       __be16 tmp;
 
        val = (u16 *)ucontrol->value.bytes.data;
        reg = NAU8810_REG_EQ1;
@@ -177,8 +178,8 @@ static int nau8810_eq_get(struct snd_kcontrol *kcontrol,
                /* conversion of 16-bit integers between native CPU format
                 * and big endian format
                 */
-               reg_val = cpu_to_be16(reg_val);
-               memcpy(val + i, &reg_val, sizeof(reg_val));
+               tmp = cpu_to_be16(reg_val);
+               memcpy(val + i, &tmp, sizeof(tmp));
        }
 
        return 0;
@@ -201,6 +202,7 @@ static int nau8810_eq_put(struct snd_kcontrol *kcontrol,
        void *data;
        u16 *val, value;
        int i, reg, ret;
+       __be16 *tmp;
 
        data = kmemdup(ucontrol->value.bytes.data,
                params->max, GFP_KERNEL | GFP_DMA);
@@ -213,7 +215,8 @@ static int nau8810_eq_put(struct snd_kcontrol *kcontrol,
                /* conversion of 16-bit integers between native CPU format
                 * and big endian format
                 */
-               value = be16_to_cpu(*(val + i));
+               tmp = (__be16 *)(val + i);
+               value = be16_to_cpup(tmp);
                ret = regmap_write(nau8810->regmap, reg + i, value);
                if (ret) {
                        dev_err(component->dev, "EQ configuration fail, register: %x ret: %d\n",