Devicetree
 help / color / mirror / Atom feed
* [PATCH 1/2] dt-bindings: extcon: ptn5150: Document CON_DET enable
@ 2026-11-29 17:19 Marek Vasut
  2026-11-29 17:19 ` [PATCH 2/2] extcon: ptn5150: Make CON_DET configurable Marek Vasut
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Vasut @ 2026-11-29 17:19 UTC (permalink / raw)
  To: linux-usb
  Cc: Marek Vasut, Chanwoo Choi, Conor Dooley, Krzysztof Kozlowski,
	MyungJoo Ham, Rob Herring, devicetree, linux-kernel

Document boolean property "nxp,con-det-enable", which selects whether the
CON_DET signal is output on Pin 5 of the chip. Chip default is disabled,
which is also the behavior when the property is not present.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Chanwoo Choi <cw00.choi@samsung.com>
Cc: Conor Dooley <conor+dt@kernel.org>
Cc: Krzysztof Kozlowski <krzk@kernel.org>
Cc: MyungJoo Ham <myungjoo.ham@samsung.com>
Cc: Rob Herring <robh@kernel.org>
Cc: devicetree@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 Documentation/devicetree/bindings/extcon/extcon-ptn5150.yaml | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Documentation/devicetree/bindings/extcon/extcon-ptn5150.yaml b/Documentation/devicetree/bindings/extcon/extcon-ptn5150.yaml
index 79f88b5f4e5cc..dc7af415e4dee 100644
--- a/Documentation/devicetree/bindings/extcon/extcon-ptn5150.yaml
+++ b/Documentation/devicetree/bindings/extcon/extcon-ptn5150.yaml
@@ -45,6 +45,11 @@ properties:
   connector:
     $ref: /schemas/connector/usb-connector.yaml#
 
+  nxp,con-det-enable:
+    type: boolean
+    description:
+      Enable CON_DET output on pin 5.
+
 required:
   - compatible
   - interrupts
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] extcon: ptn5150: Make CON_DET configurable
  2026-11-29 17:19 [PATCH 1/2] dt-bindings: extcon: ptn5150: Document CON_DET enable Marek Vasut
@ 2026-11-29 17:19 ` Marek Vasut
  2026-11-29 17:26   ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Vasut @ 2026-11-29 17:19 UTC (permalink / raw)
  To: linux-usb
  Cc: Marek Vasut, Chanwoo Choi, Conor Dooley, Krzysztof Kozlowski,
	MyungJoo Ham, Rob Herring, devicetree, linux-kernel

Handle boolean property "nxp,con-det-enable", which selects whether the
CON_DET signal is output on Pin 5 of the chip. Chip default is disabled,
which is also the behavior when the property is not present.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Chanwoo Choi <cw00.choi@samsung.com>
Cc: Conor Dooley <conor+dt@kernel.org>
Cc: Krzysztof Kozlowski <krzk@kernel.org>
Cc: MyungJoo Ham <myungjoo.ham@samsung.com>
Cc: Rob Herring <robh@kernel.org>
Cc: devicetree@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/extcon/extcon-ptn5150.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c
index 0b96b58b42124..f15c585f817ab 100644
--- a/drivers/extcon/extcon-ptn5150.c
+++ b/drivers/extcon/extcon-ptn5150.c
@@ -45,6 +45,7 @@
 #define PTN5150_REG_CC_PORT_ATTACHMENT		GENMASK(4, 2)
 #define PTN5150_REG_CC_POLARITY			GENMASK(1, 0)
 #define PTN5150_REG_CC_VBUS_DETECTION		BIT(7)
+#define PTN5150_REG_CON_DET_DIS			BIT(0)
 #define PTN5150_REG_INT_CABLE_ATTACH_MASK	BIT(0)
 #define PTN5150_REG_INT_CABLE_DETACH_MASK	BIT(1)
 
@@ -362,6 +363,11 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)
 	if (ret)
 		return ret;
 
