[PATCH] usb: typec: altmodes/displayport: Drop the device reference in dp_altmode_probe()

Haoxiang Li posted 1 patch 1 week, 6 days ago
drivers/usb/typec/altmodes/displayport.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
[PATCH] usb: typec: altmodes/displayport: Drop the device reference in dp_altmode_probe()
Posted by Haoxiang Li 1 week, 6 days ago
In error paths, call typec_altmode_put_plug() to drop the device reference
obtained by typec_altmode_get_plug().

Fixes: 71ba4fe56656 ("usb: typec: altmodes/displayport: add SOP' support")
Cc: stable@vger.kernel.org
Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
---
 drivers/usb/typec/altmodes/displayport.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
index 1dcb77faf85d..5d02c97e256e 100644
--- a/drivers/usb/typec/altmodes/displayport.c
+++ b/drivers/usb/typec/altmodes/displayport.c
@@ -764,12 +764,16 @@ int dp_altmode_probe(struct typec_altmode *alt)
 	if (!(DP_CAP_PIN_ASSIGN_DFP_D(port->vdo) &
 	      DP_CAP_PIN_ASSIGN_UFP_D(alt->vdo)) &&
 	    !(DP_CAP_PIN_ASSIGN_UFP_D(port->vdo) &
-	      DP_CAP_PIN_ASSIGN_DFP_D(alt->vdo)))
-		return -ENODEV;
+	      DP_CAP_PIN_ASSIGN_DFP_D(alt->vdo))) {
+		typec_altmode_put_plug(plug);
+		return -ENODEV;
+	}
 
 	dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL);
-	if (!dp)
+	if (!dp) {
+		typec_altmode_put_plug(plug);
 		return -ENOMEM;
+	}
 
 	INIT_WORK(&dp->work, dp_altmode_work);
 	mutex_init(&dp->lock);
-- 
2.25.1
Re: [PATCH] usb: typec: altmodes/displayport: Drop the device reference in dp_altmode_probe()
Posted by Heikki Krogerus 1 week ago
Sat, Dec 06, 2025 at 03:04:45PM +0800, Haoxiang Li kirjoitti:
> In error paths, call typec_altmode_put_plug() to drop the device reference
> obtained by typec_altmode_get_plug().
> 
> Fixes: 71ba4fe56656 ("usb: typec: altmodes/displayport: add SOP' support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/altmodes/displayport.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
> index 1dcb77faf85d..5d02c97e256e 100644
> --- a/drivers/usb/typec/altmodes/displayport.c
> +++ b/drivers/usb/typec/altmodes/displayport.c
> @@ -764,12 +764,16 @@ int dp_altmode_probe(struct typec_altmode *alt)
>  	if (!(DP_CAP_PIN_ASSIGN_DFP_D(port->vdo) &
>  	      DP_CAP_PIN_ASSIGN_UFP_D(alt->vdo)) &&
>  	    !(DP_CAP_PIN_ASSIGN_UFP_D(port->vdo) &
> -	      DP_CAP_PIN_ASSIGN_DFP_D(alt->vdo)))
> -		return -ENODEV;
> +	      DP_CAP_PIN_ASSIGN_DFP_D(alt->vdo))) {
> +		typec_altmode_put_plug(plug);
> +		return -ENODEV;
> +	}
>  
>  	dp = devm_kzalloc(&alt->dev, sizeof(*dp), GFP_KERNEL);
> -	if (!dp)
> +	if (!dp) {
> +		typec_altmode_put_plug(plug);
>  		return -ENOMEM;
> +	}
>  
>  	INIT_WORK(&dp->work, dp_altmode_work);
>  	mutex_init(&dp->lock);
> -- 
> 2.25.1

-- 
heikki