From: Mark Brown Date: Wed, 14 Jul 2010 15:14:33 +0000 (+0100) Subject: ASoC: Handle read failures in codec_reg X-Git-Tag: v2.6.36-rc1~6^2~4^2~36 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=5164d74d74447895aaa31c094a1b9e666acaa656;p=linux-block.git ASoC: Handle read failures in codec_reg When a device is powered down volatile registers can't be read so attempts to display codec_reg will show error values, and obviously it is also possible for there to be hardware errors too. Check for errors from reads and display them more clearly when formatting codec_reg. Signed-off-by: Mark Brown Acked-by: Liam Girdwood --- diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 8b79d90efdc1..5299932db0b6 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -84,7 +84,7 @@ static int run_delayed_work(struct delayed_work *dwork) /* codec register dump */ static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf) { - int i, step = 1, count = 0; + int ret, i, step = 1, count = 0; if (!codec->reg_cache_size) return 0; @@ -101,12 +101,24 @@ static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf) if (count >= PAGE_SIZE - 1) break; - if (codec->display_register) + if (codec->display_register) { count += codec->display_register(codec, buf + count, PAGE_SIZE - count, i); - else - count += snprintf(buf + count, PAGE_SIZE - count, - "%4x", codec->read(codec, i)); + } else { + /* If the read fails it's almost certainly due to + * the register being volatile and the device being + * powered off. + */ + ret = codec->read(codec, i); + if (ret >= 0) + count += snprintf(buf + count, + PAGE_SIZE - count, + "%4x", ret); + else + count += snprintf(buf + count, + PAGE_SIZE - count, + "", ret); + } if (count >= PAGE_SIZE - 1) break;