Skip to content

Commit

Permalink
USB: cdc-acm: fix minor-number release
Browse files Browse the repository at this point in the history
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.

Fixes: cae2bc7 ("usb: cdc-acm: Decrement tty port's refcount if probe() fail")
Cc: [email protected]      # 4.19
Cc: Jaejoong Kim <[email protected]>
Acked-by: Oliver Neukum <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
jhovold authored and gregkh committed Sep 14, 2021
1 parent 856e6e8 commit 91fac07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/usb/class/cdc-acm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_MINOR_INVALID)
acm_release_minor(acm);
usb_put_intf(acm->control);
kfree(acm->country_codes);
kfree(acm);
Expand Down Expand Up @@ -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_MINOR_INVALID;
goto err_put_port;
}

acm->minor = minor;
acm->dev = usb_dev;
Expand Down
2 changes: 2 additions & 0 deletions drivers/usb/class/cdc-acm.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#define ACM_TTY_MAJOR 166
#define ACM_TTY_MINORS 256

#define ACM_MINOR_INVALID ACM_TTY_MINORS

/*
* Requests.
*/
Expand Down

0 comments on commit 91fac07

Please sign in to comment.