[PATCH 13/19] usb: typec: anx7411: zero on-stack alt mode descriptors

From: Greg Kroah-Hartman

Date: Tue Oct 27 2026 - 11:06:55 EST


From: Josef Bacik <josef@xxxxxxxxxxxxxx>

typec_port_register_altmodes() and anx7411_typec_register_altmode() fill a
struct typec_altmode_desc on the stack member by member: svid, vdo, mode.
typec_register_altmode() reads three more members:

- inactive: a port alternate mode is registered with active = !inactive.
If the byte of stack garbage is not 0, the mode starts disabled and
typec_altmode_enter() refuses it with -EPERM until somebody writes to
the "active" attribute of the port;
- mode_selection: the DisplayPort and Thunderbolt drivers enter the mode
on their own only if it is false. For the partner alternate modes of
anx7411, garbage there means that the mode is never entered;
- roles: decides what supported_roles of the port alternate mode shows.

typec_port_register_altmodes() is what tcpm and anx7411 register the
alternate modes of their ports with.
CONFIG_INIT_STACK_ALL_ZERO=y hides the problem.

Fixes: 183b194d8fb6 ("usb: typec: Make active on port altmode writable")
Fixes: be727d400066 ("usb: typec: Introduce mode_selection bit")
Fixes: 7b458a4c5d73 ("usb: typec: Add typec_port_register_altmodes()")
Cc: stable <stable@xxxxxxxxxx>
Cc: Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx>
Cc: Benson Leung <bleung@xxxxxxxxxxxx>
Signed-off-by: Josef Bacik <josef@xxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
drivers/usb/typec/anx7411.c | 2 +-
drivers/usb/typec/class.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/typec/anx7411.c b/drivers/usb/typec/anx7411.c
index 06c25af094b3..ac122ab3175a 100644
--- a/drivers/usb/typec/anx7411.c
+++ b/drivers/usb/typec/anx7411.c
@@ -552,7 +552,7 @@ static int anx7411_typec_register_altmode(struct anx7411_data *ctx,
int svid, int vdo)
{
struct device *dev = &ctx->spi_client->dev;
- struct typec_altmode_desc desc;
+ struct typec_altmode_desc desc = {};
int err;
int i;

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 54c7810b563b..9d9703c70820 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -2684,7 +2684,7 @@ void typec_port_register_altmodes(struct typec_port *port,
struct typec_altmode **altmodes, size_t n)
{
struct fwnode_handle *child;
- struct typec_altmode_desc desc;
+ struct typec_altmode_desc desc = {};
struct typec_altmode *alt;
size_t index = 0;
u16 svid;

--
2.56.0