From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.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 4149C3431EF for ; Thu, 4 Jun 2026 10:16:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568172; cv=none; b=EzngmZAwSm4Cnj2/9mNvQis7FZ3MNH+aAczUNZ3OuarGFmjgozVe6uehwrztH/0ncIanKGIBu/y06M1rbf6E1IErJAtzsg7gZ5nSpLqm4yG6gHnyGRV4u4lOeRZWA/H86qolF0wEHI18I4eW33biztgj94U0CFAdjxesbS4Mwio= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780568172; c=relaxed/simple; bh=B9t+QC+dNCG4cjJ/lPOcvwGISuX//DyjsNtkJLRYxjE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H4swC1mVSn3XU+tABW5yVdd4k5XNirQ1uL136sa3qjFaN9kPfO3bM8j6nBbt8k7wiJpQdRz5A5g8Jhv4YOsjxYWhMRzP97UhvQKS+/lGL0OSHRM4ybp0Gmr1eaJWQSNBz4OLA/jsrrikItefdY0/aqNFCT23d6rkgBX0jTeI90U= 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=FohMz8yo; arc=none smtp.client-ip=209.85.128.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="FohMz8yo" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-490af320e2aso6266395e9.2 for ; Thu, 04 Jun 2026 03:16:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1780568170; x=1781172970; 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=EZRiwF7pwuo2FecZRPUOws87FlaHbZze5014dvSa7OA=; b=FohMz8yo+RpTAc8EBBC5/RlkF4HhfWgHWyxFX4kZ6nQL0T5Uaq46fp1eVl3bJQQuBg DUzn3pn/xiDTJhKuxNBnld1x0EGeTHg4/2BmGoOgrip3pXXbphx18uufoYNXvzAf7io+ ZdqKbLHMwZINW7G293BuFbRxKyXRap6k+uIzsM65nxxTd3EVqE+Y7JKmzvKwhoNCmjo5 kjs/LreOrlKpzmMnX1EV6Wm9DrJr666QoeGLaaxgyIbvzX6KjdkUPre6FZ0gVNr3xlEl lC+XRzthMY+Cd7r41q0XLJHs7GXfT5A2DRomAvUuIsWKA3V4d28QUl8eY3Aqx072ctr7 zG5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780568170; x=1781172970; 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=EZRiwF7pwuo2FecZRPUOws87FlaHbZze5014dvSa7OA=; b=MadBx8aNECNy5IO/LGQK9KdoI0RKKt4FDkoqCumb4WrRoAlHWoRL0NUQJLcXJv+uLD dPOtbtnXL/dgNPhjWzdyhUSkA16DDN+IzJZYBH7h4Ce8LeWufgDB8vk9p+xGrlaMphPF N1mbnTQRdaDhQtIejbTq53w2bR8PNJlE0UqribIjJyY891946sxe7mA+4tMDaGy550Cr 9P+o02Cfa/UYtpIWpPB0r4pUgI10M7gefqd45/vR53zYuiU9hIIWOa1E81hgVyJxGgqv EaXd44Hl01QgMO7VYh1RDEHhbiEsfslZCni6ZqR+kfYzWKY4/sktlkIIwwtQ/LLNUwKw 5Fqg== X-Forwarded-Encrypted: i=1; AFNElJ+D7yxCJi9ov7mjk5sjTWFEj9R8MpG6pxuMNt3oG8HrIuX1egL2v3YGlroxlR3/VxMgiMTAgMwf9OqSrdY=@vger.kernel.org X-Gm-Message-State: AOJu0Yxllz0Jo/94QFOF1YzAFNaxWg0Omav5iIo6DINH3ziFsMHAaUNl 8uElmA4xUt/XxibuGpxmZu42MBOxtHSolNL/BgccScd0uDg6pqyxhfPbvxRDCANqqbQ= X-Gm-Gg: Acq92OEtUw08UodrycjqEjr2iHGUhBrbXeVyOIo8CI/fN77Ul6aRMWQ2ty1hQTSpJgS CRU7TI8HrkyinMU2VQbU3PjPUl3+A65VolDHy6UFBbM+FuKCymDNA6i8GGKamrI4qhI1CnTWTLl 0uWUAK8U3M7wWz7Sh1Szzjc4ShbwaQTqMKzFqSAusq0BEgC0GYJkqbRcl46CRe7NLA6Nj89gEm0 NcOf7dd+j6YjresIm3JQ0Agrg2WxXQrDfBbmRKRlCO6Iqf6q8zuAM4a5OMLicJa9vzcmiluA4lL cGeRK9rNyHMQnyxH2RIxQvTOaimhy5BIVOyImc4eseJq8gNnYJVkk8IPoQycOdj3Arhl1bFa+WC 6kQhEkMjrQtRhZo8nC+yS6qSB2Ji7tWuxKbbVP1yr2sOspApmSm/Quo9kjXvhDJX/59Hokqzhjq sx15jlCxbVg/MUexO3gRWDq1kieIAbiaufiR4V X-Received: by 2002:a05:600c:8b48:b0:490:9df1:f0cf with SMTP id 5b1f17b1804b1-490b5e94e13mr115360955e9.2.1780568169630; Thu, 04 Jun 2026 03:16:09 -0700 (PDT) Received: from pathway.suse.cz ([176.114.240.130]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3e4b5asm60075625e9.13.2026.06.04.03.16.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jun 2026 03:16:08 -0700 (PDT) From: Petr Mladek To: John Ogness Cc: Sergey Senozhatsky , Steven Rostedt , Marcos Paulo de Souza , Chris Down , Naveen Kumar Chaudhary , linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH v4 05/11] printk: Cleanup _braille_(un)register_console() wrappers Date: Thu, 4 Jun 2026 12:14:52 +0200 Message-ID: <20260604101459.393162-6-pmladek@suse.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260604101459.393162-1-pmladek@suse.com> References: <20260604101459.393162-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 b7dbbc1baeb1..4ee98a4d2ce5 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -4003,8 +4003,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) @@ -4316,17 +4316,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