From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 0C4C03AD50E for ; Tue, 2 Jun 2026 08:54:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390465; cv=none; b=ktifALb/14js8MFQD+/MFwAh68yRezEZEdYy1YgqWzgVVB7Vveb17L+pjS6xwisT9lnu/5rV4qAIj8lyPquS9uL/Z2L9bjBs8oOVLbwTB+N1Exk+I+IC7xOh3RH+BpZU8o9IkRtvmVIZOvouItDMI08Q3jGdl5SpCDp5osmT6to= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780390465; c=relaxed/simple; bh=CFoGni/kFfd2DzrCmbPAUyOHnqZ34zCaezXsF0V5Rt0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mYyOk0cLxmQ0oOJTGeZKS/lCKOAhW/2zT5eCZh8G1/RhiYXj5LZM0RZ+h/OKC2PXqcsXJQXTsXe2kLlelNq386fOV0YqWcBQKcWMF2StFHtrg/CUQ9uo2Nv/0BJLE4ZcPQH8oGe0MnQ+F2T6Aftd9hl5teqLXB132IXh7EXh7To= 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=HGeTtnxM; arc=none smtp.client-ip=209.85.221.52 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="HGeTtnxM" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-45ee6d32402so2719392f8f.1 for ; Tue, 02 Jun 2026 01:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780390458; x=1780995258; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yIfYBC9coKnvV2xjTHOUNafFcovucRtDATksoAoVxpY=; b=HGeTtnxMQT+bpcuuHkURejTxqAnMlTXL50fPzKZkfTGilCkPivQleHvnPtDwurnery BP8TTsHyzJgj7GRlrWUfyEUxSVJO19UrMRqmVj+05epWSLw85frwUXdMn7/QZoLDP9uS 2jGuG9/k3+/pOIjJAE/+GfVk/dxVMhD3CDhwXdyOpQYEFyyywtLwlJ0oLKjArZgtvQ8g k42ZHdjQDD+E7Dcv69Qo7VeQ5i9bfdhFzKPRrnXLMaov8hKRqz2/YW4vQPPEcxg4kIiZ 8U8/ijJZjSIRnQ2ZdasJ271Jt32EcqRkjIvV0s3C5oU9oE2/uVvdamrmAKJg4vC0WoD9 biBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780390458; x=1780995258; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yIfYBC9coKnvV2xjTHOUNafFcovucRtDATksoAoVxpY=; b=dm1JMpwHPjC97uvnDK3hv0S77SRehPjongFx2inEIeKS4v8uiFWBZOlbanAzkw5eRA LaI6Bsg4ATX9t+LVO9Pv5kxKA8h0+4IfcjDqbiYMbF6WNZYxFd8LrbDVxecPl/lGZ37i Ho5U3bV+fNiEDijZeMeYivtY74OJxD4s/izSnNeYZCqAMQoeG9Pz4qYyCr4nGgi6j75f 42PIZCiUw0WwS8YmbXqSIV++k5cL6u3PvpeiFT6IpgAFeCOl09vxlxC2VojbXNX7fuil 2HVbsSwcRLrPc0PcExvzQtMxu+tlBwj9cI8bBeVyMjMza6D6Hg6UJQX6gZEHqWLXKfy5 mA4A== X-Forwarded-Encrypted: i=1; AFNElJ9YG38Mcswcctoo1zs3DtdLrY/c11PdDLub8rGc58L3l/YrV3XK0G9Qu7vJke+w7ZlodH6UdexVmFKNlpw=@vger.kernel.org X-Gm-Message-State: AOJu0YztA1Ff4sIrGOeeQCbRc2E9S3pxDrMNYnufIThm3my+8S14bRUd okOcO0Yam58PiCC3gcbqTq2GbX5d5JbXxaUn+1Xxh45XpKNWblWxFN496JPKKBSSzLaTVMnMhBF fw+JC X-Gm-Gg: Acq92OGQDBYPrO7lGPEYN5+bY/UdE66aSnRooRhmUIXgtvuEiD6Sl9zHKEckxEMHJf8 iy7ncz7wacDyQ20uxlYfUlNfqc+ASOiqMWLBTOSgPRK8/+VOmF8ApJGOyKKo72E6W71+gxiAJEt K2+Xp9y/15lHNBnTx4n+TIf3LOxet2OqsiSDLQjzvzl1ugy0OA1YyCxGcw1uKYXv37bbqPjtdl3 5tKoPF65fu4YEm7epLZ0vY+S0n42IclvejGK4/L1hhhNRefVXk/DZB9gW+H7C/wu+d1eoOg+Oi8 OX3jiYttR/83PdDppGSDEZGP/JupcESHhvt///tNkPLSfbnjNsWznIJ3jwIYzbrZJObBKSl7rDd WQRPM9xFwZEre2R9/G/EwW2c64Jj2sDus8raDE3ZhpTysDaRGjRE1fYDBW6qUpiof3B6vayPtAH crxeWdYzTSN4zl1KWLrFuJQVfUDeFuLrnmTBwTYOkWskZgg+A= X-Received: by 2002:adf:fe90:0:b0:45e:64b3:af44 with SMTP id ffacd0b85a97d-45ef6b94067mr19058283f8f.36.1780390458257; Tue, 02 Jun 2026 01:54:18 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45ef354b7edsm31498416f8f.22.2026.06.02.01.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:54:17 -0700 (PDT) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v3 04/11] printk: Cleanup _braille_(un)register_console() wrappers Date: Tue, 2 Jun 2026 10:53:05 +0200 Message-ID: <20260602085312.228251-5-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260602085312.228251-1-pmladek@suse.com> References: <20260602085312.228251-1-pmladek@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The _braille_(un)register_console() wrappers currently attempt to hide implementation details like the CON_BRL flag and pc->brl_options. This forces callers to handle an unconventional tri-state return value (0 for NOP, >0 for success, <0 for error), which makes the control flow harder to follow and non-standard. Refactor the wrappers to use standard kernel return codes (0 for success, -ERRCODE on failure). Move the responsibility of checking brl_options to the caller to make the logic more explicit. Additionally, move the assignment of the CON_BRL flag from the internal wrapper to braille_register_console(). This aligns it with how CON_ENABLED is handled. To maintain symmetry and fix a potential bug where flags might persist after removal, explicitly clear both CON_ENABLED and CON_BRL in braille_unregister_console(). No behavior change. Signed-off-by: Petr Mladek Acked-by: Chris Down Reviewed-by: Marcos Paulo de Souza Reviewed-by: John Ogness --- drivers/accessibility/braille/braille_console.c | 7 ++++--- kernel/printk/braille.c | 16 +++------------- kernel/printk/braille.h | 12 ++++++++++++ kernel/printk/printk.c | 13 +++++-------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/drivers/accessibility/braille/braille_console.c b/drivers/accessibility/braille/braille_console.c index 06b43b678d6e..7b324329882f 100644 --- a/drivers/accessibility/braille/braille_console.c +++ b/drivers/accessibility/braille/braille_console.c @@ -360,12 +360,12 @@ int braille_register_console(struct console *console, int index, if (ret != 0) return ret; } - console->flags |= CON_ENABLED; + console->flags |= CON_ENABLED | CON_BRL; console->index = index; braille_co = console; register_keyboard_notifier(&keyboard_notifier_block); register_vt_notifier(&vt_notifier_block); - return 1; + return 0; } int braille_unregister_console(struct console *console) @@ -375,5 +375,6 @@ int braille_unregister_console(struct console *console) unregister_keyboard_notifier(&keyboard_notifier_block); unregister_vt_notifier(&vt_notifier_block); braille_co = NULL; - return 1; + console->flags &= ~(CON_ENABLED | CON_BRL); + return 0; } diff --git a/kernel/printk/braille.c b/kernel/printk/braille.c index 9d21a2bb1d38..593f83eb0487 100644 --- a/kernel/printk/braille.c +++ b/kernel/printk/braille.c @@ -37,22 +37,12 @@ int _braille_console_setup(char **str, char **brl_options) int _braille_register_console(struct console *console, struct preferred_console *pc) { - int rtn = 0; - - if (pc->brl_options) { - console->flags |= CON_BRL; - rtn = braille_register_console(console, pc->index, pc->options, - pc->brl_options); - } - - return rtn; + return braille_register_console(console, pc->index, pc->options, + pc->brl_options); } int _braille_unregister_console(struct console *console) { - if (console->flags & CON_BRL) - return braille_unregister_console(console); - - return 0; + return braille_unregister_console(console); } diff --git a/kernel/printk/braille.h b/kernel/printk/braille.h index 0bdac303f8b1..ec5feac1f508 100644 --- a/kernel/printk/braille.h +++ b/kernel/printk/braille.h @@ -11,6 +11,12 @@ braille_update_options(struct preferred_console *pc, char *brl_options) pc->brl_options = brl_options; } +static inline bool +is_braille_console_preferred(struct preferred_console *pc) +{ + return (!!pc->brl_options); +} + /* * Setup console according to braille options. * Return -EINVAL on syntax error, 0 on success (or no braille option was @@ -34,6 +40,12 @@ braille_update_options(struct preferred_console *pc, char *brl_options) { } +static inline bool +is_braille_console_preferred(struct preferred_console *pc) +{ + return false; +} + static inline int _braille_console_setup(char **str, char **brl_options) { diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 4e4aadc51f6b..ffff77f81e97 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4006,8 +4006,8 @@ static int try_enable_preferred_console(struct console *newcon, if (newcon->index < 0) newcon->index = pc->index; - if (_braille_register_console(newcon, pc)) - return 0; + if (is_braille_console_preferred(pc)) + return _braille_register_console(newcon, pc); err = console_call_setup(newcon, pc->options); if (err) @@ -4319,17 +4319,14 @@ static int unregister_console_locked(struct console *console) bool found_boot_con = false; unsigned long flags; struct console *c; - int res; + int res = 0; lockdep_assert_console_list_lock_held(); con_printk(KERN_INFO, console, "disabled\n"); - res = _braille_unregister_console(console); - if (res < 0) - return res; - if (res > 0) - return 0; + if (console->flags & CON_BRL) + return _braille_unregister_console(console); if (!console_is_registered_locked(console)) res = -ENODEV; -- 2.54.0