extcon: ptn5150: request the IRQ after the resources its work uses
Subsystems (3)
PATCH 1/1 extcon: ptn5150: request the IRQ after the resources its work uses
The IRQ is requested before the work cleanup action is registered. On unbind, devres cancels irq_work and releases its switches before freeing the IRQ, allowing an interrupt to queue work against released resources. Earlier probe failures can leave the work uncancelled.
Request the IRQ after registering the cleanup action so devres frees it before cancelling the work and releasing its resources. Keep ptn5150_init_dev_type() after the IRQ request: clearing pending status before installing the falling-edge handler can lose an interrupt.
Found by a static analysis tool under development.
Compile-tested with W=1 for arm64 and x86_64.
Not tested on hardware.
---
drivers/extcon/extcon-ptn5150.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
drivers/extcon/extcon-ptn5150.c +15 -15
@@ -307,16 +307,6 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c) } } - ret =devm_request_threaded_irq (dev, info->irq,NULL , - ptn5150_irq_handler, -IRQF_TRIGGER_FALLING | -IRQF_ONESHOT , - i2c->name, info); -if (ret <0 ) { -dev_err (dev,"failed to request handler for INTB IRQ\n" ); -return ret; - } -/* Allocate extcon device */ info->edev =devm_extcon_dev_allocate (info->dev, ptn5150_extcon_cable);if (IS_ERR (info->edev)) {
@@ -338,11 +328,6 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)extcon_set_property_capability (info->edev,EXTCON_USB_HOST ,EXTCON_PROP_USB_TYPEC_POLARITY ); -/* Initialize PTN5150 device and print vendor id and version id */ - ret =ptn5150_init_dev_type (info); -if (ret) -return -EINVAL ; - connector =device_get_named_child_node (dev,"connector" );if (connector) { info->orient_sw =fwnode_typec_switch_get (connector);
@@ -362,6 +347,21 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)if (ret)return ret; + ret =devm_request_threaded_irq (dev, info->irq,NULL , + ptn5150_irq_handler, +IRQF_TRIGGER_FALLING | +IRQF_ONESHOT , + i2c->name, info); +if (ret <0 ) { +dev_err (dev,"failed to request handler for INTB IRQ\n" ); +return ret; + } + +/* Initialize PTN5150 device and print vendor id and version id */ + ret =ptn5150_init_dev_type (info); +if (ret) +return -EINVAL ; +/* * Update current extcon state if for example OTG connection was there * before the probe
base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47
Signature · 1 line
2.43.0
Quoted 11 lines · Myeonghun Pak
The IRQ is requested before the work cleanup action is registered. On unbind, devres cancels
irq_workand releases its switches before freeing the IRQ, allowing an interrupt to queue work against released resources. Earlier probe failures can leave the work uncancelled.Request the IRQ after registering the cleanup action so devres frees it before cancelling the work and releasing its resources. Keep
ptn5150_init_dev_type()after the IRQ request: clearing pending status before installing the falling-edge handler can lose an interrupt.Found by a static analysis tool under development.
LLM is not a static analysis tool. Mentioning unknown tool is pointless.
Quoted 3 lines
Compile-tested with W=1 for arm64 and
x86_64.
Not tested on hardware.
Drop from commit msg. Such information goes to changelog, not commit msg.
Quoted 3 lines
Fixes 782cd939cbe0 ("extcon: ptn5150: Add queue work sync before driver release")
With above fixed:
Best regards,
Krzysztof
Hi!
Quoted 12 lines · Myeonghun Pak
The IRQ is requested before the work cleanup action is registered. On unbind, devres cancels
irq_workand releases its switches before freeing the IRQ, allowing an interrupt to queue work against released resources. Earlier probe failures can leave the work uncancelled.Request the IRQ after registering the cleanup action so devres frees it before cancelling the work and releasing its resources. Keep
ptn5150_init_dev_type()after the IRQ request: clearing pending status before installing the falling-edge handler can lose an interrupt.Found by a static analysis tool under development.
Quoted 8 lines
Compile-tested with W=1 for arm64 and
x86_64.
Not tested on hardware.Fixes 782cd939cbe0 ("extcon: ptn5150: Add queue work sync before driver release")Co-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>
Reminds me of my patch from Jan 26 [1].
I'm guilty of mixing two issues into one patch though.
I actually expected the patch to land somewhere after almost a year in extcon-testing, but it seems to jsut disappear?
[1] https://lore.kernel.org/all/[email protected]/
Quoted 62 lines
---
drivers/extcon/extcon-ptn5150.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)drivers/extcon/extcon-ptn5150.c +15
-15@@ -307,16 +307,6 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c) } } - ret =devm_request_threaded_irq (dev, info->irq,NULL , - ptn5150_irq_handler, -IRQF_TRIGGER_FALLING | -IRQF_ONESHOT , - i2c->name, info); -if (ret <0 ) { -dev_err (dev,"failed to request handler for INTB IRQ\n" ); -return ret; - } -/* Allocate extcon device */ info->edev =devm_extcon_dev_allocate (info->dev, ptn5150_extcon_cable);if (IS_ERR (info->edev)) {@@ -338,11 +328,6 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)extcon_set_property_capability (info->edev,EXTCON_USB_HOST ,EXTCON_PROP_USB_TYPEC_POLARITY ); -/* Initialize PTN5150 device and print vendor id and version id */ - ret =ptn5150_init_dev_type (info); -if (ret) -return -EINVAL ; - connector =device_get_named_child_node (dev,"connector" );if (connector) { info->orient_sw =fwnode_typec_switch_get (connector);@@ -362,6 +347,21 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)if (ret)return ret; + ret =devm_request_threaded_irq (dev, info->irq,NULL , + ptn5150_irq_handler, +IRQF_TRIGGER_FALLING | +IRQF_ONESHOT , + i2c->name, info); +if (ret <0 ) { +dev_err (dev,"failed to request handler for INTB IRQ\n" ); +return ret; + } + +/* Initialize PTN5150 device and print vendor id and version id */ + ret =ptn5150_init_dev_type (info); +if (ret) +return -EINVAL ; +/* * Update current extcon state if for example OTG connection was there * before the probe base-commit:
630059a5a632377b9b7b487baccde92b7ae1dd47
Signature · 3 lines
Alexander Sverdlin Siemens AG www.siemens.com
Hi Ijae, Myeonghun, Chanwoo!
Quoted 74 lines · Alexander Sverdlin
Hi!
Quoted 12 lines · Myeonghun Pak
The IRQ is requested before the work cleanup action is registered. On unbind, devres cancels
irq_workand releases its switches before freeing the IRQ, allowing an interrupt to queue work against released resources. Earlier probe failures can leave the work uncancelled.Request the IRQ after registering the cleanup action so devres frees it before cancelling the work and releasing its resources. Keep
ptn5150_init_dev_type()after the IRQ request: clearing pending status before installing the falling-edge handler can lose an interrupt.Found by a static analysis tool under development.
Quoted 8 lines
Compile-tested with W=1 for arm64 and
x86_64.
Not tested on hardware.Fixes 782cd939cbe0 ("extcon: ptn5150: Add queue work sync before driver release")Co-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>Reminds me of my patch from Jan 26 [1].
I'm guilty of mixing two issues into one patch though.I actually expected the patch to land somewhere after almost a year in extcon-testing, but it seems to jsut disappear?
[1] https://lore.kernel.org/all/[email protected]/
Quoted 42 lines
---
drivers/extcon/extcon-ptn5150.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)drivers/extcon/extcon-ptn5150.c +0
-15@@ -307,16 +307,6 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c) } } - ret =devm_request_threaded_irq (dev, info->irq,NULL , - ptn5150_irq_handler, -IRQF_TRIGGER_FALLING | -IRQF_ONESHOT , - i2c->name, info); -if (ret <0 ) { -dev_err (dev,"failed to request handler for INTB IRQ\n" ); -return ret; - } -/* Allocate extcon device */ info->edev =devm_extcon_dev_allocate (info->dev, ptn5150_extcon_cable);if (IS_ERR (info->edev)) {@@ -338,11 +328,6 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)extcon_set_property_capability (info->edev,EXTCON_USB_HOST ,EXTCON_PROP_USB_TYPEC_POLARITY ); -/* Initialize PTN5150 device and print vendor id and version id */ - ret =ptn5150_init_dev_type (info); -if (ret) -return -EINVAL ; - connector =device_get_named_child_node (dev,"connector" );if (connector) { info->orient_sw =fwnode_typec_switch_get (connector);@@ -362,6 +347,21 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)if (ret)return ret;
Quoted 15 lines
Quoted 5 lines
drivers/extcon/extcon-ptn5150.c +5
-0+ ret =devm_request_threaded_irq (dev, info->irq,NULL , + ptn5150_irq_handler, +IRQF_TRIGGER_FALLING | +IRQF_ONESHOT , + i2c->name, info);drivers/extcon/extcon-ptn5150.c static int ptn5150_i2c_probe(struct i2c_client *i2c) · line 364
Quoted 10 lines
drivers/extcon/extcon-ptn5150.c +10
-0+if (ret <0 ) { +dev_err (dev,"failed to request handler for INTB IRQ\n" ); +return ret; + } + +/* Initialize PTN5150 device and print vendor id and version id */ + ret =ptn5150_init_dev_type (info); +if (ret) +return -EINVAL ; +
Thanks Chanwoo for merging c5cc8c44b7ae, which is now available in next-20261202!
Just wanted to return to the review of this patch:
I believe, if Ijae or Myeonghun would rebase it, only ptn5150_init_dev_type() movement would remain but exactly this part, I believe, might be not required:
it would preserve any pending pre-probe interrupt and would eventually result in ptn5150_irq_work() calling ptn5150_check_state(), but exactly this already happens as the very last action of ptn5150_i2c_probe().
So in my opinion, this patch now might be obsolete.
Quoted 5 lines
Quoted 5 lines
drivers/extcon/extcon-ptn5150.c +0
-0/* * Update current extcon state if for example OTG connection was there * before the probe base-commit:
630059a5a632377b9b7b487baccde92b7ae1dd47
Signature · 3 lines
Alexander Sverdlin Siemens AG www.siemens.com