Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp189485rdb; Wed, 17 Jan 2024 23:59:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUTiAbGkso4DWBqDkfRFyron7NC7nEpHW3tganTujJ7HEIlavLkmiAsRqRtdAaJDmmG21H X-Received: by 2002:a05:6a00:51:b0:6d9:af4e:804 with SMTP id i17-20020a056a00005100b006d9af4e0804mr436679pfk.35.1705564753766; Wed, 17 Jan 2024 23:59:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705564753; cv=pass; d=google.com; s=arc-20160816; b=ktBDngqk7dw69/Xrystu9lRZs/xDC9dyWgtjhO38sWNQeDPn6LrzfxHT5Ff54PhxBo gmds4kn3g9iuMFlqSu5uu+eBe1aGcByO7wW1c+8xWVlJAiEwsSB4MjNlQGIIx3fr4PYI i9upxwlyNFFBfCXUSgVVYVeXwS/zEzMduESzAs3SlRZi0WJU0hZOUFmOLQHUSitKSEdw yUHoxNxAOJKtmkOeiQFN3FFF6M5cNSiVH2cWw+otVPezfMuER/wV9t1aFCsuQSCDfgXz AOkKQC17vzYxMGECV9Q1xJrFKAGoY4K0OcYgAhp9COyx3/Y23pDqY7hZP47sBeMZQn5n OcOg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=EIJjWh5PWK44CLQzbiz2JhrpAQJaaL5SVYzeQRX6F40=; fh=1YNwm5KBWetjB3qGkhgLqh/dZnCTsWuqRk83JW6hjgE=; b=KQCESkfCMm+3P4qbidE5ChzysDckZ9HcEWqY65io0/hmoW7b9bUZiij/dRX9XmiOqX PfDVCe79xDd0t83sjkNryg1NahzURJPhCQwtaoE/tlX8qpXfHGOyFf5nGPxIFymKEQrT wDK9QnIdl2AA/P4BkMF3Y4aaoUKl4LKvPKgCyo38A7Ln/L0KMT0vsbrOnLM38G6WA+9i KotjqyusPdjBQoaldnuJhuDuaj0Dv3GoveD4wn/55xtfjQqrpwrwdE4IdbkVHXu+M5MR NKQ3TnyZ+ZZX1ASzC9gVA5FsVCn3yC7AZaSIcFCfOfWPnzMg+slnXmfJEvE5ufD8cQUL KYpw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hUHWWmny; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-29791-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29791-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q136-20020a632a8e000000b0059779ae58a0si1014112pgq.465.2024.01.17.23.59.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 23:59:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-29791-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hUHWWmny; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-29791-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-29791-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6CE01284551 for ; Thu, 18 Jan 2024 07:59:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3CF591F61E; Thu, 18 Jan 2024 07:58:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hUHWWmny" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69D071E493; Thu, 18 Jan 2024 07:58:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705564691; cv=none; b=JD8708TUFoHpKd5guJ2uBjUe22oA4hR7ZBR2r3i/T4ziEY0X0I72ByjoWDY97eaLr5/YnhbZfic4KfkdceifI5y6r7nTf76EsUaWz9UEXNOLfsPCn2jrYoZ214glrPsing5dBNdzXvxugnpOGlJN2Y9LSlxrqYFE7qCSjOMqly0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705564691; c=relaxed/simple; bh=rUROH6mYOVI5bovPWhIiic94alNwwSPkZdh64JHmGT4=; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; b=kfOyQGm2NXnWgku+6fQ6mjj63z+/urrPJ1BoboiKMOYTV0miaH0aBiBTavHVZpwqFg/Wm6j0YmqMuZYKQxELozaBapxqV/0N74HloIizwjjWygcVtMiOuxViPoIhfFLoTIWH4BwwAwIDQg0xQvrSZpkUiErGs0H1jG2qtlnkuHs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hUHWWmny; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBE0AC43390; Thu, 18 Jan 2024 07:58:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705564691; bh=rUROH6mYOVI5bovPWhIiic94alNwwSPkZdh64JHmGT4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hUHWWmnyO52C8o8MDzELpYndROckNu3ZUgrlPoxmX3vamOdpNpW6a9pfmy0vu30wb bnpvPy6/VwkelT37nZ5RYyYDuxlXckLRwkx9TP6zvB6kMLBSv2eE4YXBkCY4AKXPe3 dwQwO4hOZAoZfJ2lUl6p7+fvo6j6l7MwWFJCDfZcR2qvk/ez4aRZtA2YK5sn3e0V7U 49MaShu2oQufFg4SFJp4SwTVy9l7Qpqp/uMzX58XVU6AdSvFQirMPLbMH6GJhVaPJz WLZcrpsA9SJNDBggVHz2nqdDEGYOsGN89Z05CTix/oWe95F6VpuB+JodskmEtCDIar 5XvZuCFCOOUIw== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, "Jiri Slaby (SUSE)" Subject: [PATCH 04/45] tty: vt: expect valid vc when in tty ops Date: Thu, 18 Jan 2024 08:57:15 +0100 Message-ID: <20240118075756.10541-5-jirislaby@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118075756.10541-1-jirislaby@kernel.org> References: <20240118075756.10541-1-jirislaby@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit At least since commits feebed6515a1 ("tty: shutdown method") and bc1e99d93f09 ("TTY: vt, add ->install"), tty->driver_data in vc is expected to be set since tty_operations::install() till ::cleanup(). So the checks of !tty->driver_data (aka !vc) in: * vc_do_resize() by tty -> ioctl(TIOCSWINSZ) -> vt_resize() * do_con_write() by tty -> tty_operations::write()/::put_char() * con_flush_chars() by tty -> ::flush_chars() are all superfluous. And also, holding a console lock is not needed to fetch tty->driver_data. Note there is even a stale comment in con_flush_chars() about a race between that and con_close(). But con_close() does not set tty->driver_data to NULL for years already. Drop all these in a hope I am not terribly mistaken. Signed-off-by: Jiri Slaby (SUSE) --- drivers/tty/vt/vt.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 55ce6cdecbca..e131edea00da 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -1154,9 +1154,6 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc, WARN_CONSOLE_UNLOCKED(); - if (!vc) - return -ENXIO; - user = vc->vc_resize_user; vc->vc_resize_user = 0; @@ -2852,7 +2849,7 @@ static int do_con_write(struct tty_struct *tty, const u8 *buf, int count) }; int c, tc, n = 0; unsigned int currcons; - struct vc_data *vc; + struct vc_data *vc = tty->driver_data; struct vt_notifier_param param; bool rescan; @@ -2860,13 +2857,6 @@ static int do_con_write(struct tty_struct *tty, const u8 *buf, int count) return count; console_lock(); - vc = tty->driver_data; - if (vc == NULL) { - pr_err("vt: argh, driver_data is NULL !\n"); - console_unlock(); - return 0; - } - currcons = vc->vc_num; if (!vc_cons_allocated(currcons)) { /* could this happen? */ @@ -3312,16 +3302,13 @@ static void con_start(struct tty_struct *tty) static void con_flush_chars(struct tty_struct *tty) { - struct vc_data *vc; + struct vc_data *vc = tty->driver_data; if (in_interrupt()) /* from flush_to_ldisc */ return; - /* if we race with con_close(), vt may be null */ console_lock(); - vc = tty->driver_data; - if (vc) - set_cursor(vc); + set_cursor(vc); console_unlock(); } -- 2.43.0