Skip to content

Commit

Permalink
ALSA: hda: hda_component: Fix mutex crash if nothing ever binds
Browse files Browse the repository at this point in the history
Move the initialization of parent->mutex into
hda_component_manager_init() so that it is always valid.

In hda_component_manager_bind() do not clear the parent information.
Only zero-fill the per-component data ready for it to be filled in
by the components as they bind.

Previously parent->mutex was being initialized only in
hda_component_manager_bind(). This meant that it was only
initialized if all components appeared and there was a bind callback.
If there wasn't a bind the mutex object was not valid when the
Realtek driver called any of the other functions.

Signed-off-by: Richard Fitzgerald <[email protected]>
Fixes: 047b9cb ("ALSA: hda: hda_component: Protect shared data with a mutex")
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
rfvirgil authored and tiwai committed Aug 26, 2024
1 parent 2dc43c5 commit 28b329f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sound/pci/hda/hda_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ int hda_component_manager_bind(struct hda_codec *cdc,
int ret;

/* Init shared and component specific data */
memset(parent, 0, sizeof(*parent));
mutex_init(&parent->mutex);
memset(parent->comps, 0, sizeof(parent->comps));
parent->codec = cdc;

mutex_lock(&parent->mutex);
Expand All @@ -164,6 +163,8 @@ int hda_component_manager_init(struct hda_codec *cdc,
struct hda_scodec_match *sm;
int ret, i;

mutex_init(&parent->mutex);

for (i = 0; i < count; i++) {
sm = devm_kmalloc(dev, sizeof(*sm), GFP_KERNEL);
if (!sm)
Expand Down

0 comments on commit 28b329f

Please sign in to comment.