Skip to content

Commit

Permalink
ASoC: let snd_soc_update_bits() return an error code
Browse files Browse the repository at this point in the history
Update snd_soc_update_bits() so that it returns a negative error code if the
the read or write operation fails.

Note that currently, a lot of the lower-level read functions have an unsigned
integer return type (and some of them even try to return a negative number),
but this code still appears to work in those cases.

An examination of the code shows that all current callers are compatible with
this change.

Signed-off-by: Timur Tabi <timur@freescale.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
Timur Tabi authored and Mark Brown committed Jan 11, 2011
1 parent 4fde768 commit 180c329
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions sound/soc/soc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2137,19 +2137,27 @@ EXPORT_SYMBOL_GPL(snd_soc_write);
*
* Writes new register value.
*
* Returns 1 for change else 0.
* Returns 1 for change, 0 for no change, or negative error code.
*/
int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
unsigned int mask, unsigned int value)
{
int change;
unsigned int old, new;
int ret;

old = snd_soc_read(codec, reg);
ret = snd_soc_read(codec, reg);
if (ret < 0)
return ret;

old = ret;
new = (old & ~mask) | value;
change = old != new;
if (change)
snd_soc_write(codec, reg, new);
if (change) {
ret = snd_soc_write(codec, reg, new);
if (ret < 0)
return ret;
}

return change;
}
Expand Down

0 comments on commit 180c329

Please sign in to comment.