From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F05EE225760 for ; Thu, 19 Feb 2026 12:46:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771505203; cv=none; b=aB8AY8KsJhMdpTtTM087KP+CzzLyOiPhZRn8ChEJKazXGwEgAfsRAfcXOtJ/fmn7glBRcdNar53DSb7dIJHoKRTFvkb23BGQBPtQ+qGlH47/YZEKKtqwzLzgRCbuPJt5OREjopVedLQcscYvfyNe6ELunrhFvU3c/P7xJu8/Tmk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771505203; c=relaxed/simple; bh=RSmm80TFR9F74wx68oE5ettRi5s2htzoQ4h/rX+ERS0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pmnWlS23sIBgi5R6FARzIqI0CJ89hXDxMNze8dCNgd7X3w9IHepaRM61xXiBKxzWXICcqFi3eKZNpW60U3ifQFQdM9h8eqhYpHDuYR5aUE124mCZcwWwfISKxdXoqJahqB4qblwVrbBZUJhWuQCno32+ObbUCtwXjZBReu+DNuA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b=TPigORyv; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=suse.com header.i=@suse.com header.b="TPigORyv" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-48336a6e932so6201555e9.3 for ; Thu, 19 Feb 2026 04:46:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1771505200; x=1772110000; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=x7zwKrPpHemaHt4Sey8v9DKq8rR2lzvse0BOyJPVaoQ=; b=TPigORyvTat5IlnZxN2HmNiNZ03z2YLcyWdyrztah4Jdqfk52FqXJkqk6T5S+f+C5m RCzLslqjll/pLfjt/zxOX191DWuBPsth+J4n//HRaAMG9vkKOpjdgCdY1pq4HIOim4Aw CrIrxVnQNQ6S+cM61ox6HmAnIunfL7j+r8YrZEQNl7lV1qOtWrmjB2bJNqWgfVx5CV17 MqZsX/S27gpk0qKC9FZCqNSNLOOY8YZB0hYSzvhJ8IPmSu3sWejflg4DJDY8TW0dSTOG pi5YK69gTY2YzzImOYB8GJJ+5St8mDoV0Ew+1HQdVqTar7ENTkMc8gxvwTtNfz+u+y6l StPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771505200; x=1772110000; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x7zwKrPpHemaHt4Sey8v9DKq8rR2lzvse0BOyJPVaoQ=; b=JAI6PkQ/PJVw12jJG0FNW7zeLci2H1B4wRNL079+m56FJNWeO8m7n7/qoSaJqBRDkF 0Dxx6R6aV1wSaxggLWM5LBKKlMCrXbnmWJ/sllc8pQ8CZO4AGwAGMt5ek+WoPYspzHUK gORt2QwfYNuBBNiZo1xhAjg6OBOJ18IP93PxTX7jxSnYpHLMSXVUGfuRlzDBXElWbpGg 1ktc1F314nF9UBQOcsxEpZ8/Mk5VQI5FqdqXCkMvibRgNXYFmUuW4qfbcqIz/5lFkwRw rujwViUgG5cciatAsOPKCmSQbVRQlnUV5LbtKAN/0rTBOLqOxLlaOxR8sFfAmS22SxT2 S7IA== X-Forwarded-Encrypted: i=1; AJvYcCU8Ciz5G0opAzMhlqKK1qp0xldiUga3NvyopTQqh+glBEPvlfZFbCS4f6fVsklWyhiMoPFle6CFuoORHb4=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7nlw3s4Td5WRd6eNVxB+URgfDz/HShv25yQ5DkhJswJZWr6c9 nl67XD473JOm8EdO7UaL98kI5Mpk5HSPz8rOesPlECqbFZ0XzA81dppiMDADbPhWPH4= X-Gm-Gg: AZuq6aI6+mg5QstXVWL7BP3Z/Vf4Cyb1sf7AId4fJmgIp127EBzztOw9dUmhvXLma3C 52ylEe/KU+p+Wqz0IW539/cFcumnIj+lIBkCiBaPGFlNCravij0fIGeqstiWouigvZMZ3jMkf38 zp7YCMIz0Oau2jUmubm58NvzhX9TKEN1RJ8oWlAJWjfZNWieLkgo7IP4TZo0u8mlszHrIdCEDZt 3RwI6eIYpJ5aLGjGOQbFEhLdHHoWuzKDeqyvEvC3/3gWlJEpRlhG3VHc+v1W1gHaWYsHuZHBjHW 0gU35lnoMGkybN0r84gYFLJeNj5iXEDzrD0LGeUYSVH8QdYeBg4j6udqoBjGv71h1UEHMdrv1AG f/y4dSyVDaA+m/d2DcXlyANtH8MV64pNJb4GqN127Ppt115NORQMRhdH4zBXLizQIYao528r6ym JTgnorQCmYApbXlC2Yubsr8X4+Cw== X-Received: by 2002:a05:600c:83c6:b0:480:1e9e:f9d with SMTP id 5b1f17b1804b1-48379b934ffmr257424055e9.8.1771505200114; Thu, 19 Feb 2026 04:46:40 -0800 (PST) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4839f97825bsm20219905e9.13.2026.02.19.04.46.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Feb 2026 04:46:39 -0800 (PST) Date: Thu, 19 Feb 2026 13:46:34 +0100 From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/8] printk: Separate code for adding/updating preferred console metadata Message-ID: References: <20260206165002.496724-1-pmladek@suse.com> <20260206165002.496724-4-pmladek@suse.com> <87v7fwdbqw.fsf@jogness.linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87v7fwdbqw.fsf@jogness.linutronix.de> On Mon 2026-02-16 15:11:59, John Ogness wrote: > Hi Petr, > > On 2026-02-06, Petr Mladek wrote: > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > > index 3f856a438e74..ee57c7ac9d02 100644 > > --- a/kernel/printk/printk.c > > +++ b/kernel/printk/printk.c > > @@ -2491,18 +2491,82 @@ asmlinkage __visible void early_printk(const char *fmt, ...) > > } > > #endif > > > > -static void set_user_specified(struct preferred_console *pc, bool user_specified) > > +static int update_preferred_console(int i, const char *name, const short idx, > > Perhaps @i should be unsigned in order to guarantee no possibility of > negative array indexing. > > It would need to be defined that way in __add_preferred_console() as well. Makes sense. I'll do it in v2. > > + const char *devname, char *options, > > + char *brl_options, bool user_specified) > > { > > - if (!user_specified) > > - return; > > + struct preferred_console *pc; > > + > > + if (i >= MAX_PREFERRED_CONSOLES) > > + return -E2BIG; > > + > > + pc = &preferred_consoles[i]; > > + > > + if (!name && !devname) > > + return -EINVAL; > > + > > + if (devname) { > > + /* > > + * A valid console name and index will get assigned when > > + * a matching device gets registered. > > + */ > > + if (name) { > > + pr_err("Adding a preferred console devname with a hard-coded console name: %s, %s\n", > > + devname, name); > > + return -EINVAL; > > + } > > + if (idx != -1) { > > + pr_err("Adding a preferred console devname with a hard-coded index: %s, %d\n", > > + devname, idx); > > + return -EINVAL; > > + } > > + > > + if (!pc->devname[0]) { > > + strscpy(pc->devname, devname); > > + pc->index = idx; > > + } else if (strcmp(pc->devname, devname) != 0) { > > + pr_err("Updating a preferred console with an invalid devname: %s vs. %s\n", > > + pc->devname, devname); > > + return -EINVAL; > > + } > > + } > > + > > + if (name) { > > + /* A console name must be defined with a valid index. */ > > + if (idx < 0) { > > + pr_err("Adding a preferred console with an invalid index: %s, %d\n", > > + name, idx); > > + return -EINVAL; > > + } > > + > > + if (!pc->name[0]) { > > + strscpy(pc->name, name); > > + pc->index = idx; > > + } else if (strcmp(pc->name, name) != 0 || pc->index != idx) { > > + pr_err("Updating a preferred console with an invalid name or index: %s%d vs. %s%d\n", > > + pc->name, pc->index, name, idx); > > + return -EINVAL; > > + } > > + } > > + > > + if (!pc->options || (user_specified && options)) > > + pc->options = options; > > + > > + braille_update_options(pc, brl_options); > > + > > + if (!brl_options) > > + preferred_dev_console = i; > > > > /* > > * @c console was defined by the user on the command line. > > * Do not clear when added twice also by SPCR or the device tree. > > */ > > - pc->user_specified = true; > > - /* At least one console defined by the user on the command line. */ > > - console_set_on_cmdline = 1; > > + if (user_specified) { > > + pc->user_specified = true; > > + console_set_on_cmdline = 1; > > + } > > + > > + return 0; > > } > > > > static int __add_preferred_console(const char *name, const short idx, > > There are a lot of rules to arguments of __add_preferred_console(). Can > you add some comment above the __add_preferred_console() function > definition about these rules? I think this patch is an appropriate place > to do that since the rules are quite visible with your changes to > update_preferred_console(). For example, mentioning: > > - required: either @name and a valid @idx OR @devname and idx=-1 > - specify @brl_options if it is a Braille console > - Braille consoles will never be associated with /dev/console > > And a simple description like "Add a new preferred console or update the > options of an already registered preferred console." I am preparing v2 and added this: /** update_preferred_console - Update a given entry in the preferred_consoles[] * table. * @i: index of the entry in @preferred_consoles table which should get updated. * @name: The name of the preferred console driver. * @idx: Preferred console index, e.g. port number. * @devname: The name of the preferred physical device. * @options: Options used when setting up the console driver. * @brl_options: Options used when setting up the console driver * as a braille console. * @user_specified: True if preferred via the kernel command line. * * The function ensures that the given values are consistent. Also * it updates some global variables which are used to make the right * decisions in register_console(). * * Rules: * * 1. Either @name and valid @idx OR @devname and @idx=-1 are allowed. * Note that a valid @name and @idx will get assigned later when * @devname matches during the device initialization. * 2. Specify @brl_options if the console should be enabled as * a Braille console [*] * 3. Only matching entries can be updated. * 4. @options passed via the command line are used when the same * console is is preferred also by some platform-specific code. * * [*] Braille console is using the mechanism for registering consoles * but it is very special. It is primary used for an user interaction * with the system. It neither gets printk() messages nor is * associated with /dev/cosnole. */ Best Regards, Petr