Skip to contentSkip to conversation

input: synaptics_i2c - cancel delayed work before freeing device

PATCH In review Minseong Kim 3 participants 6 messages Dec 10, 2025 – Jan 21

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 input: synaptics_i2c - cancel delayed work before freeing device

synaptics_i2c_irq() schedules touch->dwork via mod_delayed_work(). The delayed work performs I2C transactions and may still be running (or get queued) when the device is removed.

synaptics_i2c_remove() currently frees 'touch' without canceling touch->dwork. If removal happens while the work is pending/running, the work handler may dereference freed memory, leading to a potential use-after-free.

Cancel the delayed work synchronously before unregistering/freeing the device.

Fixes eef3e4cab72e Input: add driver for Synaptics I2C touchpad
---
 drivers/input/mouse/synaptics_i2c.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/input/mouse/synaptics_i2c.c +2 -0
index a0d707e47d93..fe30bf9aea3a 100644
@@ -593,6 +593,8 @@ static void synaptics_i2c_remove(struct i2c_client *client)
 	if (!polling_req)
 		free_irq(client->irq, touch);
 
+	cancel_delayed_work_sync(&touch->dwork);
+
 	input_unregister_device(touch->input);
 	kfree(touch);
 }
Signature · 1 line
2.39.5
maintainer
#1 lore raw

Hi Minseong,

Quoted 25 lines · Minseong Kim

synaptics_i2c_irq() schedules touch->dwork via mod_delayed_work(). The delayed work performs I2C transactions and may still be running (or get queued) when the device is removed.

synaptics_i2c_remove() currently frees 'touch' without canceling touch->dwork. If removal happens while the work is pending/running, the work handler may dereference freed memory, leading to a potential use-after-free.

Cancel the delayed work synchronously before unregistering/freeing the device.

Fixes eef3e4cab72e Input: add driver for Synaptics I2C touchpad
---
 drivers/input/mouse/synaptics_i2c.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/input/mouse/synaptics_i2c.c +0 -0
index a0d707e47d93..fe30bf9aea3a 100644

drivers/input/mouse/synaptics_i2c.c static void synaptics_i2c_remove(struct i2c_client *client) · line 597

Quoted 5 lines
drivers/input/mouse/synaptics_i2c.c +2 -0
@@ -593,6 +593,8 @@ static void synaptics_i2c_remove(struct i2c_client *client)
 	if (!polling_req)
 		free_irq(client->irq, touch);
 
+	cancel_delayed_work_sync(&touch->dwork);
+

The call to cancel_delayed_work_sync() happens in the close() handler for the device. I see that in resume we restart the polling without checking if the device is opened, so if we want to fix it we should add the checks there.

However support for the PXA board using in the device with this touch controller (eXeda) was removed a while ago. Mike, you're one of the authors, any objections to simply removing the driver?

Thanks.

Signature · 1 line
Dmitry
#2 lore raw

Hi Dmitry,

Thanks for the review.

Understood that cancel_delayed_work_sync() is already called from the close() handler, and that resume() can restart polling regardless of open state. If we keep this driver, I can send a v2 that adds an open-state guard in resume().

However, if this driver is no longer used and Mike confirms there are no remaining users, I have no objections to removing it instead.

Thanks,
Minseong

#3 lore raw
In reply to Dmitry Torokhov

Hi,

Quoted 39 lines · Dmitry Torokhov

Hi Minseong,

Quoted 25 lines · Minseong Kim

synaptics_i2c_irq() schedules touch->dwork via mod_delayed_work(). The delayed work performs I2C transactions and may still be running (or get queued) when the device is removed.

synaptics_i2c_remove() currently frees 'touch' without canceling touch->dwork. If removal happens while the work is pending/running, the work handler may dereference freed memory, leading to a potential use-after-free.

Cancel the delayed work synchronously before unregistering/freeing the device.

Fixes eef3e4cab72e Input: add driver for Synaptics I2C touchpad
---
 drivers/input/mouse/synaptics_i2c.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/input/mouse/synaptics_i2c.c +0 -0
index a0d707e47d93..fe30bf9aea3a 100644

drivers/input/mouse/synaptics_i2c.c static void synaptics_i2c_remove(struct i2c_client *client) · line 597

Quoted 5 lines
drivers/input/mouse/synaptics_i2c.c +2 -0
@@ -593,6 +593,8 @@ static void synaptics_i2c_remove(struct i2c_client *client)
 	if (!polling_req)
 		free_irq(client->irq, touch);
 
+	cancel_delayed_work_sync(&touch->dwork);
+

