gpio: kill dev-sync-probe
Subsystems (2)
cover gpio: kill dev-sync-probe
I came up with this elaborate mechanism to synchronously wait for the platform devices activated over configs to probe, involving notifiers and completions (which was later factored out into what is today the dev-sync-probe module) because I didn't know any better. It turns out there's an idiomatic way of achieving the same goal with much less LOC. Port the three drivers to using a combination of wait_for_probe() and device_is_bound() and remove the dev-sync-probe module.
---
Bartosz Golaszewski (4):
gpio: sim: stop using dev-sync-probe
gpio: aggregator: stop using dev-sync-probe
gpio: virtuser: stop using dev-sync-probe
gpio: remove dev-sync-probe
drivers/gpio/Kconfig | 6 --- drivers/gpio/Makefile | 3 -- drivers/gpio/dev-sync-probe.c | 97 ------------------------------------------ drivers/gpio/dev-sync-probe.h | 25 ----------- drivers/gpio/gpio-aggregator.c | 38 +++++++++-------- drivers/gpio/gpio-sim.c | 49 ++++++++++++--------- drivers/gpio/gpio-virtuser.c | 30 ++++++++----- 7 files changed, 70 insertions(+), 178 deletions(-)
---
base-commit: e77a5a5cfe43b4c25bd44a3818e487033287517f
change-id: 20260327-gpio-kill-dev-sync-probe-4027fab0c0a6
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>
PATCH 1/4 gpio: sim: stop using dev-sync-probe
dev-err-probe is an overengineered solution to a simple problem. Use a combination of wait_for_probe() and device_is_bound() to synchronously wait for the platform device to probe.
--- drivers/gpio/Kconfig | 1 - drivers/gpio/gpio-sim.c | 49 +++++++++++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 21 deletions(-)
drivers/gpio/Kconfig +0 -1
@@ -2036,7 +2036,6 @@ config GPIO_SIM tristate "GPIO Simulator Module" select IRQ_SIM select CONFIGFS_FS - select DEV_SYNC_PROBE help This enables the GPIO simulator - a configfs-based GPIO testing driver.
drivers/gpio/gpio-sim.c +29 -20
115 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH 2/4 gpio: aggregator: stop using dev-sync-probe
In reply to Bartosz Golaszewskidev-err-probe is an overengineered solution to a simple problem. Use a combination of wait_for_probe() and device_is_bound() to synchronously wait for the platform device to probe.
--- drivers/gpio/Kconfig | 1 - drivers/gpio/gpio-aggregator.c | 38 +++++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 18 deletions(-)
drivers/gpio/Kconfig +0 -1
@@ -1984,7 +1984,6 @@ menu "Virtual GPIO drivers" config GPIO_AGGREGATOR tristate "GPIO Aggregator" select CONFIGFS_FS - select DEV_SYNC_PROBE help Say yes here to enable the GPIO Aggregator, which provides a way to aggregate existing GPIO lines into a new virtual GPIO chip.
drivers/gpio/gpio-aggregator.c +21 -17
@@ -32,8 +32,6 @@#include <linux/gpio/forwarder.h> #include <linux/gpio/machine.h> -#include "dev-sync-probe.h" -#define AGGREGATOR_MAX_GPIOS 512#define AGGREGATOR_LEGACY_PREFIX "_sysfs"
@@ -42,7 +40,7 @@*/ struct gpio_aggregator { -struct dev_sync_probe_data probe_data; +struct platform_device *pdev;struct config_group group;struct gpiod_lookup_table *lookups;struct mutex lock;
@@ -135,7 +133,7 @@ static bool gpio_aggregator_is_active(struct gpio_aggregator *aggr) {lockdep_assert_held (&aggr->lock); -return aggr->probe_data.pdev &&platform_get_drvdata (aggr->probe_data.pdev); +return aggr->pdev &&platform_get_drvdata (aggr->pdev); }/* Only aggregators created via legacy sysfs can be "activating". */
@@ -143,7 +141,7 @@ static bool gpio_aggregator_is_activating(struct gpio_aggregator *aggr) {lockdep_assert_held (&aggr->lock); -return aggr->probe_data.pdev && !platform_get_drvdata (aggr->probe_data.pdev); +return aggr->pdev && !platform_get_drvdata (aggr->pdev); }static size_t gpio_aggregator_count_lines (struct gpio_aggregator *aggr)
@@ -909,6 +907,7 @@ static int gpio_aggregator_activate(struct gpio_aggregator *aggr) {struct platform_device_info pdevinfo;struct gpio_aggregator_line *line; +struct platform_device *pdev;struct fwnode_handle *swnode;unsigned int n =0 ;int ret =0 ;
@@ -962,12 +961,23 @@ static int gpio_aggregator_activate(struct gpio_aggregator *aggr)gpiod_add_lookup_table (aggr->lookups); - ret =dev_sync_probe_register (&aggr->probe_data, &pdevinfo); -if (ret) + pdev =platform_device_register_full (&pdevinfo); +if (IS_ERR (pdev)) { + ret =PTR_ERR (pdev); goto err_remove_lookup_table; + } +wait_for_device_probe (); +if (!device_is_bound (&pdev->dev)) { + ret = -ENXIO ; + goto err_unregister_pdev; + } + + aggr->pdev = pdev;return 0 ; +err_unregister_pdev: +platform_device_unregister (pdev); err_remove_lookup_table:kfree (aggr->lookups->dev_id);gpiod_remove_lookup_table (aggr->lookups);
@@ -981,7 +991,8 @@ static int gpio_aggregator_activate(struct gpio_aggregator *aggr)static void gpio_aggregator_deactivate (struct gpio_aggregator *aggr) { -dev_sync_probe_unregister (&aggr->probe_data); +platform_device_unregister (aggr->pdev); + aggr->pdev =NULL ;gpiod_remove_lookup_table (aggr->lookups);kfree (aggr->lookups->dev_id);kfree (aggr->lookups);
@@ -1145,7 +1156,7 @@ gpio_aggregator_device_dev_name_show(struct config_item *item, char *page)guard (mutex)(&aggr->lock); - pdev = aggr->probe_data.pdev; + pdev = aggr->pdev;if (pdev)return sysfs_emit (page,"%s\n" ,dev_name (&pdev->dev));
@@ -1322,7 +1333,6 @@ gpio_aggregator_make_group(struct config_group *group, const char *name)return ERR_PTR (ret);config_group_init_type_name (&aggr->group, name, &gpio_aggregator_device_type); -dev_sync_probe_init (&aggr->probe_data);return &aggr->group; }
@@ -1471,12 +1481,6 @@ static ssize_t gpio_aggregator_new_device_store(struct device_driver *driver,scnprintf (name,sizeof (name),"%s.%d" ,AGGREGATOR_LEGACY_PREFIX , aggr->id);config_group_init_type_name (&aggr->group, name, &gpio_aggregator_device_type); -/* -* Since the device created by sysfs might be toggled via configfs -* 'live' attribute later, this initialization is needed. -*/ -dev_sync_probe_init (&aggr->probe_data); -/* Expose to configfs */ res =configfs_register_group (&gpio_aggregator_subsys.su_group, &aggr->group);
@@ -1495,7 +1499,7 @@ static ssize_t gpio_aggregator_new_device_store(struct device_driver *driver, goto remove_table; } - aggr->probe_data.pdev = pdev; + aggr->pdev = pdev;module_put (THIS_MODULE );return count;
Signature · 1 line
2.47.3
Bartosz Golaszewski
maintainerRe: [PATCH 2/4] gpio: aggregator: stop using dev-sync-probe
Quoted 7 lines · Bartosz Golaszewski
dev-err-probe is an overengineered solution to a simple problem. Use a combination of
wait_for_probe()anddevice_is_bound()to synchronously wait for the platform device to probe.Signed-off-by Bartosz Golaszewski <[email protected]>---
Hi Geert!
Any objections to this being queued for v7.1?
Bart
PATCH 3/4 gpio: virtuser: stop using dev-sync-probe
In reply to Bartosz Golaszewskidev-err-probe is an overengineered solution to a simple problem. Use a combination of wait_for_probe() and device_is_bound() to synchronously wait for the platform device to probe.
--- drivers/gpio/Kconfig | 1 - drivers/gpio/gpio-virtuser.c | 30 ++++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-)
drivers/gpio/Kconfig +0 -1
@@ -2072,7 +2072,6 @@ config GPIO_VIRTUSER select DEBUG_FS select CONFIGFS_FS select IRQ_WORK - select DEV_SYNC_PROBE help Say Y here to enable the configurable, configfs-based virtual GPIO consumer testing driver.
drivers/gpio/gpio-virtuser.c +20 -10
@@ -36,8 +36,6 @@#include <linux/string_helpers.h> #include <linux/types.h> -#include "dev-sync-probe.h" -#define GPIO_VIRTUSER_NAME_BUF_LEN 32static DEFINE_IDA (gpio_virtuser_ida);
@@ -978,7 +976,7 @@ static struct platform_driver gpio_virtuser_driver = { };struct gpio_virtuser_device { -struct dev_sync_probe_data probe_data; +struct platform_device *pdev;struct config_group group;int id;
@@ -1002,7 +1000,7 @@ gpio_virtuser_device_is_live(struct gpio_virtuser_device *dev) {lockdep_assert_held (&dev->lock); -return !!dev->probe_data.pdev; +return !!dev->pdev; }struct gpio_virtuser_lookup {
@@ -1342,7 +1340,7 @@ gpio_virtuser_device_config_dev_name_show(struct config_item *item,guard (mutex)(&dev->lock); - pdev = dev->probe_data.pdev; + pdev = dev->pdev;if (pdev)return sprintf (page,"%s\n" ,dev_name (&pdev->dev));
@@ -1450,6 +1448,7 @@ static int gpio_virtuser_device_activate(struct gpio_virtuser_device *dev) {struct platform_device_info pdevinfo; +struct platform_device *pdev;struct fwnode_handle *swnode;int ret;
@@ -1471,12 +1470,23 @@ gpio_virtuser_device_activate(struct gpio_virtuser_device *dev)if (ret) goto err_remove_swnode; - ret =dev_sync_probe_register (&dev->probe_data, &pdevinfo); -if (ret) + pdev =platform_device_register_full (&pdevinfo); +if (IS_ERR (pdev)) { + ret =PTR_ERR (pdev); goto err_remove_lookup_table; + } + +wait_for_device_probe (); +if (!device_is_bound (&pdev->dev)) { + ret = -ENXIO ; + goto err_unregister_pdev; + } + dev->pdev = pdev;return 0 ; +err_unregister_pdev: +platform_device_unregister (pdev); err_remove_lookup_table:gpio_virtuser_remove_lookup_table (dev); err_remove_swnode:
@@ -1492,8 +1502,9 @@ gpio_virtuser_device_deactivate(struct gpio_virtuser_device *dev)lockdep_assert_held (&dev->lock); - swnode =dev_fwnode (&dev->probe_data.pdev->dev); -dev_sync_probe_unregister (&dev->probe_data); + swnode =dev_fwnode (&dev->pdev->dev); +platform_device_unregister (dev->pdev); + dev->pdev =NULL ;gpio_virtuser_remove_lookup_table (dev);fwnode_remove_software_node (swnode); }
@@ -1723,7 +1734,6 @@ gpio_virtuser_config_make_device_group(struct config_group *group, &gpio_virtuser_device_config_group_type);mutex_init (&dev->lock);INIT_LIST_HEAD (&dev->lookup_list); -dev_sync_probe_init (&dev->probe_data);return &no_free_ptr (dev)->group; }
Signature · 1 line
2.47.3
PATCH 4/4 gpio: remove dev-sync-probe
In reply to Bartosz GolaszewskiThere are no more users. Remove the dev-sync-probe module.
--- drivers/gpio/Kconfig | 3 -- drivers/gpio/Makefile | 3 -- drivers/gpio/dev-sync-probe.c | 97 ------------------------------------------- drivers/gpio/dev-sync-probe.h | 25 ----------- 4 files changed, 128 deletions(-)
drivers/gpio/Kconfig +0 -3
@@ -2082,6 +2082,3 @@ config GPIO_VIRTUSER endmenu endif - -config DEV_SYNC_PROBE - tristate
drivers/gpio/Makefile +0 -3
@@ -21,9 +21,6 @@ obj-$(CONFIG_GPIO_GENERIC) += gpio-generic.o # directly supported by gpio-generic gpio-generic-$(CONFIG_GPIO_GENERIC) += gpio-mmio.o -# Utilities for drivers that need synchronous fake device creation -obj-$(CONFIG_DEV_SYNC_PROBE) += dev-sync-probe.o - obj-$(CONFIG_GPIO_104_DIO_48E) += gpio-104-dio-48e.o obj-$(CONFIG_GPIO_104_IDI_48) += gpio-104-idi-48.o obj-$(CONFIG_GPIO_104_IDIO_16) += gpio-104-idio-16.o
drivers/gpio/dev-sync-probe.c deleted +0 -97
97 lines not on this page · raw message
drivers/gpio/dev-sync-probe.h deleted +0 -25
@@ -1,25 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ - -#ifndef DEV_SYNC_PROBE_H -#define DEV_SYNC_PROBE_H - -#include <linux/completion.h> -#include <linux/notifier.h> -#include <linux/platform_device.h> - -struct dev_sync_probe_data { -struct platform_device *pdev; -const char *name; - -/* Synchronize with probe */ -struct notifier_block bus_notifier; -struct completion probe_completion; -bool driver_bound; -}; - -void dev_sync_probe_init (struct dev_sync_probe_data *data); -int dev_sync_probe_register (struct dev_sync_probe_data *data, -struct platform_device_info *pdevinfo); -void dev_sync_probe_unregister (struct dev_sync_probe_data *data); - -#endif /* DEV_SYNC_PROBE_H */
Signature · 1 line
2.47.3
Quoted 9 lines · Bartosz Golaszewski
I came up with this elaborate mechanism to synchronously wait for the platform devices activated over configs to probe, involving notifiers and completions (which was later factored out into what is today the dev-sync-probe module) because I didn't know any better. It turns out there's an idiomatic way of achieving the same goal with much less LOC. Port the three drivers to using a combination of
wait_for_probe()anddevice_is_bound()and remove the dev-sync-probe module.Signed-off-by Bartosz Golaszewski <[email protected]>
That looks way better!
Yours,
Linus Walleij
Bartosz Golaszewski
AppliedQuoted 9 lines · Bartosz Golaszewski
I came up with this elaborate mechanism to synchronously wait for the platform devices activated over configs to probe, involving notifiers and completions (which was later factored out into what is today the dev-sync-probe module) because I didn't know any better. It turns out there's an idiomatic way of achieving the same goal with much less LOC. Port the three drivers to using a combination of
wait_for_probe()anddevice_is_bound()and remove the dev-sync-probe module.[...]
Applied, thanks!
[1/4] gpio: sim: stop using dev-sync-probe
https://git.kernel.org/brgl/c/7fb3287946f937a32adad35c9bec4bbc71e25bb8 [2/4] gpio: aggregator: stop using dev-sync-probe https://git.kernel.org/brgl/c/3a27f40b457053e6112a63d14590e4a3ff553b44 [3/4] gpio: virtuser: stop using dev-sync-probe https://git.kernel.org/brgl/c/c3e2a8aef28c48a94c0cf0525ca96aa308bcf961 [4/4] gpio: remove dev-sync-probe https://git.kernel.org/brgl/c/dd84f7ce6fd12fb5d6648d6b5d8ea4bf6f834273
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>