Re: [PATCH 6/8] i2c: nomadik: handle pm_runtime errors
From: Wolfram Sang
Date: Sun Nov 08 2026 - 05:27:23 EST
On Thu, Nov 05, 2026 at 10:51:07AM +0200, Wolfram Sang wrote:
> On Thu, Nov 05, 2026 at 09:42:02AM +0100, Linus Walleij wrote:
> > On Tue, Nov 3, 2026 at 9:30 AM Dmitry Guzman <Dmitry.Guzman@xxxxxxxxxxxx> wrote:
> >
> > > 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.
> > >
> > > Check the return value of pm_runtime_get_sync() and it if is not 0,
> > > return the error immediately.
> > >
> > > Signed-off-by: Dmitry Guzman <Dmitry.Guzman@xxxxxxxxxxxx>
> > (...)
> > > - pm_runtime_get_sync(&priv->adev->dev);
> > > + i = pm_runtime_get_sync(&priv->adev->dev);
> > > + if (i)
> > > + return i;
> >
> > It's a bit odd to reuse the i (= iterator...) variable for this.
> > I would just add an int ret or int err for this.
>
> Yes, please.
I changed this to:
@@ -730,11 +730,12 @@ 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);
- pm_runtime_get_sync(&priv->adev->dev);
+ status = pm_runtime_get_sync(&priv->adev->dev);
+ if (status)
+ return status;
/* setup the i2c controller */
setup_i2c_controller(priv);
while applying.