Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ffd33c3 authored by Phani Kumar Uppalapati's avatar Phani Kumar Uppalapati
Browse files

ASoC: core: protect component list traversal with lock



Protect soc component list traversal using mutex lock
to prevent it being modified (add/delete nodes) by other
thread at the same time.

CRs-fixed: 981674
Change-Id: I0bc003f9ca1d490b65d5a4121562ed68f026f9bf
Signed-off-by: default avatarPhani Kumar Uppalapati <phaniu@codeaurora.org>
parent 53d1dd96
Loading
Loading
Loading
Loading
+24 −6
Original line number Diff line number Diff line
@@ -878,6 +878,7 @@ struct snd_soc_component *soc_find_component(
	const struct device_node *of_node, const char *name)
{
	struct snd_soc_component *component;
	bool found = false;

	if (!of_node && !name) {
		pr_err("%s: Either of_node or name must be valid\n",
@@ -885,15 +886,24 @@ struct snd_soc_component *soc_find_component(
		return NULL;
	}

	mutex_lock(&client_mutex);
	list_for_each_entry(component, &component_list, list) {
		if (of_node) {
			if (component->dev->of_node == of_node)
				return component;
			if (component->dev->of_node == of_node) {
				found = true;
				goto exit;
			}
		} else if (strcmp(component->name, name) == 0) {
			return component;
			found = true;
			goto exit;
		}
	}

exit:
	mutex_unlock(&client_mutex);
	if (found)
		return component;
	else
		return NULL;
}
EXPORT_SYMBOL(soc_find_component);
@@ -903,7 +913,9 @@ static struct snd_soc_dai *snd_soc_find_dai(
{
	struct snd_soc_component *component;
	struct snd_soc_dai *dai;
	bool found = false;

	mutex_lock(&client_mutex);
	/* Find CPU DAI from registered DAIs*/
	list_for_each_entry(component, &component_list, list) {
		if (dlc->of_node && component->dev->of_node != dlc->of_node)
@@ -914,10 +926,16 @@ static struct snd_soc_dai *snd_soc_find_dai(
			if (dlc->dai_name && strcmp(dai->name, dlc->dai_name))
				continue;

			return dai;
			found = true;
			goto exit;
		}
	}

exit:
	mutex_unlock(&client_mutex);
	if (found)
		return dai;
	else
		return NULL;
}