2022-07-19 09:51:55

by Shengjiu Wang

[permalink] [raw]
Subject: [PATCH -next 2/5] ASoC: fsl_asrc: force cast the asrc_format type

Fix sparse warning:
sound/soc/fsl/fsl_asrc.c:1177:60: sparse: warning: incorrect type in argument 3 (different base types)
sound/soc/fsl/fsl_asrc.c:1177:60: sparse: expected unsigned int [usertype] *out_value
sound/soc/fsl/fsl_asrc.c:1177:60: sparse: got restricted snd_pcm_format_t *
sound/soc/fsl/fsl_asrc.c:1200:47: sparse: warning: restricted snd_pcm_format_t degrades to integer

Fixes: 4520af41fd21 ("ASoC: fsl_asrc: Support new property fsl,asrc-format")
Signed-off-by: Shengjiu Wang <[email protected]>
---
sound/soc/fsl/fsl_asrc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c
index 20a9f8e924b3..544395efd605 100644
--- a/sound/soc/fsl/fsl_asrc.c
+++ b/sound/soc/fsl/fsl_asrc.c
@@ -1174,7 +1174,7 @@ static int fsl_asrc_probe(struct platform_device *pdev)
return ret;
}

- ret = of_property_read_u32(np, "fsl,asrc-format", &asrc->asrc_format);
+ ret = of_property_read_u32(np, "fsl,asrc-format", (u32 *)&asrc->asrc_format);
if (ret) {
ret = of_property_read_u32(np, "fsl,asrc-width", &width);
if (ret) {
@@ -1197,7 +1197,7 @@ static int fsl_asrc_probe(struct platform_device *pdev)
}
}

- if (!(FSL_ASRC_FORMATS & (1ULL << asrc->asrc_format))) {
+ if (!(FSL_ASRC_FORMATS & (1ULL << (__force u32)asrc->asrc_format))) {
dev_warn(&pdev->dev, "unsupported width, use default S24_LE\n");
asrc->asrc_format = SNDRV_PCM_FORMAT_S24_LE;
}
--
2.34.1


2022-07-19 10:19:45

by David Laight

[permalink] [raw]
Subject: RE: [PATCH -next 2/5] ASoC: fsl_asrc: force cast the asrc_format type

From: Shengjiu Wang
> Sent: 19 July 2022 10:28
>
> Fix sparse warning:
> sound/soc/fsl/fsl_asrc.c:1177:60: sparse: warning: incorrect type in argument 3 (different base types)
> sound/soc/fsl/fsl_asrc.c:1177:60: sparse: expected unsigned int [usertype] *out_value
> sound/soc/fsl/fsl_asrc.c:1177:60: sparse: got restricted snd_pcm_format_t *
> sound/soc/fsl/fsl_asrc.c:1200:47: sparse: warning: restricted snd_pcm_format_t degrades to integer
>
> Fixes: 4520af41fd21 ("ASoC: fsl_asrc: Support new property fsl,asrc-format")
> Signed-off-by: Shengjiu Wang <[email protected]>
> ---
> sound/soc/fsl/fsl_asrc.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c
> index 20a9f8e924b3..544395efd605 100644
> --- a/sound/soc/fsl/fsl_asrc.c
> +++ b/sound/soc/fsl/fsl_asrc.c
> @@ -1174,7 +1174,7 @@ static int fsl_asrc_probe(struct platform_device *pdev)
> return ret;
> }
>
> - ret = of_property_read_u32(np, "fsl,asrc-format", &asrc->asrc_format);
> + ret = of_property_read_u32(np, "fsl,asrc-format", (u32 *)&asrc->asrc_format);

Ugg, you really shouldn't need to do that.
It means that something is badly wrong somewhere.
Casting pointers to integer types is just asking for a bug.

> if (ret) {
> ret = of_property_read_u32(np, "fsl,asrc-width", &width);
> if (ret) {
> @@ -1197,7 +1197,7 @@ static int fsl_asrc_probe(struct platform_device *pdev)
> }
> }
>
> - if (!(FSL_ASRC_FORMATS & (1ULL << asrc->asrc_format))) {
> + if (!(FSL_ASRC_FORMATS & (1ULL << (__force u32)asrc->asrc_format))) {

Ditto.

David

> dev_warn(&pdev->dev, "unsupported width, use default S24_LE\n");
> asrc->asrc_format = SNDRV_PCM_FORMAT_S24_LE;
> }
> --
> 2.34.1

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

2022-07-19 10:26:25

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH -next 2/5] ASoC: fsl_asrc: force cast the asrc_format type

On Tue, Jul 19, 2022 at 10:01:54AM +0000, David Laight wrote:
> From: Shengjiu Wang

> > - ret = of_property_read_u32(np, "fsl,asrc-format", &asrc->asrc_format);
> > + ret = of_property_read_u32(np, "fsl,asrc-format", (u32 *)&asrc->asrc_format);

> Ugg, you really shouldn't need to do that.
> It means that something is badly wrong somewhere.
> Casting pointers to integer types is just asking for a bug.

That's casting one pointer type to another pointer type.


Attachments:
(No filename) (475.00 B)
signature.asc (499.00 B)
Download all attachments

2022-07-19 11:22:06

by David Laight

[permalink] [raw]
Subject: RE: [PATCH -next 2/5] ASoC: fsl_asrc: force cast the asrc_format type

From: Mark Brown
> Sent: 19 July 2022 11:17
>
> On Tue, Jul 19, 2022 at 10:01:54AM +0000, David Laight wrote:
> > From: Shengjiu Wang
>
> > > - ret = of_property_read_u32(np, "fsl,asrc-format", &asrc->asrc_format);
> > > + ret = of_property_read_u32(np, "fsl,asrc-format", (u32 *)&asrc->asrc_format);
>
> > Ugg, you really shouldn't need to do that.
> > It means that something is badly wrong somewhere.
> > Casting pointers to integer types is just asking for a bug.
>
> That's casting one pointer type to another pointer type.

It is casting the address of some type to a 'u32 *'.
This will then be dereferenced by the called function.
So the original type better be 32 bits.

I'm also guessing that sparse was complaining about endianness?
It isn't at all clear that these casts actually fix it.

(Mark: You'll be glad to hear that the office aircon is
broken again - two weeks lead time on the spare part.)

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)