From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (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 F13B23B8BB2 for ; Thu, 23 Apr 2026 13:01:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949283; cv=none; b=E7etuPSH0eXf9GsZNGopT9ZQ/MgVZqRf/kRTiW/Sek1sbLl8lGP9+ZC0+tyajANbQz3IAfHlVrbgDIMrZ2/RimEafjgvBINaokgdCaGGTOmbIcz/WaK+43I3yHQr29rATBjJ7/USDwYPpMJp02dmScIW4oLXSiU25AujdPcsIdU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776949283; c=relaxed/simple; bh=+VBeH9oyGFsdhOP+o6agKwpvUyUUhqnwzA69eIXCSjY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f/YuQEStzWI3oMm9gff0cO5YvrePdwq3mujztlmg76unx9hYeR9tOGbr99T8PB5Hn06Y+X6v5YjuvrdGqt1/+Asrd4tTqJjOdMEBvtFgaxIU4Ya9Lgfh0xLJ63Uct1uRECHAV5f36wYLLMgoPAVAwuFrBUCwOA2M0ba/Cawdxio= 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=dUYEDTTr; arc=none smtp.client-ip=209.85.221.45 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="dUYEDTTr" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-43d572f7437so4415303f8f.1 for ; Thu, 23 Apr 2026 06:01:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1776949280; x=1777554080; 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=YRsSHYNbUIrGTNk1cMXgUnL20Y0xVCc5kgWXyD53d7w=; b=dUYEDTTrnHOGLn5/hfENU9nYiUbZXyNXuFJhIemFfGhiB8Y0xwZbWgyXoopqlxM2U2 VFbc9ifmyVEYjHhNbZEcrfuPRFi4vC+NM17v6/NfPgz/LroeoPePRM+Nrz5H9veAY2z8 03dW4f5wYoM+om/u8MEuvxu4YTmNdq0qc+B2DzHhD334F+8PXxL5OKkQ/aoMVuUSSq+y rkcWOOrXw31swujbaabmjADAEM+K5bIDWoo3NdjDVw3Z1Ge9AI/05tBVb4PguAR8knL1 NWi65KxNaKDk0aZr3CuMAWBcZBnWxmxrr0cVZ9NGnSMy+eOGGRw2L6W/8l4x37KV4vzd OSTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776949280; x=1777554080; 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=YRsSHYNbUIrGTNk1cMXgUnL20Y0xVCc5kgWXyD53d7w=; b=L0hTrTTQfYLbGiZr4hI68N1S63Tf8brS2eD8RvdrmvcWQVQKgTkSPZC72TV5X28Wvb B1r157oOubHWgmWVwSysWBZPQp4QAG5y9rqVnFUaFfg0jXMxOj69gWqGmyl0U0HdmXng G3OJh+upXX1ezSn6ZtQerjLIgJiiLiq7KTkWeWLl15sJajHlPakXXgOf7dv7Rad5L/bK XxsFg+3ACYgtsL5MLXzDw4J/+DaF2TDsT+i6rOmEg5QfLRbnGkiZKThhLjJTjQSeNQbT 7GUbIIt+Rpfdjxg0a7JIN3KjG/ZSgImccLWoOp+KB6qcAt5kW7OdZ1EEhkmMByJbRpdv amsw== X-Forwarded-Encrypted: i=1; AFNElJ9EGS6D3CWp3Vki3vKSg3z1XgN4m8BmCMUax8aSWoPV+LNS9zINNc6ekcl9ERcSiQdH9nsFNBZf9v+vC4U=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7CBakcVjwXITXWuNT+Pge2u9IJiKSe0RfBiZYVvUwIi5UsYTE zusXYnmTq2KQD2hp/BzQXju+gnAb1/f0OU3Yr0LeEX2xSMl1ZCT0CIQD/xOMX1Swe8g= X-Gm-Gg: AeBDiesG5bqWXCcNVkUumlw5eE98CY3WdkyIPGCTN2khPk197s+uo6GB7pUBIwIRTds Fia/Ar3SlDd5HwgpcS00XejGmgsfiu/gyHyNQLDPgPV9b/zAhT1eQjNZUZ2sHxRuRCJfjOAJw4s Cq82g8rGaXZG73WyOstDBGxvhCg1WxeAzwqyNU95ybWYUvrYxlzuWcco0oIfTyxigCzil9WXAfk v66gM7NW2yZ4WLPglrlacdHC5W7PXGdYem4iQErXdRGxi4b2bUZ5SvgN8recVjhFxJ84ERUjn/M xm/28fwSITIVGWpCynxyxtSGca0c+bCgjtCTUcMqiVVFOqUrP6ufhsVEPpzrUkmvumx7BbRjFYN WAcFuyvNVATdEmsTDJgAl96Ge7ymoPqS25Tyk4tr70ACUPjTt5bZgVKMk6c8Cq8FMtVLb2u9q2S gPHm1LXH5uDQdpxG/zhxBVf7CQACkdQgp4FLTu X-Received: by 2002:a05:6000:1a8d:b0:439:ca9b:1f61 with SMTP id ffacd0b85a97d-43fe3dcbf0emr42427213f8f.17.1776949279978; Thu, 23 Apr 2026 06:01:19 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4e4d112sm57663442f8f.29.2026.04.23.06.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 06:01:19 -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 v2 4/9] printk: Cleanup _braille_(un)register_console() wrappers Date: Thu, 23 Apr 2026 15:00:09 +0200 Message-ID: <20260423130015.85175-5-pmladek@suse.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260423130015.85175-1-pmladek@suse.com> References: <20260423130015.85175-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(). The patch should not change the existing behavior. Signed-off-by: Petr Mladek Acked-by: Chris Down Reviewed-by: Marcos Paulo de Souza --- 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 d251bf8e104f..7a3bbb0cb794 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4001,8 +4001,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) @@ -4314,17 +4314,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.53.0