Skip to content

Commit 4a5aa00

Browse files
benoitmoninAndi Shyti
authored andcommitted
i2c: designware: Use runtime PM macro for auto-cleanup
Simplify runtime PM handling in i2c_dw_xfer_common() by using the pm_runtime_active_auto_try guard. This adds the proper handling for runtime PM resume errors and allows us to get rid of the done and done_nolock labels. Also use the dedicated PM_RUNTIME macros in amd_i2c_dw_xfer_quirk() instead of ACQUIRE()/ACQUIRE_ERR(). Signed-off-by: Benoît Monin <benoit.monin@bootlin.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Link: https://lore.kernel.org/r/20260130-i2c-dw-v6-2-08ca1e9ece07@bootlin.com
1 parent 470f1a7 commit 4a5aa00

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

drivers/i2c/busses/i2c-designware-master.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ static int amd_i2c_dw_xfer_quirk(struct dw_i2c_dev *dev, struct i2c_msg *msgs, i
296296
u8 *tx_buf;
297297
unsigned int val;
298298

299-
ACQUIRE(pm_runtime_active_auto_try, pm)(dev->dev);
300-
if (ACQUIRE_ERR(pm_runtime_active_auto_try, &pm))
299+
PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev->dev, pm);
300+
if (PM_RUNTIME_ACQUIRE_ERR(&pm))
301301
return -ENXIO;
302302

303303
/*
@@ -846,11 +846,13 @@ i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num)
846846

847847
dev_dbg(dev->dev, "msgs: %d\n", num);
848848

849-
pm_runtime_get_sync(dev->dev);
849+
PM_RUNTIME_ACQUIRE_AUTOSUSPEND(dev->dev, pm);
850+
if (PM_RUNTIME_ACQUIRE_ERR(&pm))
851+
return -ENXIO;
850852

851853
ret = i2c_dw_acquire_lock(dev);
852854
if (ret)
853-
goto done_nolock;
855+
return ret;
854856

855857
/*
856858
* If the I2C_M_STOP is present in some the messages,
@@ -866,28 +868,26 @@ i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num)
866868
for (cnt = 1; ; cnt++) {
867869
if (!i2c_dw_msg_is_valid(dev, msgs_part, cnt - 1)) {
868870
ret = -EINVAL;
869-
goto done;
871+
break;
870872
}
871873

872874
if ((msgs_part[cnt - 1].flags & I2C_M_STOP) ||
873875
(msgs_part + cnt == msgs + num))
874876
break;
875877
}
878+
if (ret < 0)
879+
break;
876880

877881
/* transfer one part up to a STOP */
878882
ret = __i2c_dw_xfer_one_part(dev, msgs_part, cnt);
879883
if (ret < 0)
880884
break;
881885
}
882886

883-
done:
884887
i2c_dw_set_mode(dev, DW_IC_SLAVE);
885888

886889
i2c_dw_release_lock(dev);
887890

888-
done_nolock:
889-
pm_runtime_put_autosuspend(dev->dev);
890-
891891
if (ret < 0)
892892
return ret;
893893
return num;

0 commit comments

Comments
 (0)