Skip to contentSkip to conversation

USB: typec: fix const issue in typec_match()

PATCH In review Greg Kroah-Hartman 2 participants 3 messages May 21, 2025 – May 22, 2025

Subsystems (2)
lore
Share & tools
lore

Greg Kroah-Hartman

author maintainer
#0 lore raw

PATCH 1/1 USB: typec: fix const issue in typec_match()

typec_match() takes a const pointer, and then decides to cast it away into a non-const one, which is not a good thing to do overall. Fix this up by properly setting the pointers to be const to preserve that attribute.

---
 drivers/usb/typec/bus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/typec/bus.c +2 -2
index ae90688d23e4..91eae95d6fa4 100644
@@ -449,8 +449,8 @@ ATTRIBUTE_GROUPS(typec);
 
 static int typec_match(struct device *dev, const struct device_driver *driver)
 {
-	struct typec_altmode_driver *drv = to_altmode_driver(driver);
-	struct typec_altmode *altmode = to_typec_altmode(dev);
+	const struct typec_altmode_driver *drv = to_altmode_driver(driver);
+	const struct typec_altmode *altmode = to_typec_altmode(dev);
 	const struct typec_device_id *id;
 
 	for (id = drv->id_table; id->svid; id++)
Signature · 1 line
2.49.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

Hi Greg,

Quoted 7 lines · Greg Kroah-Hartman

typec_match() takes a const pointer, and then decides to cast it away into a non-const one, which is not a good thing to do overall. Fix this up by properly setting the pointers to be const to preserve that attribute.

Shouldn't there be a Fixes tag? git blame gives commit d69d804845985

thanks,

Quoted 22 lines
---
 drivers/usb/typec/bus.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/typec/bus.c +2 -2
index ae90688d23e4..91eae95d6fa4 100644
@@ -449,8 +449,8 @@ ATTRIBUTE_GROUPS(typec);
 
 static int typec_match(struct device *dev, const struct device_driver *driver)
 {
-	struct typec_altmode_driver *drv = to_altmode_driver(driver);
-	struct typec_altmode *altmode = to_typec_altmode(dev);
+	const struct typec_altmode_driver *drv = to_altmode_driver(driver);
+	const struct typec_altmode *altmode = to_typec_altmode(dev);
 	const struct typec_device_id *id;
 
 	for (id = drv->id_table; id->svid; id++)
Signature · 1 line
2.49.0
Signature · 1 line
heikki
author maintainer
#2 lore raw
Quoted 8 lines · Heikki Krogerus

Hi Greg,

Quoted 5 lines · Greg Kroah-Hartman

typec_match() takes a const pointer, and then decides to cast it away into a non-const one, which is not a good thing to do overall. Fix this up by properly setting the pointers to be const to preserve that attribute.

Quoted 4 lines
Quoted 2 lines

Shouldn't there be a Fixes tag? git blame gives commit d69d804845985

Yes, as Johan pointed out, this is my fault :) I'll add that when I commit this.

Quoted 1 line

thanks for the review!

greg k-h