The dummy regulator driver does not need to create a platform device, it
only did so because it was simple to do. Change it over to use the
faux bus instead as this is NOT a real platform device, and it makes
the code even smaller than before.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/regulator/dummy.c | 37 +++++++++----------------------------
1 file changed, 9 insertions(+), 28 deletions(-)
diff --git a/drivers/regulator/dummy.c b/drivers/regulator/dummy.c
index 5b9b9e4e762d..163b47e25291 100644
--- a/drivers/regulator/dummy.c
+++ b/drivers/regulator/dummy.c
@@ -13,7 +13,7 @@
#include <linux/err.h>
#include <linux/export.h>
-#include <linux/platform_device.h>
+#include <linux/device/faux.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
@@ -37,15 +37,15 @@ static const struct regulator_desc dummy_desc = {
.ops = &dummy_ops,
};
-static int dummy_regulator_probe(struct platform_device *pdev)
+static int dummy_regulator_probe(struct faux_device *vdev)
{
struct regulator_config config = { };
int ret;
- config.dev = &pdev->dev;
+ config.dev = &vdev->dev;
config.init_data = &dummy_initdata;
- dummy_regulator_rdev = devm_regulator_register(&pdev->dev, &dummy_desc,
+ dummy_regulator_rdev = devm_regulator_register(&vdev->dev, &dummy_desc,
&config);
if (IS_ERR(dummy_regulator_rdev)) {
ret = PTR_ERR(dummy_regulator_rdev);
@@ -56,36 +56,17 @@ static int dummy_regulator_probe(struct platform_device *pdev)
return 0;
}
-static struct platform_driver dummy_regulator_driver = {
- .probe = dummy_regulator_probe,
- .driver = {
- .name = "reg-dummy",
- .probe_type = PROBE_PREFER_ASYNCHRONOUS,
- },
+struct faux_driver_ops dummy_regulator_driver = {
+ .probe = dummy_regulator_probe,
};
-static struct platform_device *dummy_pdev;
+static struct faux_device *dummy_fdev;
void __init regulator_dummy_init(void)
{
- int ret;
-
- dummy_pdev = platform_device_alloc("reg-dummy", -1);
- if (!dummy_pdev) {
+ dummy_fdev = faux_device_create("reg-dummy", &dummy_regulator_driver);
+ if (!dummy_fdev) {
pr_err("Failed to allocate dummy regulator device\n");
return;
}
-
- ret = platform_device_add(dummy_pdev);
- if (ret != 0) {
- pr_err("Failed to register dummy regulator device: %d\n", ret);
- platform_device_put(dummy_pdev);
- return;
- }
-
- ret = platform_driver_register(&dummy_regulator_driver);
- if (ret != 0) {
- pr_err("Failed to register dummy regulator driver: %d\n", ret);
- platform_device_unregister(dummy_pdev);
- }
}
--
2.48.1
On Mon, Feb 03, 2025 at 03:25:18PM +0100, Greg Kroah-Hartman wrote: > The dummy regulator driver does not need to create a platform device, it > only did so because it was simple to do. Change it over to use the > faux bus instead as this is NOT a real platform device, and it makes > the code even smaller than before. No, they did this because you explicitly asked that this be done.... > -static int dummy_regulator_probe(struct platform_device *pdev) > +static int dummy_regulator_probe(struct faux_device *vdev) Just dev or fdev - we could just pass a struct device in here, we don't actually care that it's a platform device at this point. Having the abbreviation mismatch with the device type is odd.
On Mon, Feb 03, 2025 at 03:39:06PM +0000, Mark Brown wrote: > On Mon, Feb 03, 2025 at 03:25:18PM +0100, Greg Kroah-Hartman wrote: > > The dummy regulator driver does not need to create a platform device, it > > only did so because it was simple to do. Change it over to use the > > faux bus instead as this is NOT a real platform device, and it makes > > the code even smaller than before. > > No, they did this because you explicitly asked that this be done.... I did? What was it attempting to be before this? I don't remember that at all, sorry. > > -static int dummy_regulator_probe(struct platform_device *pdev) > > +static int dummy_regulator_probe(struct faux_device *vdev) > > Just dev or fdev - we could just pass a struct device in here, we don't > actually care that it's a platform device at this point. Having the > abbreviation mismatch with the device type is odd. Ah, that's a mistake from my first pass when this was a "struct virtual_device" and I called this "vdev". I'll go fix that up, thanks. greg k-h
On Mon, Feb 03, 2025 at 04:46:02PM +0100, Greg Kroah-Hartman wrote: > On Mon, Feb 03, 2025 at 03:39:06PM +0000, Mark Brown wrote: > > On Mon, Feb 03, 2025 at 03:25:18PM +0100, Greg Kroah-Hartman wrote: > > > The dummy regulator driver does not need to create a platform device, it > > > only did so because it was simple to do. Change it over to use the > > > faux bus instead as this is NOT a real platform device, and it makes > > > the code even smaller than before. > > No, they did this because you explicitly asked that this be done.... > I did? What was it attempting to be before this? I don't remember that > at all, sorry. Yeah, there were some things where people were creating custom buses for internal uses like this which you pushed back on due to code duplication - you said to just use platform bus since the bus code looked identical.
© 2016 - 2026 Red Hat, Inc.