i2c: imx: Switch to new reg_target/unreg_target callbacks
PATCH 1/1 i2c: imx: Switch to new reg_target/unreg_target callbacks
The reg_slave and unreg_slave members of i2c_algorithm are deprecated and will be removed. The i.MX I2C driver still uses the old names for both the struct members and the callback implementations.
Switch to the new reg_target and unreg_target members, and rename the corresponding callback functions from reg_slave/unreg_slave to reg_target/unreg_target. This aligns the driver with the ongoing terminology migration in the I2C subsystem and avoids future build issues.
--- drivers/i2c/busses/i2c-imx.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-imx.c +4 -4
@@ -922,7 +922,7 @@ static void i2c_imx_slave_init(struct imx_i2c_struct *i2c_imx)i2c_imx_enable_bus_idle (i2c_imx); } -static int i2c_imx_reg_slave (struct i2c_client *client) +static int i2c_imx_reg_target (struct i2c_client *client) {struct imx_i2c_struct *i2c_imx =i2c_get_adapdata (client->adapter);int ret;
@@ -945,7 +945,7 @@ static int i2c_imx_reg_slave(struct i2c_client *client)return 0 ; } -static int i2c_imx_unreg_slave (struct i2c_client *client) +static int i2c_imx_unreg_target (struct i2c_client *client) {struct imx_i2c_struct *i2c_imx =i2c_get_adapdata (client->adapter);int ret;
@@ -1704,8 +1704,8 @@ static const struct i2c_algorithm i2c_imx_algo = { .xfer = i2c_imx_xfer, .xfer_atomic = i2c_imx_xfer_atomic, .functionality = i2c_imx_func, - .reg_slave = i2c_imx_reg_slave, - .unreg_slave = i2c_imx_unreg_slave, + .reg_target = i2c_imx_reg_target, + .unreg_target = i2c_imx_unreg_target, };static int i2c_imx_probe (struct platform_device *pdev)
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] i2c_imx_reg_target leaves a dangling pointer on pm_runtime_resume_and_get failure, leading to state inconsistency and potential UAF/NULL pointer dereference.
- [High] Missing lock acquisition and timer cancellation in i2c_imx_unreg_target causes data races and guaranteed NULL pointer dereference during concurrent slave transactions. --
(Due to recitation policy restrictions, this report does not quote the original patch code inline and instead provides a free-form summary of the findings.)
commit e5a765606d0417cc96ddfca98fce10ada4405f48
Author: Liem <[email protected]>
i2c: imx: Switch to new reg_target/unreg_target callbacks
This commit updates the i.MX I2C driver to use the new reg_target and unreg_target callbacks instead of the deprecated reg_slave and unreg_slave names.
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the changes to the newly renamed i2c_imx_reg_target function, I noticed a potential pre-existing issue.
If pm_runtime_resume_and_get() fails, the function returns immediately without resetting i2c_imx->slave back to NULL. Does this leave a dangling pointer in the state structure?
If so, future slave registration attempts might permanently fail with -EBUSY. Furthermore, since the I2C core sets client->slave_cb to NULL on error, if a shared interrupt fires, could i2c_imx_slave_handle() dereference the dangling i2c_imx->slave and invoke i2c_slave_event() with a NULL callback, potentially causing a panic?
[Severity: High]
This is a pre-existing issue, but I also spotted a potential synchronization flaw in the newly renamed i2c_imx_unreg_target function.
The function sets i2c_imx->slave = NULL without taking i2c_imx->slave_lock and without cancelling i2c_imx->slave_timer. If unregistration happens during an active slave transaction (for example, during a driver unbind), could this lead to a race condition with the timer?
Specifically, unreg_target disables the module and clears i2c_imx->slave. If the concurrent slave_timer fires and runs i2c_imx_slave_timeout(), reading the disabled I2SR yields 0 (meaning the bus is no longer busy). This leads i2c_imx_slave_handle() to invoke i2c_imx_slave_finish_op(). Since the transaction was abruptly interrupted, it will then call i2c_imx_slave_event(). Will this pass the now-NULL i2c_imx->slave to i2c_slave_event(), resulting in a NULL pointer dereference?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Subject: Re: [PATCH] i2c: imx: Switch to new reg_target/unreg_target callbacks
Hi Sashiko AI and all,
Thank you for the thorough review and for catching these issues.
Both the dangling pointer on pm_runtime_resume_and_get() failure in i2c_imx_reg_target() and the missing lock/timer cancellation in i2c_imx_unreg_target() are pre-existing problems that were already present before this patch. My commit only renames the deprecated function pointers and their implementations, without modifying any of the underlying logic.
I agree these are real issues that should be fixed. I'll prepare a separate follow-up patch to address them, keeping this first patch focused solely on the terminology migration.
Thanks again,
Liem