Commit e8712315 authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: soc-component: use io_mutex correctly

component has io_mutex, but it had been used at
snd_soc_component_update_bits_legacy() only which does read and write.

	static int snd_soc_component_update_bits_legacy(...)
	{
		...
=>		mutex_lock(&component->io_mutex);
		...
		old = snd_soc_component_read(...);
		...
		ret = snd_soc_component_write(...);
		...
=>		mutex_unlock(&component->io_mutex);
		...
	}

It is pointless if it is not used with both read and write functions.
This patch uses io_mutex correctly with read/write.
Here, xxx_no_lock() is local functions.

	static int snd_soc_component_read(...)
	{
		...
=>		mutex_lock(&component->io_mutex);
		val = soc_component_read_no_lock(...);
=>		mutex_unlock(&component->io_mutex);
		...
	}

	static int snd_soc_component_write(...)
	{
		...
=>		mutex_lock(&component->io_mutex);
		ret = soc_component_write_no_lock(...);
=>		mutex_unlock(&component->io_mutex);
		...
	}

	static int snd_soc_component_update_bits_legacy(...)
	{
		...
=>		mutex_lock(&component->io_mutex);
		...
		old = soc_component_read_no_lock(...);
		...
		ret = soc_component_write_no_lock(...);
		...
=>		mutex_unlock(&component->io_mutex);
		...
	}
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/87r1uf4mfa.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent cf6e26c7
...@@ -403,14 +403,8 @@ EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap); ...@@ -403,14 +403,8 @@ EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
#endif #endif
/** static unsigned int soc_component_read_no_lock(
* snd_soc_component_read() - Read register value struct snd_soc_component *component,
* @component: Component to read from
* @reg: Register to read
*
* Return: read value
*/
unsigned int snd_soc_component_read(struct snd_soc_component *component,
unsigned int reg) unsigned int reg)
{ {
int ret; int ret;
...@@ -430,8 +424,41 @@ unsigned int snd_soc_component_read(struct snd_soc_component *component, ...@@ -430,8 +424,41 @@ unsigned int snd_soc_component_read(struct snd_soc_component *component,
return val; return val;
} }
/**
* snd_soc_component_read() - Read register value
* @component: Component to read from
* @reg: Register to read
*
* Return: read value
*/
unsigned int snd_soc_component_read(struct snd_soc_component *component,
unsigned int reg)
{
unsigned int val;
mutex_lock(&component->io_mutex);
val = soc_component_read_no_lock(component, reg);
mutex_unlock(&component->io_mutex);
return val;
}
EXPORT_SYMBOL_GPL(snd_soc_component_read); EXPORT_SYMBOL_GPL(snd_soc_component_read);
static int soc_component_write_no_lock(
struct snd_soc_component *component,
unsigned int reg, unsigned int val)
{
int ret = -EIO;
if (component->regmap)
ret = regmap_write(component->regmap, reg, val);
else if (component->driver->write)
ret = component->driver->write(component, reg, val);
return soc_component_ret(component, ret);
}
/** /**
* snd_soc_component_write() - Write register value * snd_soc_component_write() - Write register value
* @component: Component to write to * @component: Component to write to
...@@ -443,14 +470,13 @@ EXPORT_SYMBOL_GPL(snd_soc_component_read); ...@@ -443,14 +470,13 @@ EXPORT_SYMBOL_GPL(snd_soc_component_read);
int snd_soc_component_write(struct snd_soc_component *component, int snd_soc_component_write(struct snd_soc_component *component,
unsigned int reg, unsigned int val) unsigned int reg, unsigned int val)
{ {
int ret = -EIO; int ret;
if (component->regmap) mutex_lock(&component->io_mutex);
ret = regmap_write(component->regmap, reg, val); ret = soc_component_write_no_lock(component, reg, val);
else if (component->driver->write) mutex_unlock(&component->io_mutex);
ret = component->driver->write(component, reg, val);
return soc_component_ret(component, ret); return ret;
} }
EXPORT_SYMBOL_GPL(snd_soc_component_write); EXPORT_SYMBOL_GPL(snd_soc_component_write);
...@@ -463,12 +489,12 @@ static int snd_soc_component_update_bits_legacy( ...@@ -463,12 +489,12 @@ static int snd_soc_component_update_bits_legacy(
mutex_lock(&component->io_mutex); mutex_lock(&component->io_mutex);
old = snd_soc_component_read(component, reg); old = soc_component_read_no_lock(component, reg);
new = (old & ~mask) | (val & mask); new = (old & ~mask) | (val & mask);
*change = old != new; *change = old != new;
if (*change) if (*change)
ret = snd_soc_component_write(component, reg, new); ret = soc_component_write_no_lock(component, reg, new);
mutex_unlock(&component->io_mutex); mutex_unlock(&component->io_mutex);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment