From nobody Tue Apr 7 22:20:38 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D5C0C4332F for ; Wed, 19 Oct 2022 15:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232213AbiJSPHd (ORCPT ); Wed, 19 Oct 2022 11:07:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230455AbiJSPFs (ORCPT ); Wed, 19 Oct 2022 11:05:48 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EAA2205CC for ; Wed, 19 Oct 2022 07:59:28 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666191378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f12nNYu1o1nheACyaBAz3IPbjPiOwdCr955JKGftNi0=; b=gEk/56dyVdJxDt/J7kVgFStcKjvZrGcgIOwQYk0XwQKdK8FsV0Y9dvc9y2PrxlYjtuLQT3 fSJL3lf/BuDtIhc+l6cIXdtEsuXqSJu6EpaxJSdLt15yliOrYrRp1+h7ASkvcNnkIleiOK WZ+Tm++vLlUFSJX9OqsxsxRrd4s4tFKvj3VUqZdNFTfb3Xhi8xUPk8f1Hr6A5xGkJiRoR+ A2sCQpxxeuWpEagnAVMwC/rga5HRcHoOkPCaPZzrNI1r1Nzz5TeNQX3rrKHlEpNHJHjOfV JKp1j4/HoOOs0hPNpCf8W0nyoa5ouc48VUQum9WrHC4viYimonEL+j+iP2L95A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666191378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f12nNYu1o1nheACyaBAz3IPbjPiOwdCr955JKGftNi0=; b=Hy5IF74AngV6AgkVUBSfbWawZSbLHUumgqjJi1aW8Es4tyHbxXvp1fWUJHJOyfgmdOtGqL +/HMreGlQbQCBDAQ== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH printk v2 31/38] printk: register_console: use srcu console list iterator Date: Wed, 19 Oct 2022 17:01:53 +0206 Message-Id: <20221019145600.1282823-32-john.ogness@linutronix.de> In-Reply-To: <20221019145600.1282823-1-john.ogness@linutronix.de> References: <20221019145600.1282823-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use srcu console list iteration for console list traversal. Now the traversal at the beginning of register_console() is safe. Signed-off-by: John Ogness Reviewed-by: Petr Mladek --- kernel/printk/printk.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 410ad9d5649c..809c43e596d8 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3188,20 +3188,23 @@ void register_console(struct console *newcon) struct console *con; bool bootcon_enabled =3D false; bool realcon_enabled =3D false; + int cookie; int err; =20 - for_each_console(con) { + cookie =3D console_srcu_read_lock(); + for_each_console_srcu(con) { if (WARN(con =3D=3D newcon, "console '%s%d' already registered\n", - con->name, con->index)) + con->name, con->index)) { + console_srcu_read_unlock(cookie); return; - } + } =20 - for_each_console(con) { if (con->flags & CON_BOOT) bootcon_enabled =3D true; else realcon_enabled =3D true; } + console_srcu_read_unlock(cookie); =20 /* Do not register boot consoles when there already is a real one. */ if (newcon->flags & CON_BOOT && realcon_enabled) { --=20 2.30.2