i2c: nomadik: handle pm_runtime errors
Subsystems (2)
PATCH 1/1 i2c: nomadik: handle pm_runtime errors
In nmk_i2c_xfer(), pm_runtime_get_sync() is called on start and then the controller registers are accessed without checking the return value. If pm_runtime_get_sync() fails, access to the register of the device that was not correctly powered on may cause a bus fault or other unpredictable system behavior.
Replace pm_runtime_get_sync() with pm_runtime_resume_and_get() that always return 0 on success and automatically restores PM usage counter on failure, and return immediately if it returns any error.
---
This is fixed version of patch #6 in a set of fixes in i2c-nomadik driver:
https://lore.kernel.org/linux-i2c/[email protected]/
Please replace that patch with this one.
Changes in this version of the patch:
- use pm_runtime_resume_and_get() instead of pm_runtime_get_sync() in order to automatically restore the usage counter on failure and always
get 0 on success (pm_runtime_get_sync() may also return 1 if the device is already active).
- use variable status instead of i for its return value.
--- drivers/i2c/busses/i2c-nomadik.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-nomadik.c +4 -3
@@ -713,12 +713,13 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *priv, u16 flags)static int nmk_i2c_xfer (struct i2c_adapter *i2c_adap,struct i2c_msg msgs[],int num_msgs) { -int status =0 ; -int i; +int status, i;struct nmk_i2c_dev *priv =i2c_get_adapdata (i2c_adap);int j; -pm_runtime_get_sync (&priv->adev->dev); + status =pm_runtime_resume_and_get (&priv->adev->dev); +if (status) +return status;/* Attempt three times to send the message queue */ for (j =0 ; j <3 ; j++) {
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261110-i2c-nomadik-handle-pm_errors-4925b54a5076
Best regards,
Signature · 1 line
Dmitry Guzman <[email protected]>
Wolfram Sang
AppliedQuoted 11 lines · Dmitry Guzman
In
nmk_i2c_xfer(),pm_runtime_get_sync()is called on start and then the controller registers are accessed without checking the return value. Ifpm_runtime_get_sync()fails, access to the register of the device that was not correctly powered on may cause a bus fault or other unpredictable system behavior.Replace
pm_runtime_get_sync()withpm_runtime_resume_and_get()that always return 0 on success and automatically restores PM usage counter on failure, and return immediately if it returns any error.Signed-off-by Dmitry Guzman <[email protected]>
Applied to my for-andi branch, thanks!