+	if (device_property_present(&i2c->dev, "nxp,con-det-enable")) {
+		regmap_clear_bits(info->regmap, PTN5150_REG_CON_DET,
+				  PTN5150_REG_CON_DET_DIS);
+	}
+
 	/*
 	 * Update current extcon state if for example OTG connection was there
 	 * before the probe
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 2/2] extcon: ptn5150: Make CON_DET configurable
  2026-11-29 17:19 ` [PATCH 2/2] extcon: ptn5150: Make CON_DET configurable Marek Vasut
@ 2026-11-29 17:26   ` sashiko-bot
  0 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-29 17:26 UTC (permalink / raw)
  To: Marek Vasut; +Cc: devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] extcon: ptn5150: unchecked regmap_clear_bits() return in
  ptn5150_i2c_probe()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [Critical] extcon: ptn5150: orient_sw leak and irq_work race in
  ptn5150_i2c_probe() [1]
--

commit aeab3d399b32bd1935fe640269c15aa72b9b637c
Author: Marek Vasut <marek.vasut+renesas@mailbox.org>

extcon: ptn5150: Make CON_DET configurable

This commit adds support for the "nxp,con-det-enable" boolean property to
enable the CON_DET output signal on the PTN5150 chip during probe.

> diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c
> index eca1b140aeb0f..7d462680dd88e 100644
> --- a/drivers/extcon/extcon-ptn5150.c
> +++ b/drivers/extcon/extcon-ptn5150.c

[ ... ]

> @@ -362,6 +363,11 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c)
>  	if (ret)
>  		return ret;

[Severity: Critical]
This problem wasn't introduced by this patch, but registering
ptn5150_work_sync_and_put() via devm_add_action_or_reset() here is ordered
after devm_request_threaded_irq() and after acquiring info->orient_sw
[1]:

drivers/extcon/extcon-ptn5150.c:ptn5150_i2c_probe() {
    ...
	ret = devm_request_threaded_irq(dev, info->irq, NULL,
					ptn5150_irq_handler, ...);
    ...
	if (connector) {
		info->orient_sw = fwnode_typec_switch_get(connector);
		if (IS_ERR(info->orient_sw))
			return dev_err_probe(...);
	}

	info->role_sw = usb_role_switch_get(info->dev);
	if (!info->role_sw && connector)
		info->role_sw = fwnode_usb_role_switch_get(connector);
	if (IS_ERR(info->role_sw))
		return dev_err_probe(...);

	ret = devm_add_action_or_reset(dev, ptn5150_work_sync_and_put, info);
    ...
}

Because devres runs teardown actions in reverse order, could an interrupt
fire after ptn5150_work_sync_and_put() runs and before the IRQ is freed?

CPU0                                  CPU1
ptn5150_work_sync_and_put()
  cancel_work_sync(&info->irq_work)
  usb_role_switch_put(info->role_sw)
  typec_switch_put(info->orient_sw)
                                      ptn5150_irq_handler()
                                        schedule_work(&info->irq_work)
devm_irq_release()
devm kfree(info)
                                      ptn5150_irq_work()
                                        mutex_lock(&info->mutex)
                                          <-- use-after-free

In addition, if acquiring info->role_sw fails, probe returns before
ptn5150_work_sync_and_put() is registered, leaking info->orient_sw and
leaving any already-scheduled info->irq_work uncanceled.

> +
> +	if (device_property_present(&i2c->dev, "nxp,con-det-enable")) {
> +		regmap_clear_bits(info->regmap, PTN5150_REG_CON_DET,
> +				  PTN5150_REG_CON_DET_DIS);
> +	}

[Severity: Low]
Should the return value of regmap_clear_bits() be checked and propagated?
If the I2C transfer fails, probe will succeed with CON_DET still disabled.

[1] https://sashiko.dev/#/bug/linux-475a50da-a64e-4ed0-a654-d7f65166df20

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261129171935.280160-1-marek.vasut+renesas@mailbox.org?part=2

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-29 17:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 17:19 [PATCH 1/2] dt-bindings: extcon: ptn5150: Document CON_DET enable Marek Vasut
2026-11-29 17:19 ` [PATCH 2/2] extcon: ptn5150: Make CON_DET configurable Marek Vasut
2026-11-29 17:26   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox