* [PATCH 1/3] ASoC: rt5514: Mark rt5514_i2c_driver as static
@ 2017-04-14 16:40 Douglas Anderson
2017-04-14 16:40 ` [PATCH 2/3] ASoC: rt5514: Avoid relying on uninitialized "val" value Douglas Anderson
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Douglas Anderson @ 2017-04-14 16:40 UTC (permalink / raw)
To: bardliao, oder_chiou
Cc: Douglas Anderson, lgirdwood, broonie, perex, tiwai, alsa-devel,
linux-kernel
There's no reason for rt5514_i2c_driver to be non-static.
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
sound/soc/codecs/rt5514.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c
index b281a46d769d..481e77763fe4 100644
--- a/sound/soc/codecs/rt5514.c
+++ b/sound/soc/codecs/rt5514.c
@@ -1149,7 +1149,7 @@ static int rt5514_i2c_remove(struct i2c_client *i2c)
return 0;
}
-struct i2c_driver rt5514_i2c_driver = {
+static struct i2c_driver rt5514_i2c_driver = {
.driver = {
.name = "rt5514",
.of_match_table = of_match_ptr(rt5514_of_match),
--
2.12.2.762.g0e3151a226-goog
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 2/3] ASoC: rt5514: Avoid relying on uninitialized "val" value 2017-04-14 16:40 [PATCH 1/3] ASoC: rt5514: Mark rt5514_i2c_driver as static Douglas Anderson @ 2017-04-14 16:40 ` Douglas Anderson 2017-04-14 17:11 ` Applied "ASoC: rt5514: Avoid relying on uninitialized "val" value" to the asoc tree Mark Brown 2017-04-14 16:40 ` [PATCH 3/3] ASoC: rt5514: Unconfuse the rt5514 at probe / resume time Douglas Anderson 2017-04-14 17:12 ` Applied "ASoC: rt5514: Mark rt5514_i2c_driver as static" " Mark Brown 2 siblings, 1 reply; 6+ messages in thread From: Douglas Anderson @ 2017-04-14 16:40 UTC (permalink / raw) To: bardliao, oder_chiou Cc: Douglas Anderson, lgirdwood, broonie, perex, tiwai, alsa-devel, linux-kernel In rt5514_i2c_probe() if the regmap_read(RT5514_VENDOR_ID2) fails then "val" may be left as uninitialized. Current code relies on "val" not being RT5514_DEVICE_ID, but that's potentially unsafe. Let's check for errors from regmap_read() and also explicitly init the value do we're not passing a possibly uninitialized int to printk. Signed-off-by: Douglas Anderson <dianders@chromium.org> --- sound/soc/codecs/rt5514.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c index 481e77763fe4..969a05620e04 100644 --- a/sound/soc/codecs/rt5514.c +++ b/sound/soc/codecs/rt5514.c @@ -1090,7 +1090,7 @@ static int rt5514_i2c_probe(struct i2c_client *i2c, struct rt5514_platform_data *pdata = dev_get_platdata(&i2c->dev); struct rt5514_priv *rt5514; int ret; - unsigned int val; + unsigned int val = ~0; rt5514 = devm_kzalloc(&i2c->dev, sizeof(struct rt5514_priv), GFP_KERNEL); @@ -1120,8 +1120,8 @@ static int rt5514_i2c_probe(struct i2c_client *i2c, return ret; } - regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); - if (val != RT5514_DEVICE_ID) { + ret = regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); + if (ret || val != RT5514_DEVICE_ID) { dev_err(&i2c->dev, "Device with ID register %x is not rt5514\n", val); return -ENODEV; -- 2.12.2.762.g0e3151a226-goog ^ permalink raw reply [flat|nested] 6+ messages in thread
* Applied "ASoC: rt5514: Avoid relying on uninitialized "val" value" to the asoc tree 2017-04-14 16:40 ` [PATCH 2/3] ASoC: rt5514: Avoid relying on uninitialized "val" value Douglas Anderson @ 2017-04-14 17:11 ` Mark Brown 0 siblings, 0 replies; 6+ messages in thread From: Mark Brown @ 2017-04-14 17:11 UTC (permalink / raw) To: Douglas Anderson Cc: Mark Brown, bardliao, oder_chiou, alsa-devel, lgirdwood, linux-kernel, tiwai, broonie, alsa-devel The patch ASoC: rt5514: Avoid relying on uninitialized "val" value has been applied to the asoc tree at git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark >From 0a78b248c3324fbbba49f74e2c93e0f436583788 Mon Sep 17 00:00:00 2001 From: Douglas Anderson <dianders@chromium.org> Date: Fri, 14 Apr 2017 09:40:31 -0700 Subject: [PATCH] ASoC: rt5514: Avoid relying on uninitialized "val" value In rt5514_i2c_probe() if the regmap_read(RT5514_VENDOR_ID2) fails then "val" may be left as uninitialized. Current code relies on "val" not being RT5514_DEVICE_ID, but that's potentially unsafe. Let's check for errors from regmap_read() and also explicitly init the value do we're not passing a possibly uninitialized int to printk. Signed-off-by: Douglas Anderson <dianders@chromium.org> Signed-off-by: Mark Brown <broonie@kernel.org> --- sound/soc/codecs/rt5514.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c index 481e77763fe4..969a05620e04 100644 --- a/sound/soc/codecs/rt5514.c +++ b/sound/soc/codecs/rt5514.c @@ -1090,7 +1090,7 @@ static int rt5514_i2c_probe(struct i2c_client *i2c, struct rt5514_platform_data *pdata = dev_get_platdata(&i2c->dev); struct rt5514_priv *rt5514; int ret; - unsigned int val; + unsigned int val = ~0; rt5514 = devm_kzalloc(&i2c->dev, sizeof(struct rt5514_priv), GFP_KERNEL); @@ -1120,8 +1120,8 @@ static int rt5514_i2c_probe(struct i2c_client *i2c, return ret; } - regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); - if (val != RT5514_DEVICE_ID) { + ret = regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); + if (ret || val != RT5514_DEVICE_ID) { dev_err(&i2c->dev, "Device with ID register %x is not rt5514\n", val); return -ENODEV; -- 2.11.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/3] ASoC: rt5514: Unconfuse the rt5514 at probe / resume time 2017-04-14 16:40 [PATCH 1/3] ASoC: rt5514: Mark rt5514_i2c_driver as static Douglas Anderson 2017-04-14 16:40 ` [PATCH 2/3] ASoC: rt5514: Avoid relying on uninitialized "val" value Douglas Anderson @ 2017-04-14 16:40 ` Douglas Anderson 2017-04-14 17:11 ` Applied "ASoC: rt5514: Unconfuse the rt5514 at probe / resume time" to the asoc tree Mark Brown 2017-04-14 17:12 ` Applied "ASoC: rt5514: Mark rt5514_i2c_driver as static" " Mark Brown 2 siblings, 1 reply; 6+ messages in thread From: Douglas Anderson @ 2017-04-14 16:40 UTC (permalink / raw) To: bardliao, oder_chiou Cc: Douglas Anderson, lgirdwood, broonie, perex, tiwai, alsa-devel, linux-kernel The rt5514 can get confused and incorrectly detect a start bit if the SCL/SDA lines happen to both go low and then high again. This situation has been seen to happen at reboot time and is also theoretically possible during suspend/resume if the rt5514 keeps power but we shut down the i2c connection. When this happens the rt5514 is confused about the state of the i2c bus and won't recognize its own address. That will lead to the rt5514 incorrectly NAKing the first transfer. A single i2c transfer to any address should be enough to get the rt5514 out of this funky state. It is currently believed that this problem should be fixed in the rt5514 driver itself because it seems that the i2c controller in the rt5514 is easily confused. Most i2c devices wouldn't detect a start bit in this case. Signed-off-by: Douglas Anderson <dianders@chromium.org> --- sound/soc/codecs/rt5514.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c index 969a05620e04..f91221b1ddf0 100644 --- a/sound/soc/codecs/rt5514.c +++ b/sound/soc/codecs/rt5514.c @@ -1084,6 +1084,21 @@ static int rt5514_parse_dt(struct rt5514_priv *rt5514, struct device *dev) return 0; } +static __maybe_unused int rt5514_i2c_resume(struct device *dev) +{ + struct rt5514_priv *rt5514 = dev_get_drvdata(dev); + unsigned int val; + + /* + * Add a bogus read to avoid rt5514's confusion after s2r in case it + * saw glitches on the i2c lines and thought the other side sent a + * start bit. + */ + regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); + + return 0; +} + static int rt5514_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { @@ -1120,7 +1135,15 @@ static int rt5514_i2c_probe(struct i2c_client *i2c, return ret; } + /* + * The rt5514 can get confused if the i2c lines glitch together, as + * can happen at bootup as regulators are turned off and on. If it's + * in this glitched state the first i2c read will fail, so we'll give + * it one change to retry. + */ ret = regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); + if (ret || val != RT5514_DEVICE_ID) + ret = regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); if (ret || val != RT5514_DEVICE_ID) { dev_err(&i2c->dev, "Device with ID register %x is not rt5514\n", val); @@ -1149,10 +1172,15 @@ static int rt5514_i2c_remove(struct i2c_client *i2c) return 0; } +static const struct dev_pm_ops rt5514_i2_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(NULL, rt5514_i2c_resume) +}; + static struct i2c_driver rt5514_i2c_driver = { .driver = { .name = "rt5514", .of_match_table = of_match_ptr(rt5514_of_match), + .pm = &rt5514_i2_pm_ops, }, .probe = rt5514_i2c_probe, .remove = rt5514_i2c_remove, -- 2.12.2.762.g0e3151a226-goog ^ permalink raw reply [flat|nested] 6+ messages in thread
* Applied "ASoC: rt5514: Unconfuse the rt5514 at probe / resume time" to the asoc tree 2017-04-14 16:40 ` [PATCH 3/3] ASoC: rt5514: Unconfuse the rt5514 at probe / resume time Douglas Anderson @ 2017-04-14 17:11 ` Mark Brown 0 siblings, 0 replies; 6+ messages in thread From: Mark Brown @ 2017-04-14 17:11 UTC (permalink / raw) To: Douglas Anderson Cc: Mark Brown, bardliao, oder_chiou, alsa-devel, lgirdwood, linux-kernel, tiwai, broonie, alsa-devel The patch ASoC: rt5514: Unconfuse the rt5514 at probe / resume time has been applied to the asoc tree at git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark >From 7952b4baff402ddca1a263380bfd142f10290eb8 Mon Sep 17 00:00:00 2001 From: Douglas Anderson <dianders@chromium.org> Date: Fri, 14 Apr 2017 09:40:32 -0700 Subject: [PATCH] ASoC: rt5514: Unconfuse the rt5514 at probe / resume time The rt5514 can get confused and incorrectly detect a start bit if the SCL/SDA lines happen to both go low and then high again. This situation has been seen to happen at reboot time and is also theoretically possible during suspend/resume if the rt5514 keeps power but we shut down the i2c connection. When this happens the rt5514 is confused about the state of the i2c bus and won't recognize its own address. That will lead to the rt5514 incorrectly NAKing the first transfer. A single i2c transfer to any address should be enough to get the rt5514 out of this funky state. It is currently believed that this problem should be fixed in the rt5514 driver itself because it seems that the i2c controller in the rt5514 is easily confused. Most i2c devices wouldn't detect a start bit in this case. Signed-off-by: Douglas Anderson <dianders@chromium.org> Signed-off-by: Mark Brown <broonie@kernel.org> --- sound/soc/codecs/rt5514.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c index 969a05620e04..f91221b1ddf0 100644 --- a/sound/soc/codecs/rt5514.c +++ b/sound/soc/codecs/rt5514.c @@ -1084,6 +1084,21 @@ static int rt5514_parse_dt(struct rt5514_priv *rt5514, struct device *dev) return 0; } +static __maybe_unused int rt5514_i2c_resume(struct device *dev) +{ + struct rt5514_priv *rt5514 = dev_get_drvdata(dev); + unsigned int val; + + /* + * Add a bogus read to avoid rt5514's confusion after s2r in case it + * saw glitches on the i2c lines and thought the other side sent a + * start bit. + */ + regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); + + return 0; +} + static int rt5514_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id) { @@ -1120,7 +1135,15 @@ static int rt5514_i2c_probe(struct i2c_client *i2c, return ret; } + /* + * The rt5514 can get confused if the i2c lines glitch together, as + * can happen at bootup as regulators are turned off and on. If it's + * in this glitched state the first i2c read will fail, so we'll give + * it one change to retry. + */ ret = regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); + if (ret || val != RT5514_DEVICE_ID) + ret = regmap_read(rt5514->regmap, RT5514_VENDOR_ID2, &val); if (ret || val != RT5514_DEVICE_ID) { dev_err(&i2c->dev, "Device with ID register %x is not rt5514\n", val); @@ -1149,10 +1172,15 @@ static int rt5514_i2c_remove(struct i2c_client *i2c) return 0; } +static const struct dev_pm_ops rt5514_i2_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(NULL, rt5514_i2c_resume) +}; + static struct i2c_driver rt5514_i2c_driver = { .driver = { .name = "rt5514", .of_match_table = of_match_ptr(rt5514_of_match), + .pm = &rt5514_i2_pm_ops, }, .probe = rt5514_i2c_probe, .remove = rt5514_i2c_remove, -- 2.11.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Applied "ASoC: rt5514: Mark rt5514_i2c_driver as static" to the asoc tree 2017-04-14 16:40 [PATCH 1/3] ASoC: rt5514: Mark rt5514_i2c_driver as static Douglas Anderson 2017-04-14 16:40 ` [PATCH 2/3] ASoC: rt5514: Avoid relying on uninitialized "val" value Douglas Anderson 2017-04-14 16:40 ` [PATCH 3/3] ASoC: rt5514: Unconfuse the rt5514 at probe / resume time Douglas Anderson @ 2017-04-14 17:12 ` Mark Brown 2 siblings, 0 replies; 6+ messages in thread From: Mark Brown @ 2017-04-14 17:12 UTC (permalink / raw) To: Douglas Anderson Cc: Mark Brown, bardliao, oder_chiou, alsa-devel, lgirdwood, linux-kernel, tiwai, broonie, alsa-devel The patch ASoC: rt5514: Mark rt5514_i2c_driver as static has been applied to the asoc tree at git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark >From d0c02e14e48be94dd312ff6edffab9f9e6acd480 Mon Sep 17 00:00:00 2001 From: Douglas Anderson <dianders@chromium.org> Date: Fri, 14 Apr 2017 09:40:30 -0700 Subject: [PATCH] ASoC: rt5514: Mark rt5514_i2c_driver as static There's no reason for rt5514_i2c_driver to be non-static. Signed-off-by: Douglas Anderson <dianders@chromium.org> Signed-off-by: Mark Brown <broonie@kernel.org> --- sound/soc/codecs/rt5514.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/codecs/rt5514.c b/sound/soc/codecs/rt5514.c index b281a46d769d..481e77763fe4 100644 --- a/sound/soc/codecs/rt5514.c +++ b/sound/soc/codecs/rt5514.c @@ -1149,7 +1149,7 @@ static int rt5514_i2c_remove(struct i2c_client *i2c) return 0; } -struct i2c_driver rt5514_i2c_driver = { +static struct i2c_driver rt5514_i2c_driver = { .driver = { .name = "rt5514", .of_match_table = of_match_ptr(rt5514_of_match), -- 2.11.0 ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-04-14 17:14 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-04-14 16:40 [PATCH 1/3] ASoC: rt5514: Mark rt5514_i2c_driver as static Douglas Anderson 2017-04-14 16:40 ` [PATCH 2/3] ASoC: rt5514: Avoid relying on uninitialized "val" value Douglas Anderson 2017-04-14 17:11 ` Applied "ASoC: rt5514: Avoid relying on uninitialized "val" value" to the asoc tree Mark Brown 2017-04-14 16:40 ` [PATCH 3/3] ASoC: rt5514: Unconfuse the rt5514 at probe / resume time Douglas Anderson 2017-04-14 17:11 ` Applied "ASoC: rt5514: Unconfuse the rt5514 at probe / resume time" to the asoc tree Mark Brown 2017-04-14 17:12 ` Applied "ASoC: rt5514: Mark rt5514_i2c_driver as static" " Mark Brown
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®