Skip to contentSkip to conversation

USB: serial: bus: fix const issue in usb_serial_device_match()

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

Subsystems (2)
lore
Share & tools
lore

Greg Kroah-Hartman

author maintainer
#0 lore raw

PATCH 1/1 USB: serial: bus: fix const issue in usb_serial_device_match()

usb_serial_device_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/serial/bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/serial/bus.c +1 -1
index 2fea1b1db4a2..9e2a18c0b218 100644
@@ -17,7 +17,7 @@ static int usb_serial_device_match(struct device *dev,
 				   const struct device_driver *drv)
 {
 	const struct usb_serial_port *port = to_usb_serial_port(dev);
-	struct usb_serial_driver *driver = to_usb_serial_driver(drv);
+	const struct usb_serial_driver *driver = to_usb_serial_driver(drv);
 
 	/*
 	 * drivers are already assigned to ports in serial_probe so it's
Signature · 1 line
2.49.0
maintainer
#1 lore raw
Quoted 4 lines · Greg Kroah-Hartman

usb_serial_device_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.

I think this deserves a Fixes tag as this is a recent issue introduced by commit d69d80484598 ("driver core: have match() callback in struct bus_type take a const *") (even if we only use the address of the pointer).

drivers/usb/serial/bus.c static int usb_serial_device_match(struct device *dev, · line 23

Quoted 12 lines
drivers/usb/serial/bus.c +1 -1
@@ -17,7 +17,7 @@ static int usb_serial_device_match(struct device *dev,
 				   const struct device_driver *drv)
 {
 	const struct usb_serial_port *port = to_usb_serial_port(dev);
-	struct usb_serial_driver *driver = to_usb_serial_driver(drv);
+	const struct usb_serial_driver *driver = to_usb_serial_driver(drv);
 
 	/*
 	 * drivers are already assigned to ports in serial_probe so it's

Now applied with a Fixes tag added.

Johan

author maintainer
#2 lore raw
Quoted 10 lines · Johan Hovold
Quoted 4 lines · Greg Kroah-Hartman

usb_serial_device_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.

I think this deserves a Fixes tag as this is a recent issue introduced by commit d69d80484598 ("driver core: have match() callback in struct bus_type take a const *") (even if we only use the address of the pointer).

Oops, yes, that is needed, sorry about that.

Quoted 10 lines
Quoted 10 lines
drivers/usb/serial/bus.c +1 -1
@@ -17,7 +17,7 @@ static int usb_serial_device_match(struct device *dev,
 				   const struct device_driver *drv)
 {
 	const struct usb_serial_port *port = to_usb_serial_port(dev);
-	struct usb_serial_driver *driver = to_usb_serial_driver(drv);
+	const struct usb_serial_driver *driver = to_usb_serial_driver(drv);
 
Quoted 4 lines

drivers/usb/serial/bus.c static int usb_serial_device_match(struct device *dev, · line 23

Quoted 2 lines
drivers/usb/serial/bus.c +0 -0
 	/*
 	 * drivers are already assigned to ports in serial_probe so it's

Now applied with a Fixes tag added.

Great, thanks!

greg k-h