MLK-14848: regmap: drop cache if the bus transfer error

This fixes regmap not properly handling errors from underlying busses
like i2c. In particular it fixes hangs caused by sending sysrq t on the
serial on imx6q. What happens is:

- cpufreq core tries to increase frequency
- cpufreq driver tries to increase voltage for new frequency
- regulator core calls set_voltage_sel which is implemented using regmap
helpers for pfuze100
- i2c controller times out because we're printing the full list of tasks
with interrupts disabled and it's BH code doesn't get to run
- this is reported as an error but the regcache value is incorrectly
updated to the new one (this is the incorrect step).
- cpufreq attempts to increase frequency and voltage again later.
- When regulator_set_voltage is called again the regulator core calls
get_voltage_sel first, gets the value it previously tried to set from
the cache and decides it doesn't need to do anything.
- regulator core returns success without attempting a new hw write.
- cpufreq driver increases frequency next and the system hangs.

There are various alternate workarounds such as disabling the cache for
pfuze100 entirely (replace REGCACHE_RBTREE with REGCACHE_NONE). This
results in additional i2c reads.

This is a squash of two upstream commits because the first fix does not
deal with locking correctly. These are:

commit 815806e39bf6 ("regmap: drop cache if the bus transfer error")
commit f0aa1ce6259e ("regmap: fix deadlock on _regmap_raw_write() error path")

Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Reported-by: Dong Aisheng <aisheng.dong@freescale.com>
1 file changed