Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp156224rwr; Wed, 19 Apr 2023 04:59:24 -0700 (PDT) X-Google-Smtp-Source: AKy350Zm06MgEwWtKPbMKebgXgQR+hc7nDiqlqol+YhfVk0yCbo537IAJWACHip0qWwmnLbVdxF9 X-Received: by 2002:a17:90b:188e:b0:237:ae98:a47f with SMTP id mn14-20020a17090b188e00b00237ae98a47fmr2472661pjb.1.1681905564610; Wed, 19 Apr 2023 04:59:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681905564; cv=none; d=google.com; s=arc-20160816; b=fBfuLDKTIBOeOqMdo23JGONkUEjPhh44ZeFafdzVR43Dd99S81jxWHh3EFMxqxAKyQ G8x988xICyRoscEhRiy6s8czK5ywfG7B0KEM/9/+RKzZJl9VfWkwy9uJ5140cl532PCF pDC4QSfyk37s1DKNB+3gpQrZ5CR3ZmggzGLj4shNbblieL6gsgQJ2r52x3oOlcv574Wy RPG3VoAJOSyCDIDHJrQtbNHFKMbJZ1eiYP3mYrV0VafVlUZ2Kv8bh5m6v9BQR/7udm7G j4G8S+lS0rTbs6rZyhCVG7SFqYHbz/lDR5c3CvXBMiYLmlwO7VdVrn79mo+ujyFYmTGC Gkzg== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pj5-20020a17090b4f4500b00233c5363cdcsi1704706pjb.142.2023.04.19.04.59.11; Wed, 19 Apr 2023 04:59:24 -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 S233062AbjDSLyr (ORCPT + 99 others); Wed, 19 Apr 2023 07:54:47 -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=20J=C3=A4rvinen?= , 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 Content-Transfer-Encoding: 8bit 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 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); } -- 2.40.0