From patchwork Wed Apr 19 11:54:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 85371 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp346572vqo; Wed, 19 Apr 2023 05:25:06 -0700 (PDT) X-Google-Smtp-Source: AKy350ZX+EdKATgDOd2NzMrIIoaUoear0G8M79475vvQhQCKprluEeK2j6hyFAHv/WMor87Eo0pM X-Received: by 2002:a05:6a00:8013:b0:63c:56f5:5053 with SMTP id eg19-20020a056a00801300b0063c56f55053mr2290133pfb.13.1681907105978; Wed, 19 Apr 2023 05:25:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681907105; cv=none; d=google.com; s=arc-20160816; b=z0DBGRzFzIfYUDjvSm/laLz91/9yuJgmoGvxi8BeMfWRUVcplAWP3CU+XvIKua+/iq ttFoizn6SW+PVTvKzKvH96pEpNPqPZjaCv6woHFV6yTZGquM30qctsHkDs1C+a8Et8kB 0HzG6iJUYx/dJqK4TnQzeNJjXyMDS/UeF2M0c9Q8EB73BqdfajO1d16CpXIOd7KVOiOR X+qYM2BZSXzW8LmwPhE8nK2jdRWJmN193SUaZlT0NBR0SXvLvqWvwXgfp9YiAePcsN+T Z12R96UiGU3DVNSS7XpzxsP4dD2Ssw6vGdT6Q9bo21bCDcNXYyv8RwOYTYee6OYl/bd3 1qgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=G/N9tiY4SScOsQPhzY7XWryL+yVu1bku7pgH9aegzS4=; b=FBcqaBbJm5gdtZQ1LwM5ih6QaQtsfsvNPY+YHVZekS8BPNG8AluWr0zLHlDPf/CIeb VVNZmv2zu9IzkguySL+UzKnFQjRDefMv7WZtEU+zlVyVa2pHZC44Cn2Mp5oDIPYtAD9+ /5Ba9E+jzH7P0FDGVX7luP2Bzyt3uYnYL4XcJkaJS4wrM9wTtHSA8ouO+fvDAb1PNEPc 4KgqO27DY/Yt4QqUFRnBmw189vRkPVHTxNXs6Q5Whiud8our+4zMXYFbcYi84PxywXlp aslh1ZrziGzisHRLZieoX9oNYwgA9RRt9zCVwpcFSDtsk5Rpnb3EgMjtZlpWupj+AdR1 tGAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f189-20020a6251c6000000b0063b893272a8si9097100pfb.246.2023.04.19.05.24.51; Wed, 19 Apr 2023 05:25:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233064AbjDSLys (ORCPT + 99 others); Wed, 19 Apr 2023 07:54:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233039AbjDSLyg (ORCPT ); Wed, 19 Apr 2023 07:54:36 -0400 Received: from muru.com (muru.com [72.249.23.125]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D561313F98; Wed, 19 Apr 2023 04:54:32 -0700 (PDT) Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id A342A80A7; Wed, 19 Apr 2023 11:54:30 +0000 (UTC) From: Tony Lindgren To: Greg Kroah-Hartman , Jiri Slaby Cc: Andy Shevchenko , =?utf-8?q?Ilpo_J=C3=A4rvi?= =?utf-8?q?nen?= , Johan Hovold , Sebastian Andrzej Siewior , Vignesh Raghavendra , linux-omap@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] serial: core: Disable uart_start() on uart_remove_one_port() Date: Wed, 19 Apr 2023 14:54:22 +0300 Message-Id: <20230419115423.59957-1-tony@atomide.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763607425450844467?= X-GMAIL-MSGID: =?utf-8?q?1763607425450844467?= While rebinding a uart device in a loop I noticed we may see a tx related race on uart_remove_one_port(): uart_write from n_tty_write n_tty_write from file_tty_write.constprop.0 file_tty_write.constprop.0 from vfs_write vfs_write from ksys_write ksys_write from ret_fast_syscall Let's disallow tx on port->UPF_DEAD. This flag gets set before we start tearing down the port in uart_remove_one_port(). Signed-off-by: Tony Lindgren --- drivers/tty/serial/serial_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -135,7 +135,7 @@ static void __uart_start(struct tty_struct *tty) struct uart_state *state = tty->driver_data; struct uart_port *port = state->uart_port; - if (port && !uart_tx_stopped(port)) + if (port && !(port->flags & UPF_DEAD) && !uart_tx_stopped(port)) port->ops->start_tx(port); }