The call to cancel_delayed_work_sync() happens in the close() handler for the device. I see that in resume we restart the polling without checking if the device is opened, so if we want to fix it we should add the checks there.

Quoted 3 lines

However support for the PXA board using in the device with this touch controller (eXeda) was removed a while ago. Mike, you're one of the authors, any objections to simply removing the driver?

No objections from my side.

Quoted 4 lines

Thanks.

Signature · 1 line
Dmitry
Signature · 2 lines
Sincerely yours,
Mike.
maintainer
#4 lore raw
Quoted 42 lines · Mike Rapoport

Hi,

Quoted 39 lines · Dmitry Torokhov

Hi Minseong,

Quoted 25 lines · Minseong Kim

synaptics_i2c_irq() schedules touch->dwork via mod_delayed_work(). The delayed work performs I2C transactions and may still be running (or get queued) when the device is removed.

synaptics_i2c_remove() currently frees 'touch' without canceling touch->dwork. If removal happens while the work is pending/running, the work handler may dereference freed memory, leading to a potential use-after-free.

Cancel the delayed work synchronously before unregistering/freeing the device.

Fixes eef3e4cab72e Input: add driver for Synaptics I2C touchpad
---
 drivers/input/mouse/synaptics_i2c.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/input/mouse/synaptics_i2c.c +0 -0
index a0d707e47d93..fe30bf9aea3a 100644

drivers/input/mouse/synaptics_i2c.c static void synaptics_i2c_remove(struct i2c_client *client) · line 597

Quoted 5 lines
drivers/input/mouse/synaptics_i2c.c +2 -0
@@ -593,6 +593,8 @@ static void synaptics_i2c_remove(struct i2c_client *client)
 	if (!polling_req)
 		free_irq(client->irq, touch);
 
+	cancel_delayed_work_sync(&touch->dwork);
+

The call to cancel_delayed_work_sync() happens in the close() handler for the device. I see that in resume we restart the polling without checking if the device is opened, so if we want to fix it we should add the checks there.

Quoted 5 lines
Quoted 3 lines

However support for the PXA board using in the device with this touch controller (eXeda) was removed a while ago. Mike, you're one of the authors, any objections to simply removing the driver?

No objections from my side.

Hmm, it looks like it is still referenced from
arch/arm/boot/dts/nxp/mxs/imx23-sansa.dts

Marek, is this device still relevant?

Thanks.

Signature · 1 line
Dmitry
maintainer
#5 lore raw
Quoted 47 lines · Dmitry Torokhov
Quoted 46 lines · Mike Rapoport

Hi,

Quoted 42 lines · Dmitry Torokhov

Hi Minseong,

Quoted 25 lines · Minseong Kim

synaptics_i2c_irq() schedules touch->dwork via mod_delayed_work(). The delayed work performs I2C transactions and may still be running (or get queued) when the device is removed.

synaptics_i2c_remove() currently frees 'touch' without canceling touch->dwork. If removal happens while the work is pending/running, the work handler may dereference freed memory, leading to a potential use-after-free.

Cancel the delayed work synchronously before unregistering/freeing the device.

Fixes eef3e4cab72e Input: add driver for Synaptics I2C touchpad
---
 drivers/input/mouse/synaptics_i2c.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/input/mouse/synaptics_i2c.c +0 -0
index a0d707e47d93..fe30bf9aea3a 100644

drivers/input/mouse/synaptics_i2c.c static void synaptics_i2c_remove(struct i2c_client *client) · line 597

Quoted 5 lines
drivers/input/mouse/synaptics_i2c.c +2 -0
@@ -593,6 +593,8 @@ static void synaptics_i2c_remove(struct i2c_client *client)
 	if (!polling_req)
 		free_irq(client->irq, touch);
 
+	cancel_delayed_work_sync(&touch->dwork);
+

The call to cancel_delayed_work_sync() happens in the close() handler for the device. I see that in resume we restart the polling without checking if the device is opened, so if we want to fix it we should add the checks there.

However support for the PXA board using in the device with this touch controller (eXeda) was removed a while ago. Mike, you're one of the authors, any objections to simply removing the driver?

Quoted 6 lines
Quoted 1 line

No objections from my side.

Hmm, it looks like it is still referenced from
arch/arm/boot/dts/nxp/mxs/imx23-sansa.dts

Marek, is this device still relevant?

I see these devices (SanDisk Sansa Fuze+) for sale on e-bay, so I guess there is a chance it will be used...

Minseong, could you please prepare a v2 that would check if the device is opened in resume before restarting polling? It should take input device's mutex and then use input_device_enabled().

Thanks.

Signature · 1 line
Dmitry