linux-stable/drivers/usb/typec
Xu Yang abfc4fa28f 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, 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: e00943e916 ("usb: typec: tcpm: PD3.0 sinks can send Discover Identity even in device mode")
cc: <stable@vger.kernel.org>
Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20230216031515.4151117-1-xu.yang_2@nxp.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-03-09 15:15:28 +01:00
..
altmodes Merge 6.2-rc8 into usb-next 2023-02-14 13:44:08 +01:00
mux usb: typec: mux: Introduce GPIO-based SBU mux 2023-01-24 18:15:28 +01:00
tcpm usb: typec: tcpm: fix warning when handle discover_identity message 2023-03-09 15:15:28 +01:00
tipd usb: typec: tipd: Support wakeup 2023-01-17 17:23:47 +01:00
ucsi usb: ucsi_acpi: Increase the command completion timeout 2023-03-09 14:39:20 +01:00
Kconfig usb: typec: anx7411: Fix build error without CONFIG_POWER_SUPPLY 2022-09-22 15:21:03 +02:00
Makefile usb: typec: Add support for retimers 2022-07-14 16:24:05 +02:00
anx7411.c usb: typec: anx7411: Convert to i2c's .probe_new() 2022-11-22 17:33:27 +01:00
bus.c Driver core changes for 6.3-rc1 2023-02-24 12:58:55 -08:00
bus.h usb: typec: Add retimer handle to port altmode 2023-01-17 17:29:00 +01:00
class.c Driver core changes for 6.3-rc1 2023-02-24 12:58:55 -08:00
class.h usb: typec: Add retimer handle to port 2022-07-14 16:24:05 +02:00
hd3ss3220.c usb: typec: hd3ss3220: Add polling support 2023-01-17 17:18:51 +01:00
mux.c device property: Constify fwnode connection match APIs 2022-10-22 13:49:55 +02:00
mux.h usb: typec: mux: Introduce indirection 2022-04-26 13:47:13 +02:00
pd.c usb: typec: pd: Add higher capability sysfs for sink PDO 2023-02-15 19:03:47 +01:00
pd.h usb: typec: Separate USB Power Delivery from USB Type-C 2022-06-12 06:49:47 +02:00
port-mapper.c ACPI: bus: Introduce acpi_bus_for_each_dev() 2022-03-02 20:55:47 +01:00
qcom-pmic-typec.c usb: typec: qcom-pmic-typec: Switch to use dev_err_probe() helper 2022-09-27 10:35:46 +02:00
retimer.c Driver Core changes for 6.2-rc1 2022-12-16 03:54:54 -08:00
retimer.h usb: typec: Make bus switch code retimer-aware 2023-01-17 17:29:00 +01:00
rt1719.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
stusb160x.c USB/Thunderbolt changes for 6.1-rc1 2022-10-07 16:48:26 -07:00
wusb3801.c usb: typec: wusb3801: fix fwnode refcount leak in wusb3801_probe() 2022-12-08 16:43:22 +01:00