<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head><body lang="EN-GB" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">grrr... top-posting because outluck is really stupid :-(<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">The definition seems to be:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">typedef int
<a href="https://elixir.bootlin.com/linux/v5.19-rc7/C/ident/__bitwise">__bitwise</a>
<a href="https://elixir.bootlin.com/linux/v5.19-rc7/C/ident/snd_pcm_format_t">snd_pcm_format_t</a>;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">#define
<a href="https://elixir.bootlin.com/linux/v5.19-rc7/C/ident/SNDRV_PCM_FORMAT_S8">
SNDRV_PCM_FORMAT_S8</a> ((<a href="https://elixir.bootlin.com/linux/v5.19-rc7/C/ident/__force">__force</a>
<a href="https://elixir.bootlin.com/linux/v5.19-rc7/C/ident/snd_pcm_format_t">snd_pcm_format_t</a>) 0)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">#define
<a href="https://elixir.bootlin.com/linux/v5.19-rc7/C/ident/SNDRV_PCM_FORMAT_U8">
SNDRV_PCM_FORMAT_U8</a> ((<a href="https://elixir.bootlin.com/linux/v5.19-rc7/C/ident/__force">__force</a>
<a href="https://elixir.bootlin.com/linux/v5.19-rc7/C/ident/snd_pcm_format_t">snd_pcm_format_t</a>) 1)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">#define
<a href="https://elixir.bootlin.com/linux/v5.19-rc7/C/ident/SNDRV_PCM_FORMAT_S16_LE">
SNDRV_PCM_FORMAT_S16_LE</a> ((<a href="https://elixir.bootlin.com/linux/v5.19-rc7/C/ident/__force">__force</a>
<a href="https://elixir.bootlin.com/linux/v5.19-rc7/C/ident/snd_pcm_format_t">snd_pcm_format_t</a>) 2)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Courier New"">...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">(goes away and looks up __bitwIse)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">I think I’d add:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">#define snd_pcm_format(val) ((__force snd_pcm_format_t)(val))<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">and use that to remove most of the casts.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">But the ones where you have (u32 *)&xxx are only valid because u32 and int are the same size.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">That does sort of happen to be true, but someone might look at all the values and<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">decide that u8 is big enough.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">After which the code will still compile, but the data areas get corrupted.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">So you really need to use a u32 ‘temp’ variable.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">It would all be slightly less problematic if the ‘force’ casts could be sparse only<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">(ie not seen by the compiler) – so the compiler would do the type checking.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"> David<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> Shengjiu Wang <shengjiu.wang@gmail.com>
<br>
<b>Sent:</b> 19 July 2022 12:07<br>
<b>To:</b> David Laight <David.Laight@ACULAB.COM><br>
<b>Cc:</b> Mark Brown <broonie@kernel.org>; Shengjiu Wang <shengjiu.wang@nxp.com>; Xiubo.Lee@gmail.com; festevam@gmail.com; nicoleotsuka@gmail.com; lgirdwood@gmail.com; perex@perex.cz; tiwai@suse.com; alsa-devel@alsa-project.org; linuxppc-dev@lists.ozlabs.org;
linux-kernel@vger.kernel.org<br>
<b>Subject:</b> Re: [PATCH -next 2/5] ASoC: fsl_asrc: force cast the asrc_format type<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Tue, Jul 19, 2022 at 6:34 PM David Laight <<a href="mailto:David.Laight@aculab.com">David.Laight@aculab.com</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt">From: Mark Brown<br>
> Sent: 19 July 2022 11:17<br>
> <br>
> On Tue, Jul 19, 2022 at 10:01:54AM +0000, David Laight wrote:<br>
> > From: Shengjiu Wang<br>
> <br>
> > > - ret = of_property_read_u32(np, "fsl,asrc-format", &asrc->asrc_format);<br>
> > > + ret = of_property_read_u32(np, "fsl,asrc-format", (u32 *)&asrc->asrc_format);<br>
> <br>
> > Ugg, you really shouldn't need to do that.<br>
> > It means that something is badly wrong somewhere.<br>
> > Casting pointers to integer types is just asking for a bug.<br>
> <br>
> That's casting one pointer type to another pointer type.<br>
<br>
It is casting the address of some type to a 'u32 *'.<br>
This will then be dereferenced by the called function.<br>
So the original type better be 32 bits.<br>
<br>
I'm also guessing that sparse was complaining about endianness?<br>
It isn't at all clear that these casts actually fix it.<o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal">The sparse is complaining about the snd_pcm_format_t cast to u32/int type.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The code in include/sound/pcm.h also does such __force cast.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">#define _SNDRV_PCM_FMTBIT(fmt) (1ULL << (__force int)SNDRV_PCM_FORMAT_##fmt)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The change I have made does not cause an issue. <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Best regards<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Wang shengjiu<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt">(Mark: You'll be glad to hear that the office aircon is<br>
broken again - two weeks lead time on the spare part.)<br>
<br>
David<br>
<br>
-<br>
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK<br>
Registration No: 1397386 (Wales)<o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</div>
<br><br><div><span style="color:#484830;font-family:Tahoma;font-size:xx-small">Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK<br>Registration No: 1397386 (Wales)</span></div>
<div>
<p><span style="color:#008000;font-family:Arial"><span style="font-size:xx-small"><span style="font-family:Webdings">P </span><strong>Please consider the environment and don't print this e-mail unless you really need to</strong></span></span></p>
</div></body></html>