Skip to contentSkip to conversation

usb: typec: mux: initialize orientation switch array

PATCH In review Haobo Cheng 2 participants 2 messages Aug 4 – Aug 5

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

PATCH 1/1 usb: typec: mux: initialize orientation switch array

Commit a53b4f9c51a9 ("usb: typec: mux: avoid duplicated orientation switches") started using the orientation switch result array as state for duplicate detection, but left the array uninitialized.

The first match therefore scans indeterminate stack contents before any result has been stored. A valid orientation switch may be incorrectly discarded as a duplicate, causing fwnode_typec_switch_get() to return no switch.

Zero-initialize the array before collecting matches.

Fixes a53b4f9c51a9 ("usb: typec: mux: avoid duplicated orientation switches")
---
 drivers/usb/typec/mux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/typec/mux.c +1 -1
index 9b908c46b..55dab1c76 100644
@@ -79,7 +79,7 @@ static void *typec_switch_match(const struct fwnode_handle *fwnode,
  */
 struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
 {
-	struct typec_switch_dev *sw_devs[TYPEC_MUX_MAX_DEVS];
+	struct typec_switch_dev *sw_devs[TYPEC_MUX_MAX_DEVS] = { };
 	struct typec_switch *sw;
 	int count;
 	int err;
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 9 lines · Haobo Cheng

Commit a53b4f9c51a9 ("usb: typec: mux: avoid duplicated orientation switches") started using the orientation switch result array as state for duplicate detection, but left the array uninitialized.

The first match therefore scans indeterminate stack contents before any result has been stored. A valid orientation switch may be incorrectly discarded as a duplicate, causing fwnode_typec_switch_get() to return no switch.

Quoted 5 lines

Zero-initialize the array before collecting matches.

Fixes a53b4f9c51a9 ("usb: typec: mux: avoid duplicated orientation switches")

---

oops.

Greetings,

-- Sebastian

Quoted 19 lines
 drivers/usb/typec/mux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/typec/mux.c +1 -1
index 9b908c46b..55dab1c76 100644
@@ -79,7 +79,7 @@ static void *typec_switch_match(const struct fwnode_handle *fwnode,
  */
 struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
 {
-	struct typec_switch_dev *sw_devs[TYPEC_MUX_MAX_DEVS];
+	struct typec_switch_dev *sw_devs[TYPEC_MUX_MAX_DEVS] = { };
 	struct typec_switch *sw;
 	int count;
 	int err;
Signature · 1 line
2.53.0