From patchwork Tue May 6 12:51:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roxana Nicolescu X-Patchwork-Id: 888479 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) (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 44550280000; Tue, 6 May 2025 12:51:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746535910; cv=none; b=Ub5R6jAX0SUAVIazEz1LYyJR8ssRKFp5QfFsxC0m871I6rPrzOUwYIfsdApbvEXkPvXQ7OyhidWmKrwy4XuMolQ8R6xJk0ToRY+3lhwv2Uj2+dCWMWdo5yTPabSa25U2cdc6iWpVJMeh2THJ07V+wQ/dkMFoFsKVLqEaps8ZcBA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746535910; c=relaxed/simple; bh=XwcK4xNdJ5bqnZI9n1Ki4hOFLIohBhzddbgDl9oczSs=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=r+MWdTSaakb9b8gjPQtFuDBnmSdZWkjKM7FfAUmEYjUAADNphSuV6NBziCALLlim7X+q1N9yGKpe+SkqF9BFACrTzfcfTPwseVGO/ptFiPKo44Irw7JRDhocDKzo61FG+W1VG0nfUR/Uy1oUV0JiSEPfGCR8pglU3bWo0lMrVFA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com; spf=pass smtp.mailfrom=protonmail.com; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b=xriuQwmg; arc=none smtp.client-ip=185.70.43.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=protonmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="xriuQwmg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1746535907; x=1746795107; bh=XwcK4xNdJ5bqnZI9n1Ki4hOFLIohBhzddbgDl9oczSs=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=xriuQwmgfNo5DJYwsgvwXvgfFBiWmCAPaxQdVdukMugEO9rR5CTpY8eU3pRNj1f9x naLNfbifRO65P3pmphcdCQfj01iN+4Nl0BzL3XCzMDveTZTTf2KiQ7WQAXfq6oeH0r VW5A9adatchp3fDbcA59DQeQkLrWtaWzBcO1incMCbLxhDtvmopzRobokwGufC7sn+ W6SvnuXs0Nj4vGf78CECa5asUyKLXZri45ydxvnOeRdcVTvhLb6et67k4SsgqBimgl aM8a2Wf0WxrrlKy35DnJCNnlzoM8M1qpgPDUhulOq36d6LRBRBUvdWA5gejYMuYv4G CPwtRcrehi+fQ== Date: Tue, 06 May 2025 12:51:42 +0000 To: gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org, jason.wessel@windriver.com, danielt@kernel.org, dianders@chromium.org, jirislaby@kernel.org From: Roxana Nicolescu Cc: kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linux.dev Subject: [RFC PATCH 1/2] driver core: faux: create the device if probe() is deferred too Message-ID: <20250506125133.108786-2-nicolescu.roxana@protonmail.com> In-Reply-To: <20250506125133.108786-1-nicolescu.roxana@protonmail.com> References: <20250506125133.108786-1-nicolescu.roxana@protonmail.com> Feedback-ID: 136600343:user:proton X-Pm-Message-ID: 015bbc2fe70bde887f946c07da822d9b7a6c0ae5 Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There are situations when the faux device is probed, it waits for the availability for another piece of hardware. In case this dependency is not available, it can return -EPROBE_DEFER and probe will be retried later. But, with the current implementation, probe won't be retried at all because we destroyed the faux device in case probe did not return 0 and therefore the device is binded to the driver. To solve this, the faux device creation fails only when probe failed with something other than -EPROBE_DEFER. In order to achieve this, a boolean var is used in struct faux_object. Signed-off-by: Roxana Nicolescu --- drivers/base/faux.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/base/faux.c b/drivers/base/faux.c index 407c1d1aad50..21e385631872 100644 --- a/drivers/base/faux.c +++ b/drivers/base/faux.c @@ -25,6 +25,7 @@ struct faux_object { struct faux_device faux_dev; const struct faux_device_ops *faux_ops; + bool probe_successed_or_deferred; }; #define to_faux_object(dev) container_of_const(dev, struct faux_object, faux_dev.dev) @@ -48,6 +49,8 @@ static int faux_probe(struct device *dev) if (faux_ops && faux_ops->probe) ret = faux_ops->probe(faux_dev); + faux_obj->probe_successed_or_deferred = !ret || ret == -EPROBE_DEFER; + return ret; } @@ -150,12 +153,13 @@ struct faux_device *faux_device_create_with_groups(const char *name, } /* - * Verify that we did bind the driver to the device (i.e. probe worked), + * Verify that we either did bind the driver to the device (i.e. probe worked), + * or probe is deferred and tried later, * if not, let's fail the creation as trying to guess if probe was * successful is almost impossible to determine by the caller. */ - if (!dev->driver) { - dev_err(dev, "probe did not succeed, tearing down the device\n"); + if (!faux_obj->probe_successed_or_deferred) { + dev_err(dev, "probe did not succeed and it's not deferred, tearing down the device\n"); faux_device_destroy(faux_dev); faux_dev = NULL; } From patchwork Tue May 6 12:51:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roxana Nicolescu X-Patchwork-Id: 888040 Received: from mail-24416.protonmail.ch (mail-24416.protonmail.ch [109.224.244.16]) (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 6F73A27FD5B for ; Tue, 6 May 2025 12:51:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=109.224.244.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746535916; cv=none; b=AnHQBQv639E6OMELqDsfvXoV3gPIXOVy+sWl6FIfqzoFHhWLAvTRqLDJXQHUnTxqIlrhld39ZYY/CMRzO8MGp8x09G1PtAOnHxQNyMoD153k6rHfaWEOAZXqd30ZNmjtHYFLHWmT41jDe3WVdFyINMvmvwxvRndZOW+gpFzdQC4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746535916; c=relaxed/simple; bh=zK9w9rIJY/9mYRo0HXp9qe6o+/wCX4Pdi5dv42T1IzQ=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e0+XUuqF03S8Q5xWKj2YanpZYNiwZK88E+cyFhqtzfJ1w61n6+nbhh2FTkriYL2WLiOp0X0NvCCzvU2peKcRF6EFfaBoa9PDKT9JJ8k4cnRBSj9UinnIgCY4596Mo8WoLIP1V5g2JGwPZYSo2OqAHHSiJT57d99Mko7Yz/maDUE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com; spf=pass smtp.mailfrom=protonmail.com; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b=Kf3Te0Yh; arc=none smtp.client-ip=109.224.244.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=protonmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=protonmail.com header.i=@protonmail.com header.b="Kf3Te0Yh" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1746535912; x=1746795112; bh=zzBJeXUf0V8P3H7TLaYvoaJ0zwNJmLoh71eDPNoDAJo=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector:List-Unsubscribe:List-Unsubscribe-Post; b=Kf3Te0YhCqJrqtUsS5gb51nXR8axsPP1nqL+iDY8TkMgQdzoCkx6O2c0UQU+0a+Jr BHDQXEHA5FizNcgY8qlaulNEZ2XnQYRJSf4y6zfCu2/xeV2cjbT6eOg5+t+ww8NQ70 6ARuZu6ks9LXXszW5NUPrrnwa8AtbI4UxNoQDGj/UmWnq9ueKMvr6rHpD6RsgpvmCM csM0jyxT3JMaWjMCYM6yXRrDR14iijkd8rQ8w+Bwi3gGvX6sBe6Nxpw+58KOxgz6Pz +f3+32rXAd3cbOI9scolGovSLPCP93xmhxKq6FyjZM10Tx+Y8hPn3GkvRAqzrVKq6q xLijbJzpPLOFw== Date: Tue, 06 May 2025 12:51:48 +0000 To: gregkh@linuxfoundation.org, rafael@kernel.org, dakr@kernel.org, jason.wessel@windriver.com, danielt@kernel.org, dianders@chromium.org, jirislaby@kernel.org From: Roxana Nicolescu Cc: kgdb-bugreport@lists.sourceforge.net, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, skhan@linuxfoundation.org, linux-kernel-mentees@lists.linux.dev Subject: [RFC PATCH 2/2] serial: kgdboc: convert to use faux_device Message-ID: <20250506125133.108786-3-nicolescu.roxana@protonmail.com> In-Reply-To: <20250506125133.108786-1-nicolescu.roxana@protonmail.com> References: <20250506125133.108786-1-nicolescu.roxana@protonmail.com> Feedback-ID: 136600343:user:proton X-Pm-Message-ID: fd5abac4492e3841c902f5b9b7f60d650c2de90c Precedence: bulk X-Mailing-List: linux-serial@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 --- 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 #include #include -#include +#include #include #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)