lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20250506125133.108786-3-nicolescu.roxana@protonmail.com>
Date: Tue, 06 May 2025 12:51:48 +0000
From: Roxana Nicolescu <nicolescu.roxana@...tonmail.com>
To: gregkh@...uxfoundation.org, rafael@...nel.org, dakr@...nel.org, jason.wessel@...driver.com, danielt@...nel.org, dianders@...omium.org, jirislaby@...nel.org
Cc: kgdb-bugreport@...ts.sourceforge.net, linux-serial@...r.kernel.org, linux-kernel@...r.kernel.org, skhan@...uxfoundation.org, linux-kernel-mentees@...ts.linux.dev
Subject: [RFC PATCH 2/2] serial: kgdboc: convert to use faux_device

The kgdboc uses a "fake" platform device to handle tty drivers showing
up late. In case the tty device is not detected during probe, it will
return EPROBE_DEFER which means the probe will be called later when the
tty device might be there. Before this, the kgdboc driver
would be initialized early in the process (useful for early boot
debugging) but then the tty device wouldn't be there, and retry wouldn't be
done later. For a better explanation, see commit
'68e55f61c138: ("kgdboc: Use a platform device to handle tty drivers
showing up late")'.

This replaces the platform_device usage with faux_device which was
introduced recently for scenarios like this, where there is not real
platform device needed. Moreover, it makes the code cleaner than before.

Signed-off-by: Roxana Nicolescu <nicolescu.roxana@...tonmail.com>
---
 drivers/tty/serial/kgdboc.c | 50 +++++++++++--------------------------
 1 file changed, 14 insertions(+), 36 deletions(-)

diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
index 85f6c5a76e0f..d1ffe6186685 100644
--- a/drivers/tty/serial/kgdboc.c
+++ b/drivers/tty/serial/kgdboc.c
@@ -21,7 +21,7 @@
 #include <linux/input.h>
 #include <linux/irq_work.h>
 #include <linux/module.h>
-#include <linux/platform_device.h>
+#include <linux/device/faux.h>
 #include <linux/serial_core.h>
 
 #define MAX_CONFIG_LEN		40
@@ -42,7 +42,7 @@ static int kgdboc_use_kms;  /* 1 if we use kernel mode switching */
 static struct tty_driver	*kgdb_tty_driver;
 static int			kgdb_tty_line;
 
-static struct platform_device *kgdboc_pdev;
+static struct faux_device *kgdboc_fdev;
 
 #if IS_BUILTIN(CONFIG_KGDB_SERIAL_CONSOLE)
 static struct kgdb_io		kgdboc_earlycon_io_ops;
@@ -259,7 +259,7 @@ static int configure_kgdboc(void)
 	return err;
 }
 
-static int kgdboc_probe(struct platform_device *pdev)
+static int kgdboc_probe(struct faux_device *fdev)
 {
 	int ret = 0;
 
@@ -276,47 +276,26 @@ static int kgdboc_probe(struct platform_device *pdev)
 	return ret;
 }
 
-static struct platform_driver kgdboc_platform_driver = {
+struct faux_device_ops kgdboc_driver = {
 	.probe = kgdboc_probe,
-	.driver = {
-		.name = "kgdboc",
-		.suppress_bind_attrs = true,
-	},
 };
 
 static int __init init_kgdboc(void)
 {
-	int ret;
 
 	/*
-	 * kgdboc is a little bit of an odd "platform_driver".  It can be
-	 * up and running long before the platform_driver object is
-	 * created and thus doesn't actually store anything in it.  There's
-	 * only one instance of kgdb so anything is stored as global state.
-	 * The platform_driver is only created so that we can leverage the
+	 * There's only one instance of kgdb so anything is stored as global
+	 * state.
+	 * The faux_device is only created so that we can leverage the
 	 * kernel's mechanisms (like -EPROBE_DEFER) to call us when our
-	 * underlying tty is ready.  Here we init our platform driver and
-	 * then create the single kgdboc instance.
+	 * underlying tty is ready. Here we init our faux device kgdboc
+	 * instance.
 	 */
-	ret = platform_driver_register(&kgdboc_platform_driver);
-	if (ret)
-		return ret;
-
-	kgdboc_pdev = platform_device_alloc("kgdboc", PLATFORM_DEVID_NONE);
-	if (!kgdboc_pdev) {
-		ret = -ENOMEM;
-		goto err_did_register;
-	}
+	kgdboc_fdev = faux_device_create("kgdboc", NULL, &kgdboc_driver);
+	if (!kgdboc_fdev)
+		return -ENOMEM;
 
-	ret = platform_device_add(kgdboc_pdev);
-	if (!ret)
-		return 0;
-
-	platform_device_put(kgdboc_pdev);
-
-err_did_register:
-	platform_driver_unregister(&kgdboc_platform_driver);
-	return ret;
+	return 0;
 }
 
 static void exit_kgdboc(void)
@@ -325,8 +304,7 @@ static void exit_kgdboc(void)
 	cleanup_kgdboc();
 	mutex_unlock(&config_mutex);
 
-	platform_device_unregister(kgdboc_pdev);
-	platform_driver_unregister(&kgdboc_platform_driver);
+	faux_device_destroy(kgdboc_fdev);
 }
 
 static int kgdboc_get_char(void)
-- 
2.34.1



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