From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 54B691FF1B4 for ; Mon, 16 Feb 2026 14:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771250763; cv=none; b=A8VlaYKrj4HOgVZs1GgTjxxq5As1F0z86Dn4HgdL7jwB5rrARZeda13uuIJU9F3EzFUUBoQATB6MJ/ZHkUkQi/tMqV3j8oVgnC9UxZZfnS0ndiQC936RsoRTZciEQa0YBoXHPcEd1PlpMbz48LledkneseB+LlE9gmtRJIYDVjY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771250763; c=relaxed/simple; bh=ZEP9xv1uddkfR201n92bXzLEIfq6FeM8MSAAm85GECc=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=CjtFnxNHq3/uH8vFeWDiFPIN+aTEI9HHf5I2fgJ1PRqLu+6ZbfEjRiOaC19oENmCf62KLwOOVGLoj15rQCbK8FePyxrFWKTrbvkARk5vXkzc2TAawI625bKrdhIRlHM/kBkQOGsxdbKpcYkfiNxHRvlXsDGbCijmPmeZdqleBwg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2pAf+Uye; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=d7V1u9ER; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2pAf+Uye"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="d7V1u9ER" From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1771250760; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AfF/i5pOFOIzhvfNk3xCF1v0ApnS0hX0s650LAMEOPI=; b=2pAf+Uyezq0cnRpkgBBEQ9IBl8UeFraL9qXjk/BfdUCfW4rcjEqjCB6LKbFVpvCMNtYQQI wymdfhPeTVk2Gqtt4LUvGjF2YIypdUSRso15IKJhOqm4IfKy9Dwh5pqD8vwaXegVeJpgXy h4l+Y+ZXn3JyZUHWVYT0V4htOXcvVkMGtTj6M5V+9X9HQY6cVdYw3zK3b+konDXu+Q8ph0 ALkc26crv/RZdDAup6e2Pyx06Hs9GpODg5MmCXme7iVpIzCy2OemnHYR4GcWvGR+nzf0dQ d4jJB0JMbDsM1uO4u8vGq5tRPZHvFjx03b7+GLNWIFiQGTHRVLTDJ5ANI+kZeQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1771250760; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=AfF/i5pOFOIzhvfNk3xCF1v0ApnS0hX0s650LAMEOPI=; b=d7V1u9ERZRJYolN3WuV9G0RHdGLNJphCZRHd3vR7alrPcqDn9qJkSAJ1uKnJtC0pumtmVv LnCvrr1aXsuzWhBg== To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , linux-kernel@vger.kernel.org, Petr Mladek Subject: Re: [PATCH 3/8] printk: Separate code for adding/updating preferred console metadata In-Reply-To: <20260206165002.496724-4-pmladek@suse.com> References: <20260206165002.496724-1-pmladek@suse.com> <20260206165002.496724-4-pmladek@suse.com> Date: Mon, 16 Feb 2026 15:11:59 +0106 Message-ID: <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 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. > + 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." John Ogness