Hi,
Actually there's no black magic there because there's no dereference but
only pointer arithmetic. The compiler just adds the calculated offset to
NULL and passes that small pointer to printk().
Thanks
Guennadi
On Mon, 3 Apr 2023, Péter Ujfalusi wrote:
On 03/04/2023 08:54, Dan Carpenter wrote:
On Mon, Apr 03, 2023 at 08:20:38AM +0300, Péter Ujfalusi wrote:
On 01/04/2023 10:44, Dan Carpenter wrote:
On Fri, Mar 31, 2023 at 10:14:11AM +0300, Péter Ujfalusi wrote:
if src_fw_module is NULL then the print will be:
source (efault) or sink sink.module.name widget weren't set up properly
Guennadi is relying on some black magic in the printk system to handle
the printing instead of open coding.
I've done compiler related work and explored some weird aspect of the
C language and I am so fascinated by this. I would have thought it
crashes before the function is called. I cannot even imagine how black
magic like this would work.
I think it is not a compiler magic, but kernel magic:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/lib/vsprintf.c#n700
Is there anyway I can test this?
You could, If you have a laptop which uses SOF and it is Intel 11th gen
or newer then you can switch it to IPC4 and install the opt-in v2.5
(which would need with 6.4 kernel).
Apply this patch to 6.3-rc (or 6.2) and boot up, but unpatched kernel
will NULL dereference, so you need to have a backup option.
https://github.com/thesofproject/sof-bin
The v2.5 is not there as a release,you need to fetch the repo and follow
the instructions.
Read the instruction in v2.5.x/README.md before attempting to use this
release.
Now that I look back at the patch, yes it is not obvious, but it is
doing a valid thing.
Yeah. Fine. It doesn't crash but "valid" is kind of debatable. It's
a super ugly thing.
Well, it is going to behave in an expected way (print (efault) instead
of the module name in case it is not present).
By itself it is correct as this is a feature given by the kernel, on the
other hand, it could be improved to print the _swidget->widget->name and
a note, which side is missing the fw_module.
I can send a v2 with a new print without waiting for Guennadi in few hours.
--
Péter