Skip to contentSkip to conversation

usb: typec: tcpm: fix warning when handle discover_identity message

PATCH Superseded Xu Yang 3 participants 5 messages Feb 15, 2023 – Feb 16, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Xu Yang

author
#0 lore raw

PATCH 1/1 usb: typec: tcpm: fix warning when handle discover_identity message

Since both source and sink device can send discover_identity message in PD3, kernel may dump below warning:

------------[ cut here ]------------
WARNING: CPU: 0 PID: 169 at drivers/usb/typec/tcpm/tcpm.c:1446 tcpm_queue_vdm+0xe0/0xf0
Modules linked in:
CPU: 0 PID: 169 Comm: 1-0050 Not tainted 6.1.1-00038-g6a3c36cf1da2-dirty #567
Hardware name: NXP i.MX8MPlus EVK board (DT)
pstate: 20000005 (nzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : tcpm_queue_vdm+0xe0/0xf0
lr : tcpm_queue_vdm+0x2c/0xf0

sp : ffff80000c19bcd0
x29: ffff80000c19bcd0 x28: 0000000000000001 x27: ffff0000d11c8ab8
x26: ffff0000d11cc000 x25: 0000000000000000 x24: 00000000ff008081
x23: 0000000000000001 x22: 00000000ff00a081 x21: ffff80000c19bdbc
x20: 0000000000000000 x19: ffff0000d11c8080 x18: ffffffffffffffff
x17: 0000000000000000 x16: 0000000000000000 x15: ffff0000d716f580
x14: 0000000000000001 x13: ffff0000d716f507 x12: 0000000000000001
x11: 0000000000000000 x10: 0000000000000020 x9 : 00000000000ee098 x8 : 00000000ffffffff x7 : 000000000000001c x6 : ffff0000d716f580 x5 : 0000000000000000 x4 : 0000000000000000 x3 : 0000000000000000 x2 : ffff80000c19bdbc x1 : 00000000ff00a081 x0 : 0000000000000004

Call trace:
tcpm_queue_vdm+0xe0/0xf0
tcpm_pd_rx_handler+0x340/0x1ab0
kthread_worker_fn+0xcc/0x18c
kthread+0x10c/0x110
ret_from_fork+0x10/0x20
---[ end trace 0000000000000000 ]---

Below sequences may trigger this warning:

tcpm_send_discover_work(work)
tcpm_send_vdm(port, USB_SID_PD, CMD_DISCOVER_IDENT, NULL, 0);

   tcpm_queue_vdm(port, header, data, count);
    port->vdm_state = VDM_STATE_READY;

vdm_state_machine_work(work);
<-- received discover_identity from partner
vdm_run_state_machine(port);
port->vdm_state = VDM_STATE_SEND_MESSAGE;
mod_vdm_delayed_work(port, x);

tcpm_pd_rx_handler(work);
tcpm_pd_data_request(port, msg);
tcpm_handle_vdm_request(port, msg->payload, cnt);
tcpm_queue_vdm(port, response[0], &response[1], rlen - 1);
--> WARN_ON(port->vdm_state > VDM_STATE_DONE);

For this case, since the state machine could still send out discover identity message later if we skip current discover_identity message. So we should handle the received message firstly and override the pending discover_identity message without warning in this case. Then, a delayed send_discover work will send discover_identity message again.

Fixes e00943e91678 ("usb: typec: tcpm: PD3.0 sinks can send Discover Identity even in device mode")
---
 drivers/usb/typec/tcpm/tcpm.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +15 -3
index 7f39cb9b3429..914bbaf4e25e 100644
@@ -1445,10 +1445,19 @@ static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams)
 static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header,
 			   const u32 *data, int cnt)
 {
+	u32 vdo_hdr = port->vdo_data[0];
+
 	WARN_ON(!mutex_is_locked(&port->lock));
 
-	/* Make sure we are not still processing a previous VDM packet */
-	WARN_ON(port->vdm_state > VDM_STATE_DONE);
+	/* If is sending discover_identity, handle received message firstly */
+	if (PD_VDO_SVDM(vdo_hdr) &&
+		PD_VDO_CMD(vdo_hdr) == CMD_DISCOVER_IDENT) {
+		port->send_discover = true;
+		mod_send_discover_delayed_work(port,
+					SEND_DISCOVER_RETRY_MS);
+	} else
+		/* Make sure we are not still processing a previous VDM packet */
+		WARN_ON(port->vdm_state > VDM_STATE_DONE);
 
 	port->vdo_count = cnt + 1;
 	port->vdo_data[0] = header;
@@ -1950,9 +1959,11 @@ static void vdm_run_state_machine(struct tcpm_port *port)
 				res = tcpm_ams_start(port, DISCOVER_IDENTITY);
 				if (res == 0)
 					port->send_discover = false;
-				else if (res == -EAGAIN)
+				else if (res == -EAGAIN) {
+					port->vdo_data[0] = 0;
 					mod_send_discover_delayed_work(port,
 								       SEND_DISCOVER_RETRY_MS);
+				}
 				break;
 			case CMD_DISCOVER_SVID:
 				res = tcpm_ams_start(port, DISCOVER_SVIDS);
@@ -2035,6 +2046,7 @@ static void vdm_run_state_machine(struct tcpm_port *port)
 			unsigned long timeout;
 
 			port->vdm_retries = 0;
+			port->vdo_data[0] = 0;
 			port->vdm_state = VDM_STATE_BUSY;
 			timeout = vdm_ready_timeout(vdo_hdr);
 			mod_vdm_delayed_work(port, timeout);
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Hi,

Quoted 7 lines · Xu Yang
drivers/usb/typec/tcpm/tcpm.c +0 -0
index 7f39cb9b3429..914bbaf4e25e 100644
@@ -1445,10 +1445,19 @@ static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams)
 static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header,
 			   const u32 *data, int cnt)

