USB: cdc-acm: fix double usb_autopm_put_interface() in acm_port_activate()

If acm_submit_read_urbs() fails in acm_port_activate(), error handling
code calls usb_autopm_put_interface() while it is already called
before acm_submit_read_urbs(). The patch reorganizes error handling code
to avoid double decrement of USB interface's PM-usage counter.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <khoroshilov@ispras.ru>
Acked-by: Oliver Neukum <oliver@neukum.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 070c0b17f6a1ba39dff9be112218127e7e8fd456)
USB: cdc-acm: fix open and suspend race

We must not do the usb_autopm_put_interface() before submitting the read
urbs or we might end up doing I/O to a suspended device.

Fixes: 088c64f81284 ("USB: cdc-acm: re-write read processing")
Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 703df3297fb1950b0aa53e656108eb936d3f21d9)
USB: cdc-acm: fix failed open not being detected

Fix errors during open not being returned to userspace. Specifically,
failed control-line manipulations or control or read urb submissions
would not be detected.

Fixes: 7fb57a019f94 ("USB: cdc-acm: Fix potential deadlock (lockdep
warning)")

Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 8727bf689a77a79816065e23a7a58a474ad544f9)
USB: cdc-acm: simplify runtime PM locking

We can simply the runtime PM locking as there's no need to check the
susp_count in the read path (at least not since killing the rx tasklet).

Specifically, the read urbs will never be resubmitted by the completion
handler when killed during suspend.

Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit bbf0cb3e93a1b6ef8bf22a67f35d7c98ef378f2b)
USB: cdc-acm: remove redundant disconnected test from shutdown

Remove redundant disconnect test from shutdown(), which is never called
post disconnect() where we do synchronous hangup.

Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 89e54e4468338df5a4ab7627c5b8b10786ee43e8)
USB: cdc-acm: minimise no-suspend window during shutdown

Now that acm_set_control() handles runtime PM properly, the only
remaining reason for the PM operations in shutdown is to clear the
needs_remote_wakeup flag before the final put.

Note that this also means that we now need to grab the write_lock to
prevent racing with resume.

Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit b1d42efc217fdc1a6a704b344fd902ae52a012c8)
USB: cdc-acm: do not update PM busy on read errors

There's no need to update the runtime PM last_busy field on read urb
errors (e.g. when the urb is being killed on shutdown).

Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 4a8ee5059a241114c644350b6cb564c729a340fa)
USB: cdc-acm: remove redundant usb_mark_last_busy

There's no need to call usb_mark_last_busy after having increased the PM
counter in write(). The device will be marked busy by USB core when the
PM counter is balanced in the completion handler.

Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 308fee18e0f06215b47b54a2b254bfaf55527bdd)
USB: cdc-acm: use tty-port dtr_rts

Add dtr_rts tty-port operation which implements proper DTR/RTS handling
(e.g. only lower DTR/RTS during shutdown if HUPCL is set).

Note that modem-control locking still needs to be added throughout the
driver.

Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 0943d8ead30e9474034cc5e92225ab0fd29fd0d4)
USB: cdc-acm: use BIT macro

Converting the header to BIT for readability. No functional
change.

Signed-off-by: Oliver Neukum <oneukum@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit d1b781002b31247d38a2892c51b88348d6a8f201)
Merge branch 'fix/cdc-acm-3.14.y' into MA-E3xx/linux-3.14.y