-
Notifications
You must be signed in to change notification settings - Fork 140
ASoC:topology: bug fix oops cause by pointer dereference. #72
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3046,6 +3046,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_card *card) | |
| { | ||
| struct snd_soc_dapm_widget *w; | ||
| unsigned int val; | ||
| int ret = 0; | ||
|
|
||
| mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_INIT); | ||
|
|
||
|
|
@@ -3068,23 +3069,30 @@ int snd_soc_dapm_new_widgets(struct snd_soc_card *card) | |
| case snd_soc_dapm_switch: | ||
| case snd_soc_dapm_mixer: | ||
| case snd_soc_dapm_mixer_named_ctl: | ||
| dapm_new_mixer(w); | ||
| ret = dapm_new_mixer(w); | ||
| break; | ||
| case snd_soc_dapm_mux: | ||
| case snd_soc_dapm_demux: | ||
| dapm_new_mux(w); | ||
| ret = dapm_new_mux(w); | ||
| break; | ||
| case snd_soc_dapm_pga: | ||
| case snd_soc_dapm_out_drv: | ||
| dapm_new_pga(w); | ||
| ret = dapm_new_pga(w); | ||
| break; | ||
| case snd_soc_dapm_dai_link: | ||
| dapm_new_dai_link(w); | ||
| ret = dapm_new_dai_link(w); | ||
| break; | ||
| default: | ||
| break; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should the code in the default case:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, do it outside default case otherwise we wont kfree() all resources.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lgirdwood in this case, the w->kcontrols will be allocated. but it is not processed by sub-function, because the default case is entered. then question comes: should we kfree this allocated w->kcontrols at this time? If yes, we have to kfree it. then I will roll back to the previous version: adding the flag in the default case. when the flag is set in the default. we will do the kfree. if no, I think we can not cover the "siggen" case, which cause our panic when in tplg free stage.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zhigang-wu I need you to improve the current patch to consider all error paths in the function. default case is a valid for other widget types so cant be used as a means of freeing resources. Just walk through this function line by line and see where things could fail and then ask where do I recover this ?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lgirdwood that function adds new widgets by walking a linked list of them. If adding one of them fails, looks like previously successfully added widgets are kept. Without this patch in such a case the function could return an error, if allocation failed, or 0, if initialisation failed. I can see the following possibilities in case of a partial success:
|
||
| } | ||
|
|
||
| if (ret < 0) { | ||
| kfree(w->kcontrols); | ||
| w->kcontrols = NULL; | ||
| mutex_unlock(&card->dapm_mutex); | ||
| return ret; | ||
| } | ||
|
|
||
| /* Read the initial power state from the device */ | ||
| if (w->reg >= 0) { | ||
| soc_dapm_read(w->dapm, w->reg, &val); | ||
|
|
||
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.
Checking the return is good, but dapm_new_mixer, dapm_new_mux etc should free any resources they allocate on failure. likewise dapm_create_or_share_kcontrol() will also need to be check that it frees any resource it allocates on failure. So please
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.
like the snd_soc_dapm_add_path(), it also do this job already when return with error.
I think we have to free it when enter the default case.