Skip to contentSkip to conversation

usb: typec: ucsi: Only set number of plug altmodes after registration

PATCH In review Jameson Thies 4 participants 4 messages Jun 25, 2024

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

PATCH 1/1 usb: typec: ucsi: Only set number of plug altmodes after registration

Move the setting of the plug's number of alternate modes into the same condition as the plug's registration to prevent dereferencing the connector's plug pointer while it is null.

Fixes c313a44ac9cd ("usb: typec: ucsi: Always set number of alternate modes")
---
 drivers/usb/typec/ucsi/ucsi.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/typec/ucsi/ucsi.c +6 -6
index 76c48d873b2a..77e46bf4a098 100644
@@ -1180,13 +1180,13 @@ static int ucsi_check_cable(struct ucsi_connector *con)
 		ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
 		if (ret < 0)
 			return ret;
-	}
 
-	if (con->plug_altmode[0]) {
-		num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
-		typec_plug_set_num_altmodes(con->plug, num_plug_am);
-	} else {
-		typec_plug_set_num_altmodes(con->plug, 0);
+		if (con->plug_altmode[0]) {
+			num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
+			typec_plug_set_num_altmodes(con->plug, num_plug_am);
+		} else {
+			typec_plug_set_num_altmodes(con->plug, 0);
+		}
 	}
 
 	return 0;

base-commit: 819984a0dd3606b7c46fe156cd56a0dc0d604788

Signature · 1 line
2.45.2.741.gdbec12cfda-goog
Reviewed-by on v1 1/1
#1 lore raw

Hi Jameson,

Quoted 7 lines · Jameson Thies

Move the setting of the plug's number of alternate modes into the same condition as the plug's registration to prevent dereferencing the connector's plug pointer while it is null.

Fixes c313a44ac9cd ("usb: typec: ucsi: Always set number of alternate modes")

Thanks,
Benson

Quoted 33 lines
---
 drivers/usb/typec/ucsi/ucsi.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/typec/ucsi/ucsi.c +6 -6
index 76c48d873b2a..77e46bf4a098 100644
@@ -1180,13 +1180,13 @@ static int ucsi_check_cable(struct ucsi_connector *con)
 		ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
 		if (ret < 0)
 			return ret;
-	}
 
-	if (con->plug_altmode[0]) {
-		num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
-		typec_plug_set_num_altmodes(con->plug, num_plug_am);
-	} else {
-		typec_plug_set_num_altmodes(con->plug, 0);
+		if (con->plug_altmode[0]) {
+			num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
+			typec_plug_set_num_altmodes(con->plug, num_plug_am);
+		} else {
+			typec_plug_set_num_altmodes(con->plug, 0);
+		}
 	}
 
 	return 0;

base-commit: 819984a0dd3606b7c46fe156cd56a0dc0d604788

Signature · 1 line
2.45.2.741.gdbec12cfda-goog
maintainer Tested-by Reviewed-by on v1 1/1
#2 lore raw
In reply to Jameson Thies
Quoted 36 lines · Jameson Thies

Move the setting of the plug's number of alternate modes into the same condition as the plug's registration to prevent dereferencing the connector's plug pointer while it is null.

Fixes c313a44ac9cd ("usb: typec: ucsi: Always set number of alternate modes")
---
  drivers/usb/typec/ucsi/ucsi.c | 12 ++++++------
  1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/typec/ucsi/ucsi.c +6 -6
index 76c48d873b2a..77e46bf4a098 100644
@@ -1180,13 +1180,13 @@ static int ucsi_check_cable(struct ucsi_connector *con)
  		ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
  		if (ret < 0)
  			return ret;
-	}
 
-	if (con->plug_altmode[0]) {
-		num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
-		typec_plug_set_num_altmodes(con->plug, num_plug_am);
-	} else {
-		typec_plug_set_num_altmodes(con->plug, 0);
+		if (con->plug_altmode[0]) {
+			num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
+			typec_plug_set_num_altmodes(con->plug, num_plug_am);
+		} else {
+			typec_plug_set_num_altmodes(con->plug, 0);
+		}
  	}
 
  	return 0;
Quoted 1 line

base-commit: 819984a0dd3606b7c46fe156cd56a0dc0d604788

Fixes it for me!

Thanks!
Jon

Signature · 1 line
nvpublic
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Jameson Thies
Quoted 7 lines · Jameson Thies

Move the setting of the plug's number of alternate modes into the same condition as the plug's registration to prevent dereferencing the connector's plug pointer while it is null.

Fixes c313a44ac9cd ("usb: typec: ucsi: Always set number of alternate modes")
Quoted 32 lines
---
 drivers/usb/typec/ucsi/ucsi.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/usb/typec/ucsi/ucsi.c +6 -6
index 76c48d873b2a..77e46bf4a098 100644
@@ -1180,13 +1180,13 @@ static int ucsi_check_cable(struct ucsi_connector *con)
 		ret = ucsi_register_altmodes(con, UCSI_RECIPIENT_SOP_P);
 		if (ret < 0)
 			return ret;
-	}
 
-	if (con->plug_altmode[0]) {
-		num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
-		typec_plug_set_num_altmodes(con->plug, num_plug_am);
-	} else {
-		typec_plug_set_num_altmodes(con->plug, 0);
+		if (con->plug_altmode[0]) {
+			num_plug_am = ucsi_get_num_altmode(con->plug_altmode);
+			typec_plug_set_num_altmodes(con->plug, num_plug_am);
+		} else {
+			typec_plug_set_num_altmodes(con->plug, 0);
+		}
 	}
 
 	return 0;

base-commit: 819984a0dd3606b7c46fe156cd56a0dc0d604788

Signature · 1 line
2.45.2.741.gdbec12cfda-goog
Signature · 1 line
heikki