USB: cdc-acm: fix minor-number release
Subsystems (3)
PATCH 1/1 USB: cdc-acm: fix minor-number release
If the driver runs out of minor numbers it would release minor 0 and allow another device to claim the minor while still in use.
Fortunately, registering the tty class device of the second device would fail (with a stack dump) due to the sysfs name collision so no memory is leaked.
--- drivers/usb/class/cdc-acm.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/class/cdc-acm.c +5 -2
@@ -726,7 +726,8 @@ static void acm_port_destruct(struct tty_port *port) { struct acm *acm = container_of(port, struct acm, port); -acm_release_minor (acm); +if (acm->minor !=ACM_TTY_MINORS ) +acm_release_minor (acm);usb_put_intf (acm->control);kfree (acm->country_codes);kfree (acm);
@@ -1323,8 +1324,10 @@ static int acm_probe(struct usb_interface *intf,usb_get_intf (acm->control);/* undone in destruct() */ minor =acm_alloc_minor (acm); -if (minor <0 ) +if (minor <0 ) { + acm->minor =ACM_TTY_MINORS ; goto err_put_port; + } acm->minor = minor; acm->dev = usb_dev;
Signature · 1 line
2.32.0
Oliver Neukum
maintainerdrivers/usb/class/cdc-acm.c static int acm_probe(struct usb_interface *intf, · line 1329
Quoted 8 lines · Johan Hovold
drivers/usb/class/cdc-acm.c +2
-1@@ -1323,8 +1324,10 @@ static int acm_probe(struct usb_interface *intf,usb_get_intf (acm->control);/* undone in destruct() */ minor =acm_alloc_minor (acm); -if (minor <0 ) +if (minor <0 ) { + acm->minor =ACM_TTY_MINORS ; goto err_put_port;
Hi,
Congratulations for catching that one.
May I request to improve understandability of the code that you give the constant a distinct name for this purpose? Something like
ACM_MINOR_POISON or ACM_INVALID_MINOR
so that normal people can understand the fixed code?
Regards
Oliver
Quoted 5 lines · Oliver Neukum
Quoted 3 lines · Johan Hovold
drivers/usb/class/cdc-acm.c +0
-0@@ -1323,8 +1324,10 @@ static int acm_probe(struct usb_interface *intf,usb_get_intf (acm->control);/* undone in destruct() */
Quoted 7 lines
drivers/usb/class/cdc-acm.c static int acm_probe(struct usb_interface *intf, · line 1329
Quoted 5 lines
drivers/usb/class/cdc-acm.c +2
-1minor =acm_alloc_minor (acm); -if (minor <0 ) +if (minor <0 ) { + acm->minor =ACM_TTY_MINORS ; goto err_put_port;Congratulations for catching that one.
Heh, thanks.
Quoted 6 lines
May I request to improve understandability of the code that you give the constant a distinct name for this purpose? Something like
ACM_MINOR_POISONorACM_INVALID_MINORso that normal people can understand the fixed code?
Sure, I'll use ACM_MINOR_INVALID.
Johan