Skip to contentSkip to conversation

USB: serial: drop bogus to_usb_serial_port() checks

PATCH In review Johan Hovold 3 participants 4 messages Feb 8, 2021 – Feb 9, 2021

Subsystems (2)
lore
Share & tools
lore

Johan Hovold

author maintainer
#0 lore raw

PATCH 1/1 USB: serial: drop bogus to_usb_serial_port() checks

The to_usb_serial_port() macro is implemented using container_of() so there's no need to check for NULL.

Note that neither bus match() or probe() is ever called with a NULL struct device pointer so the checks weren't just misplaced.

---
 drivers/usb/serial/bus.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
drivers/usb/serial/bus.c +3 -13
index 1a8c7821d00a..7133818a58b9 100644
@@ -16,19 +16,13 @@
 static int usb_serial_device_match(struct device *dev,
 						struct device_driver *drv)
 {
-	struct usb_serial_driver *driver;
-	const struct usb_serial_port *port;
+	const struct usb_serial_port *port = to_usb_serial_port(dev);
+	struct usb_serial_driver *driver = to_usb_serial_driver(drv);
 
 	/*
 	 * drivers are already assigned to ports in serial_probe so it's
 	 * a simple check here.
 	 */
-	port = to_usb_serial_port(dev);
-	if (!port)
-		return 0;
-
-	driver = to_usb_serial_driver(drv);
-
 	if (driver == port->serial->type)
 		return 1;
 
@@ -37,16 +31,12 @@ static int usb_serial_device_match(struct device *dev,
 
 static int usb_serial_device_probe(struct device *dev)
 {
+	struct usb_serial_port *port = to_usb_serial_port(dev);
 	struct usb_serial_driver *driver;
-	struct usb_serial_port *port;
 	struct device *tty_dev;
 	int retval = 0;
 	int minor;
 
-	port = to_usb_serial_port(dev);
-	if (!port)
-		return -ENODEV;
-
 	/* make sure suspend/resume doesn't race against port_probe */
 	retval = usb_autopm_get_interface(port->serial->interface);
 	if (retval)
Signature · 1 line
2.26.2
author maintainer
#3 lore raw
Quoted 10 lines · Uwe Kleine-König
Quoted 7 lines · Johan Hovold

The to_usb_serial_port() macro is implemented using container_of() so there's no need to check for NULL.

Note that neither bus match() or probe() is ever called with a NULL struct device pointer so the checks weren't just misplaced.

Thanks Uwe and Greg for reviewing. Now applied.

Johan