drivers/usb/typec/tcpm/tcpm.c static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams) · line 1454

Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +5 -2
 {
+	u32 vdo_hdr = port->vdo_data[0];
+
 	WARN_ON(!mutex_is_locked(&port->lock));
 
-	/* Make sure we are not still processing a previous VDM packet */
-	WARN_ON(port->vdm_state > VDM_STATE_DONE);
+	/* If is sending discover_identity, handle received message firstly */
+	if (PD_VDO_SVDM(vdo_hdr) &&
+		PD_VDO_CMD(vdo_hdr) == CMD_DISCOVER_IDENT) {

One line is enough.

drivers/usb/typec/tcpm/tcpm.c static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams) · line 1457

Quoted 3 lines
drivers/usb/typec/tcpm/tcpm.c +3 -0
+		port->send_discover = true;
+		mod_send_discover_delayed_work(port,
+					SEND_DISCOVER_RETRY_MS);

Ditto.

drivers/usb/typec/tcpm/tcpm.c static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams) · line 1460

Quoted 3 lines
drivers/usb/typec/tcpm/tcpm.c +3 -0
+	} else
+		/* Make sure we are not still processing a previous VDM packet */
+		WARN_ON(port->vdm_state > VDM_STATE_DONE);

You need braces around the else statement in this case.

Quoted 17 lines
drivers/usb/typec/tcpm/tcpm.c +3 -1
 	port->vdo_count = cnt + 1;
 	port->vdo_data[0] = header;
@@ -1950,9 +1959,11 @@ static void vdm_run_state_machine(struct tcpm_port *port)
 				res = tcpm_ams_start(port, DISCOVER_IDENTITY);
 				if (res == 0)
 					port->send_discover = false;
-				else if (res == -EAGAIN)
+				else if (res == -EAGAIN) {
+					port->vdo_data[0] = 0;
 					mod_send_discover_delayed_work(port,
 								       SEND_DISCOVER_RETRY_MS);
+				}
 				break;
 			case CMD_DISCOVER_SVID:
 				res = tcpm_ams_start(port, DISCOVER_SVIDS);

drivers/usb/typec/tcpm/tcpm.c static void vdm_run_state_machine(struct tcpm_port *port) · line 2052

Quoted 7 lines
drivers/usb/typec/tcpm/tcpm.c +1 -0
@@ -2035,6 +2046,7 @@ static void vdm_run_state_machine(struct tcpm_port *port)
 			unsigned long timeout;
 
 			port->vdm_retries = 0;
+			port->vdo_data[0] = 0;
 			port->vdm_state = VDM_STATE_BUSY;
 			timeout = vdm_ready_timeout(vdo_hdr);
 			mod_vdm_delayed_work(port, timeout);

