[PATCH 00/14] ASoC: Constify local snd_sof_dsp_ops

Krzysztof Kozlowski krzk at kernel.org
Mon Apr 22 13:47:43 PDT 2024


On 22/04/2024 22:42, Pierre-Louis Bossart wrote:
> 
>> There are multiple reasons and benefits for const, like compiler
>> optimization, code readability (meaning) up to security improvements,
>> e.g. by some GCC plugins or marking rodata as really non-writeable, so
>> closing some ways of exploits. There are many opportunities here, even
>> if they are not yet enabled.
> 
> Possibly, but the SOF core does not know if the structure it uses is
> rodata or not. Using the 'const' identifier would be misleading.

How so? If core does not modify structure, it should take it via ops,
just like 100 other widely known structures (see checkpatch). Why is
this different?

> 
>>> that's a different interpretation to the 'software' view you're
>>> describing. "this structure will not modified by this function" is not
>>> the same thing as "this structure CANNOT be modified".
>>
>> Yes, but can we please discuss specific patchset then? Patches which
>> change pointers to const have one "interpretation". Patches which modify
>> static or global data have another.
> 
> Just look at sound/soc/sof/intel/mtl.c... The core will sometimes use a

That's a driver (or specific implementation), not core.

> constant structure and sometimes not, depending on the PCI ID reported
> by hardware. This was intentional to override common defaults and make
> the differences limited in scope between hardware generations.


> 
> int sof_mtl_ops_init(struct snd_sof_dev *sdev)
> {
> 	struct sof_ipc4_fw_data *ipc4_data;
> 
> 	/* common defaults */
> 	memcpy(&sof_mtl_ops, &sof_hda_common_ops, sizeof(struct
> snd_sof_dsp_ops)); <<<< THE BASELINE IS CONSTANT

Yes, I saw it and such users are not changed. They won't receive any
safety. But all others are getting safer.

I really do not understand what is the problem here. In entire Linux all
of such changes are welcomed with open arms. So what is different here?

> 
>         <<< THE REST ISN'T.
> 
> 	/* shutdown */
> 	sof_mtl_ops.shutdown = hda_dsp_shutdown;


Best regards,
Krzysztof




More information about the Linux-mediatek mailing list