From patchwork Fri Sep 10 12:11:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 509025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75308C433FE for ; Fri, 10 Sep 2021 12:12:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 54FCC611C8 for ; Fri, 10 Sep 2021 12:12:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233066AbhIJMN1 (ORCPT ); Fri, 10 Sep 2021 08:13:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:41924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232982AbhIJMNZ (ORCPT ); Fri, 10 Sep 2021 08:13:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D4FB9611C8; Fri, 10 Sep 2021 12:12:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631275934; bh=FMoeBPCeVHQUwz+/csiaf0amqGtD7QOPcnxzuwU0WtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nz679UGiVMbIOpMcau/2U0nthGFmsj+ejhIu+PLqF3mrZNPsYQbdZwdgEeAu3zaw3 FOm9/5mR/IAOgRchtzBrYWP1UJ2nu/Y3jsJ+GGaJJhBXMQgNfGbbrcScLaaUDgzQl7 KLadb35F0hp3kZwSMNgeIlPFmMiH9/w20OHtSS/KkhTf1Zoxequ/C52AMgssgzGrop xQ9RRijduLYwaZ3ykeW0/XnvyB9PySCM1jOHbmyin6+4w12b3cxA1pMvbPggezh6rm dVo7sMn81QGnnfmg2u2YDMIQK+lrQsVEaeQfn0gp/wjSj8Pfis1kBcke0qv4zlDMHo yNfa/UoZVp5Uw== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1mOfO2-0004rz-6B; Fri, 10 Sep 2021 14:12:06 +0200 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] USB: serial: clean up core error labels Date: Fri, 10 Sep 2021 14:11:27 +0200 Message-Id: <20210910121128.18664-2-johan@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210910121128.18664-1-johan@kernel.org> References: <20210910121128.18664-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Clean up the core error labels by consistently naming them after what they do rather than after from where they are jumped to. Signed-off-by: Johan Hovold --- drivers/usb/serial/usb-serial.c | 34 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index eeb441c77207..abc657fec8c5 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c @@ -225,17 +225,17 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty) serial = port->serial; if (!try_module_get(serial->type->driver.owner)) - goto error_module_get; + goto err_put_serial; retval = usb_autopm_get_interface(serial->interface); if (retval) - goto error_get_interface; + goto err_put_module; init_termios = (driver->termios[idx] == NULL); retval = tty_standard_install(driver, tty); if (retval) - goto error_init_termios; + goto err_put_autopm; mutex_unlock(&serial->disc_mutex); @@ -247,11 +247,11 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty) return retval; - error_init_termios: +err_put_autopm: usb_autopm_put_interface(serial->interface); - error_get_interface: +err_put_module: module_put(serial->type->driver.owner); - error_module_get: +err_put_serial: usb_serial_put(serial); mutex_unlock(&serial->disc_mutex); return retval; @@ -1327,7 +1327,7 @@ static int __init usb_serial_init(void) result = bus_register(&usb_serial_bus_type); if (result) { pr_err("%s - registering bus driver failed\n", __func__); - goto exit_bus; + goto err_put_driver; } usb_serial_tty_driver->driver_name = "usbserial"; @@ -1347,25 +1347,23 @@ static int __init usb_serial_init(void) result = tty_register_driver(usb_serial_tty_driver); if (result) { pr_err("%s - tty_register_driver failed\n", __func__); - goto exit_reg_driver; + goto err_unregister_bus; } /* register the generic driver, if we should */ result = usb_serial_generic_register(); if (result < 0) { pr_err("%s - registering generic driver failed\n", __func__); - goto exit_generic; + goto err_unregister_driver; } return result; -exit_generic: +err_unregister_driver: tty_unregister_driver(usb_serial_tty_driver); - -exit_reg_driver: +err_unregister_bus: bus_unregister(&usb_serial_bus_type); - -exit_bus: +err_put_driver: pr_err("%s - returning with error %d\n", __func__, result); put_tty_driver(usb_serial_tty_driver); return result; @@ -1510,13 +1508,13 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[] rc = usb_register(udriver); if (rc) - goto failed_usb_register; + goto err_free_driver; for (sd = serial_drivers; *sd; ++sd) { (*sd)->usb_driver = udriver; rc = usb_serial_register(*sd); if (rc) - goto failed; + goto err_deregister_drivers; } /* Now set udriver's id_table and look for matches */ @@ -1524,11 +1522,11 @@ int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[] rc = driver_attach(&udriver->drvwrap.driver); return 0; - failed: +err_deregister_drivers: while (sd-- > serial_drivers) usb_serial_deregister(*sd); usb_deregister(udriver); -failed_usb_register: +err_free_driver: kfree(udriver); return rc; } From patchwork Fri Sep 10 12:11:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 509026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C610C433F5 for ; Fri, 10 Sep 2021 12:12:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6EF11611C8 for ; Fri, 10 Sep 2021 12:12:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232941AbhIJMN0 (ORCPT ); Fri, 10 Sep 2021 08:13:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:41920 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232952AbhIJMNZ (ORCPT ); Fri, 10 Sep 2021 08:13:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D062D611C7; Fri, 10 Sep 2021 12:12:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631275934; bh=OGpeKe8qlKrKG2MWCkAbVaugcCWxiuy7ISiHVSw/oOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UyAKLVfE0WPaM/hiFJaves446nQfPAhOHKZ16jHFcadokK40JHGWDQMxOm97sSx97 R+9yQUDk721dloiz72HxcwPVui90q1xUM/xy2RjumvzeXr7uIU9Pww6wDj+zLQPMGj wedM0eGNh1VhjnCxmBJFscNtSn53joXGgp6r4f/ks4YFUkpa9SloagnVbEvUrIwcEu 9iiU6oZhEgOOafGrsgLnKaGAU6hyskjKgBRFCzu2vxoIC4k96nEXUkSehSdr+0Wmw0 FXVlDstzABo3OypSM9sdE+ALRDjHMkMvmq11ihLgxrL3Svf53/W7gt2baE8E4ll06p Me+WWWvwYuFWg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1mOfO2-0004s1-8h; Fri, 10 Sep 2021 14:12:06 +0200 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] USB: serial: allow hung up ports to be suspended Date: Fri, 10 Sep 2021 14:11:28 +0200 Message-Id: <20210910121128.18664-3-johan@kernel.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210910121128.18664-1-johan@kernel.org> References: <20210910121128.18664-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org User space can keep a tty open indefinitely and that should not prevent a hung up port and its USB device from being runtime suspended. Fix this by incrementing the PM usage counter when the port it activated and decrementing the counter when the port is shutdown rather than when the tty is installed and the last reference is dropped, respectively. Signed-off-by: Johan Hovold --- drivers/usb/serial/usb-serial.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index abc657fec8c5..b357361d5d1e 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c @@ -208,8 +208,8 @@ void usb_serial_put(struct usb_serial *serial) * * This is the first place a new tty gets used. Hence this is where we * acquire references to the usb_serial structure and the driver module, - * where we store a pointer to the port, and where we do an autoresume. - * All these actions are reversed in serial_cleanup(). + * where we store a pointer to the port. All these actions are reversed + * in serial_cleanup(). */ static int serial_install(struct tty_driver *driver, struct tty_struct *tty) { @@ -227,15 +227,11 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty) if (!try_module_get(serial->type->driver.owner)) goto err_put_serial; - retval = usb_autopm_get_interface(serial->interface); - if (retval) - goto err_put_module; - init_termios = (driver->termios[idx] == NULL); retval = tty_standard_install(driver, tty); if (retval) - goto err_put_autopm; + goto err_put_module; mutex_unlock(&serial->disc_mutex); @@ -247,8 +243,6 @@ static int serial_install(struct tty_driver *driver, struct tty_struct *tty) return retval; -err_put_autopm: - usb_autopm_put_interface(serial->interface); err_put_module: module_put(serial->type->driver.owner); err_put_serial: @@ -265,10 +259,19 @@ static int serial_port_activate(struct tty_port *tport, struct tty_struct *tty) int retval; mutex_lock(&serial->disc_mutex); - if (serial->disconnected) + if (serial->disconnected) { retval = -ENODEV; - else - retval = port->serial->type->open(tty, port); + goto out_unlock; + } + + retval = usb_autopm_get_interface(serial->interface); + if (retval) + goto out_unlock; + + retval = port->serial->type->open(tty, port); + if (retval) + usb_autopm_put_interface(serial->interface); +out_unlock: mutex_unlock(&serial->disc_mutex); if (retval < 0) @@ -304,6 +307,8 @@ static void serial_port_shutdown(struct tty_port *tport) if (drv->close) drv->close(port); + + usb_autopm_put_interface(port->serial->interface); } static void serial_hangup(struct tty_struct *tty) @@ -352,8 +357,6 @@ static void serial_cleanup(struct tty_struct *tty) serial = port->serial; owner = serial->type->driver.owner; - usb_autopm_put_interface(serial->interface); - usb_serial_put(serial); module_put(owner); }