thanks,

Signature · 1 line
heikki
author
#2 lore raw

Hi Heikki,

Quoted 25 lines

-----Original Message-----
From: Heikki Krogerus <[email protected]>
Sent: Wednesday, February 15, 2023 9:42 PM
To: Xu Yang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; dl-linux-imx <[email protected]>; Jun Li <[email protected]>
Subject: [EXT] Re: [PATCH] usb: typec: tcpm: fix warning when handle discover_identity message

Caution: EXT Email

Hi,

Quoted 12 lines · Xu Yang
drivers/usb/typec/tcpm/tcpm.c +2 -0
index 7f39cb9b3429..914bbaf4e25e 100644
@@ -1445,10 +1445,19 @@ static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams)
 static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header,
                         const u32 *data, int cnt)
 {
+     u32 vdo_hdr = port->vdo_data[0];
+
      WARN_ON(!mutex_is_locked(&port->lock));
 
Quoted 7 lines

drivers/usb/typec/tcpm/tcpm.c static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams) · line 1454

Quoted 5 lines
drivers/usb/typec/tcpm/tcpm.c +3 -2
-     /* Make sure we are not still processing a previous VDM packet */
-     WARN_ON(port->vdm_state > VDM_STATE_DONE);
+     /* If is sending discover_identity, handle received message firstly */
+     if (PD_VDO_SVDM(vdo_hdr) &&
+             PD_VDO_CMD(vdo_hdr) == CMD_DISCOVER_IDENT) {

One line is enough.

Okay.

Quoted 6 lines

drivers/usb/typec/tcpm/tcpm.c static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams) · line 1457

Quoted 4 lines
drivers/usb/typec/tcpm/tcpm.c +3 -0
+             port->send_discover = true;
+             mod_send_discover_delayed_work(port,
+                                     SEND_DISCOVER_RETRY_MS);

Ditto.

Okay.

Quoted 6 lines

drivers/usb/typec/tcpm/tcpm.c static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams) · line 1460

Quoted 4 lines
drivers/usb/typec/tcpm/tcpm.c +3 -0
+     } else
+             /* Make sure we are not still processing a previous VDM packet */
+             WARN_ON(port->vdm_state > VDM_STATE_DONE);

You need braces around the else statement in this case.

Okay.

Quoted 20 lines
Quoted 20 lines
drivers/usb/typec/tcpm/tcpm.c +3 -1
      port->vdo_count = cnt + 1;
      port->vdo_data[0] = header;
@@ -1950,9 +1959,11 @@ static void vdm_run_state_machine(struct tcpm_port *port)
                              res = tcpm_ams_start(port, DISCOVER_IDENTITY);
                              if (res == 0)
                                      port->send_discover = false;
-                             else if (res == -EAGAIN)
+                             else if (res == -EAGAIN) {
+                                     port->vdo_data[0] = 0;
                                      mod_send_discover_delayed_work(port,
                                                                     SEND_DISCOVER_RETRY_MS);
+                             }
                              break;
                      case CMD_DISCOVER_SVID:
                              res = tcpm_ams_start(port, DISCOVER_SVIDS);
@@ -2035,6 +2046,7 @@ static void vdm_run_state_machine(struct tcpm_port *port)
                      unsigned long timeout;
 
Quoted 6 lines

drivers/usb/typec/tcpm/tcpm.c static void vdm_run_state_machine(struct tcpm_port *port) · line 2052

Quoted 5 lines
drivers/usb/typec/tcpm/tcpm.c +1 -0
                      port->vdm_retries = 0;
+                     port->vdo_data[0] = 0;
                      port->vdm_state = VDM_STATE_BUSY;
                      timeout = vdm_ready_timeout(vdo_hdr);
                      mod_vdm_delayed_work(port, timeout);

Thanks,
Xu Yang

Quoted 4 lines

thanks,

--
heikki

#3 lore raw
In reply to Xu Yang
Quoted 43 lines · Xu Yang

Since both source and sink device can send discover_identity message in PD3, kernel may dump below warning:

