-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dummy smart_amp: copy input_pins and output_pin separately #7588
Conversation
memcpy_s(sad->ipc4_cfg.input_pins, in_size, | ||
base_cfg->base_cfg_ext.pin_formats, in_size); | ||
memcpy_s(&sad->ipc4_cfg.output_pin, out_size, | ||
base_cfg->base_cfg_ext.pin_formats + in_size, out_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointer arithmetic on a flexible array member, wow! I wonder what that means. It looks suspicious... maybe this instead?
base_cfg->base_cfg_ext.pin_formats + in_size, out_size); | |
&base_cfg->base_cfg_ext.pin_formats[0] + in_size, out_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointer arithmetic on a flexible array member, wow! I wonder what that means.
Most likely the same thing as a regular array, sorry the noise. In that case:
base_cfg->base_cfg_ext.pin_formats + in_size, out_size); | |
&base_cfg->base_cfg_ext.pin_formats[in_size], out_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may cause memory leak, it may add pointer based on pin_format size instead of byte, better continue add (char *) at beginning in case xtensa compiler is not so strong.
(char *)&base_cfg->base_cfg_ext.pin_formats[0] + in_size
or
(char *)&base_cfg->base_cfg_ext.pin_formats[1] ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in case xtensa compiler is not so strong.
The xtensa compiler is based on either GCC or Clang so there's no standard compliance concern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this may cause memory leak,
I think you mean buffer overflow. Memory leak is something entirely different.
add (char *) at beginning
Yes the code assumes that sizeof(pin_formats[0])
is 1 and that's not very obvious. Especially not considering input_pins
and output_pin
are totally different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, should be buffer overflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code change is good, commit message does have a tiny issue...
This change makes the code less error prone, not more.
Thanks. |
The original code confuses static code analyzers since it was relying on the fact that we have the 2x input and 1x output pin config in adjacent position in smart_amp_data struct similarly to the extended module configuration. While it works, it is not a good practice. Split the copy of input and output pin formats to make the code obvious and less error prone. Fixes: andrula-song@ bcc1407 ("smart_amp_test: Split the module config and blob receiving for IPC4") Signed-off-by: Andrula Song <andrula.song@intel.com>
SPFCI TEST |
SOFCI TEST |
1 similar comment
SOFCI TEST |
One fail hit in https://sof-ci.01.org/sofpr/PR7588/build7818/devicetest/index.html -- a known bug. |
The original code confuses static code analyzers since it was
relying on the fact that we have the 2x input and 1x output pin
config in adjacent position in smart_amp_data struct similarly
to the extended module configuration.
While it works, it is not a good practice.
Split the copy of input and output pin formats to make the code
obvious and less error prone.
Fixes: andrula-song@bcc1407 ("smart_amp_test: Split the module config and blob receiving for IPC4")
Signed-off-by: Andrula Song andrula.song@intel.com