------------[ cut here ]------------
WARNING: CPU: 0 PID: 169 at drivers/usb/typec/tcpm/tcpm.c:1446 tcpm_queue_vdm+0xe0/0xf0
Modules linked in:
CPU: 0 PID: 169 Comm: 1-0050 Not tainted 6.1.1-00038-g6a3c36cf1da2-dirty #567
Hardware name: NXP i.MX8MPlus EVK board (DT)
pstate: 20000005 (nzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : tcpm_queue_vdm+0xe0/0xf0
lr : tcpm_queue_vdm+0x2c/0xf0

sp : ffff80000c19bcd0
x29: ffff80000c19bcd0 x28: 0000000000000001 x27: ffff0000d11c8ab8
x26: ffff0000d11cc000 x25: 0000000000000000 x24: 00000000ff008081
x23: 0000000000000001 x22: 00000000ff00a081 x21: ffff80000c19bdbc
x20: 0000000000000000 x19: ffff0000d11c8080 x18: ffffffffffffffff
x17: 0000000000000000 x16: 0000000000000000 x15: ffff0000d716f580
x14: 0000000000000001 x13: ffff0000d716f507 x12: 0000000000000001
x11: 0000000000000000 x10: 0000000000000020 x9 : 00000000000ee098 x8 : 00000000ffffffff x7 : 000000000000001c x6 : ffff0000d716f580 x5 : 0000000000000000 x4 : 0000000000000000 x3 : 0000000000000000 x2 : ffff80000c19bdbc x1 : 00000000ff00a081 x0 : 0000000000000004

Call trace:
tcpm_queue_vdm+0xe0/0xf0
tcpm_pd_rx_handler+0x340/0x1ab0
kthread_worker_fn+0xcc/0x18c
kthread+0x10c/0x110
ret_from_fork+0x10/0x20
---[ end trace 0000000000000000 ]---

Below sequences may trigger this warning:

tcpm_send_discover_work(work)

   tcpm_send_vdm(port, USB_SID_PD, CMD_DISCOVER_IDENT, NULL, 0);
    tcpm_queue_vdm(port, header, data, count);
     port->vdm_state = VDM_STATE_READY;

vdm_state_machine_work(work);
<-- received discover_identity from partner

  vdm_run_state_machine(port);
   port->vdm_state = VDM_STATE_SEND_MESSAGE;
    mod_vdm_delayed_work(port, x);
Quoted 8 lines

tcpm_pd_rx_handler(work);

  tcpm_pd_data_request(port, msg);
   tcpm_handle_vdm_request(port, msg->payload, cnt);
    tcpm_queue_vdm(port, response[0], &response[1], rlen - 1);

--> WARN_ON(port->vdm_state > VDM_STATE_DONE);

For this case, since the state machine could still send out discover identity message later if we skip current discover_identity message.

the second part of "since" is missing. since ... what ?

If this is supposed to be "since ... we should handle", just drop the "since".

Quoted 16 lines

So we should handle the received message firstly and override the pending discover_identity message without warning in this case. Then, a delayed send_discover work will send discover_identity message again.

Fixes e00943e91678 ("usb: typec: tcpm: PD3.0 sinks can send Discover Identity even in device mode")
---
  drivers/usb/typec/tcpm/tcpm.c | 18 +++++++++++++++---
  1 file changed, 15 insertions(+), 3 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +0 -0
index 7f39cb9b3429..914bbaf4e25e 100644

drivers/usb/typec/tcpm/tcpm.c static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams) · line 1452

Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +3 -2
@@ -1445,10 +1445,19 @@ static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams)
  static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header,
  			   const u32 *data, int cnt)
  {
+	u32 vdo_hdr = port->vdo_data[0];
+
  	WARN_ON(!mutex_is_locked(&port->lock));
 
-	/* Make sure we are not still processing a previous VDM packet */
-	WARN_ON(port->vdm_state > VDM_STATE_DONE);
+	/* If is sending discover_identity, handle received message firstly */

firstly -> first

Quoted 12 lines
drivers/usb/typec/tcpm/tcpm.c +8 -0
+	if (PD_VDO_SVDM(vdo_hdr) &&
+		PD_VDO_CMD(vdo_hdr) == CMD_DISCOVER_IDENT) {
+		port->send_discover = true;
+		mod_send_discover_delayed_work(port,
+					SEND_DISCOVER_RETRY_MS);
+	} else
+		/* Make sure we are not still processing a previous VDM packet */
+		WARN_ON(port->vdm_state > VDM_STATE_DONE);
 
  	port->vdo_count = cnt + 1;
  	port->vdo_data[0] = header;

drivers/usb/typec/tcpm/tcpm.c static void vdm_run_state_machine(struct tcpm_port *port) · line 1966

Quoted 9 lines
drivers/usb/typec/tcpm/tcpm.c +3 -1
@@ -1950,9 +1959,11 @@ static void vdm_run_state_machine(struct tcpm_port *port)
  				res = tcpm_ams_start(port, DISCOVER_IDENTITY);
  				if (res == 0)
  					port->send_discover = false;
-				else if (res == -EAGAIN)
+				else if (res == -EAGAIN) {
+					port->vdo_data[0] = 0;
  					mod_send_discover_delayed_work(port,
  								       SEND_DISCOVER_RETRY_MS);
+				}

Both sides of if/else should have braces.

Quoted 11 lines
drivers/usb/typec/tcpm/tcpm.c +1 -0
  				break;
  			case CMD_DISCOVER_SVID:
  				res = tcpm_ams_start(port, DISCOVER_SVIDS);
@@ -2035,6 +2046,7 @@ static void vdm_run_state_machine(struct tcpm_port *port)
  			unsigned long timeout;
 
  			port->vdm_retries = 0;
+			port->vdo_data[0] = 0;
  			port->vdm_state = VDM_STATE_BUSY;
  			timeout = vdm_ready_timeout(vdo_hdr);
  			mod_vdm_delayed_work(port, timeout);
author
#4 lore raw

Hi Guenter,

Quoted 59 lines

-----Original Message-----
From: Guenter Roeck <[email protected]> On Behalf Of Guenter Roeck
Sent: Wednesday, February 15, 2023 11:27 PM
To: Xu Yang <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>; Jun Li <[email protected]>
Subject: [EXT] Re: [PATCH] usb: typec: tcpm: fix warning when handle discover_identity message

Caution: EXT Email

Quoted 49 lines · Xu Yang

Since both source and sink device can send discover_identity message in PD3, kernel may dump below warning:

------------[ cut here ]------------
WARNING: CPU: 0 PID: 169 at drivers/usb/typec/tcpm/tcpm.c:1446 tcpm_queue_vdm+0xe0/0xf0
Modules linked in:
CPU: 0 PID: 169 Comm: 1-0050 Not tainted 6.1.1-00038-g6a3c36cf1da2-dirty #567
Hardware name: NXP i.MX8MPlus EVK board (DT)
pstate: 20000005 (nzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
pc : tcpm_queue_vdm+0xe0/0xf0
lr : tcpm_queue_vdm+0x2c/0xf0

sp : ffff80000c19bcd0
x29: ffff80000c19bcd0 x28: 0000000000000001 x27: ffff0000d11c8ab8
x26: ffff0000d11cc000 x25: 0000000000000000 x24: 00000000ff008081
x23: 0000000000000001 x22: 00000000ff00a081 x21: ffff80000c19bdbc
x20: 0000000000000000 x19: ffff0000d11c8080 x18: ffffffffffffffff
x17: 0000000000000000 x16: 0000000000000000 x15: ffff0000d716f580
x14: 0000000000000001 x13: ffff0000d716f507 x12: 0000000000000001
x11: 0000000000000000 x10: 0000000000000020 x9 : 00000000000ee098 x8 : 00000000ffffffff x7 : 000000000000001c x6 : ffff0000d716f580 x5 : 0000000000000000 x4 : 0000000000000000 x3 : 0000000000000000 x2 : ffff80000c19bdbc x1 : 00000000ff00a081 x0 : 0000000000000004

Call trace:
tcpm_queue_vdm+0xe0/0xf0
tcpm_pd_rx_handler+0x340/0x1ab0
kthread_worker_fn+0xcc/0x18c
kthread+0x10c/0x110
ret_from_fork+0x10/0x20
---[ end trace 0000000000000000 ]---

Below sequences may trigger this warning:

tcpm_send_discover_work(work)

   tcpm_send_vdm(port, USB_SID_PD, CMD_DISCOVER_IDENT, NULL, 0);
    tcpm_queue_vdm(port, header, data, count);
     port->vdm_state = VDM_STATE_READY;

vdm_state_machine_work(work);
<-- received discover_identity from partner

  vdm_run_state_machine(port);
   port->vdm_state = VDM_STATE_SEND_MESSAGE;
    mod_vdm_delayed_work(port, x);

tcpm_pd_rx_handler(work);

  tcpm_pd_data_request(port, msg);
   tcpm_handle_vdm_request(port, msg->payload, cnt);
    tcpm_queue_vdm(port, response[0], &response[1], rlen - 1);

--> WARN_ON(port->vdm_state > VDM_STATE_DONE);

Quoted 7 lines
Quoted 2 lines

For this case, since the state machine could still send out discover identity message later if we skip current discover_identity message.

the second part of "since" is missing. since ... what ?

If this is supposed to be "since ... we should handle", just drop the "since".

Okay.

Quoted 24 lines
Quoted 24 lines

So we should handle the received message firstly and override the pending discover_identity message without warning in this case. Then, a delayed send_discover work will send discover_identity message again.

Fixes e00943e91678 ("usb: typec: tcpm: PD3.0 sinks can send Discover Identity even in device mode")
---
  drivers/usb/typec/tcpm/tcpm.c | 18 +++++++++++++++---
  1 file changed, 15 insertions(+), 3 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +2 -0
index 7f39cb9b3429..914bbaf4e25e 100644
@@ -1445,10 +1445,19 @@ static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams)
  static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header,
                         const u32 *data, int cnt)
  {
+     u32 vdo_hdr = port->vdo_data[0];
+
      WARN_ON(!mutex_is_locked(&port->lock));
 
Quoted 5 lines

drivers/usb/typec/tcpm/tcpm.c static int tcpm_ams_start(struct tcpm_port *port, enum tcpm_ams ams) · line 1452

Quoted 3 lines
drivers/usb/typec/tcpm/tcpm.c +1 -2
-     /* Make sure we are not still processing a previous VDM packet */
-     WARN_ON(port->vdm_state > VDM_STATE_DONE);
+     /* If is sending discover_identity, handle received message firstly */

firstly -> first

Okay.

Quoted 10 lines
Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +8 -0
+     if (PD_VDO_SVDM(vdo_hdr) &&
+             PD_VDO_CMD(vdo_hdr) == CMD_DISCOVER_IDENT) {
+             port->send_discover = true;
+             mod_send_discover_delayed_work(port,
+                                     SEND_DISCOVER_RETRY_MS);
+     } else
+             /* Make sure we are not still processing a previous VDM packet */
+             WARN_ON(port->vdm_state > VDM_STATE_DONE);
 
Quoted 15 lines

drivers/usb/typec/tcpm/tcpm.c static void vdm_run_state_machine(struct tcpm_port *port) · line 1966

Quoted 12 lines
drivers/usb/typec/tcpm/tcpm.c +3 -1
      port->vdo_count = cnt + 1;
      port->vdo_data[0] = header;
@@ -1950,9 +1959,11 @@ static void vdm_run_state_machine(struct tcpm_port *port)
                              res = tcpm_ams_start(port, DISCOVER_IDENTITY);
                              if (res == 0)
                                      port->send_discover = false;
-                             else if (res == -EAGAIN)
+                             else if (res == -EAGAIN) {
+                                     port->vdo_data[0] = 0;
                                      mod_send_discover_delayed_work(port,
                                                                     SEND_DISCOVER_RETRY_MS);
+                             }

Both sides of if/else should have braces.

Will change.

Quoted 7 lines
Quoted 7 lines
drivers/usb/typec/tcpm/tcpm.c +0 -0
                              break;
                      case CMD_DISCOVER_SVID:
                              res = tcpm_ams_start(port, DISCOVER_SVIDS);
@@ -2035,6 +2046,7 @@ static void vdm_run_state_machine(struct tcpm_port *port)
                      unsigned long timeout;
 
Quoted 5 lines

drivers/usb/typec/tcpm/tcpm.c static void vdm_run_state_machine(struct tcpm_port *port) · line 2052

Quoted 5 lines
drivers/usb/typec/tcpm/tcpm.c +1 -0
                      port->vdm_retries = 0;
+                     port->vdo_data[0] = 0;
                      port->vdm_state = VDM_STATE_BUSY;
                      timeout = vdm_ready_timeout(vdo_hdr);
                      mod_vdm_delayed_work(port, timeout);

Thanks,
Xu Yang