mirror of
https://github.com/torvalds/linux.git
synced 2025-04-12 06:49:52 +00:00
gpio: virtuser: convert to use dev-sync-probe utilities
Update gpio-virtuser to use the new dev-sync-probe helper functions for synchronized platform device creation, reducing code duplication. No functional change. Signed-off-by: Koichiro Den <koichiro.den@canonical.com> Link: https://lore.kernel.org/r/20250221133501.2203897-4-koichiro.den@canonical.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This commit is contained in:
parent
2f41dbf9cb
commit
45af02f06f
@ -1939,6 +1939,7 @@ 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.
|
||||
|
@ -11,7 +11,6 @@
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/bitmap.h>
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/configfs.h>
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/device.h>
|
||||
@ -37,6 +36,8 @@
|
||||
#include <linux/string_helpers.h>
|
||||
#include <linux/types.h>
|
||||
|
||||
#include "dev-sync-probe.h"
|
||||
|
||||
#define GPIO_VIRTUSER_NAME_BUF_LEN 32
|
||||
|
||||
static DEFINE_IDA(gpio_virtuser_ida);
|
||||
@ -973,49 +974,17 @@ static struct platform_driver gpio_virtuser_driver = {
|
||||
};
|
||||
|
||||
struct gpio_virtuser_device {
|
||||
struct dev_sync_probe_data probe_data;
|
||||
struct config_group group;
|
||||
|
||||
struct platform_device *pdev;
|
||||
int id;
|
||||
struct mutex lock;
|
||||
|
||||
struct notifier_block bus_notifier;
|
||||
struct completion probe_completion;
|
||||
bool driver_bound;
|
||||
|
||||
struct gpiod_lookup_table *lookup_table;
|
||||
|
||||
struct list_head lookup_list;
|
||||
};
|
||||
|
||||
static int gpio_virtuser_bus_notifier_call(struct notifier_block *nb,
|
||||
unsigned long action, void *data)
|
||||
{
|
||||
struct gpio_virtuser_device *vdev;
|
||||
struct device *dev = data;
|
||||
char devname[32];
|
||||
|
||||
vdev = container_of(nb, struct gpio_virtuser_device, bus_notifier);
|
||||
snprintf(devname, sizeof(devname), "gpio-virtuser.%d", vdev->id);
|
||||
|
||||
if (!device_match_name(dev, devname))
|
||||
return NOTIFY_DONE;
|
||||
|
||||
switch (action) {
|
||||
case BUS_NOTIFY_BOUND_DRIVER:
|
||||
vdev->driver_bound = true;
|
||||
break;
|
||||
case BUS_NOTIFY_DRIVER_NOT_BOUND:
|
||||
vdev->driver_bound = false;
|
||||
break;
|
||||
default:
|
||||
return NOTIFY_DONE;
|
||||
}
|
||||
|
||||
complete(&vdev->probe_completion);
|
||||
return NOTIFY_OK;
|
||||
}
|
||||
|
||||
static struct gpio_virtuser_device *
|
||||
to_gpio_virtuser_device(struct config_item *item)
|
||||
{
|
||||
@ -1029,7 +998,7 @@ gpio_virtuser_device_is_live(struct gpio_virtuser_device *dev)
|
||||
{
|
||||
lockdep_assert_held(&dev->lock);
|
||||
|
||||
return !!dev->pdev;
|
||||
return !!dev->probe_data.pdev;
|
||||
}
|
||||
|
||||
struct gpio_virtuser_lookup {
|
||||
@ -1369,7 +1338,7 @@ gpio_virtuser_device_config_dev_name_show(struct config_item *item,
|
||||
|
||||
guard(mutex)(&dev->lock);
|
||||
|
||||
pdev = dev->pdev;
|
||||
pdev = dev->probe_data.pdev;
|
||||
if (pdev)
|
||||
return sprintf(page, "%s\n", dev_name(&pdev->dev));
|
||||
|
||||
@ -1478,7 +1447,6 @@ gpio_virtuser_device_activate(struct gpio_virtuser_device *dev)
|
||||
{
|
||||
struct platform_device_info pdevinfo;
|
||||
struct fwnode_handle *swnode;
|
||||
struct platform_device *pdev;
|
||||
int ret;
|
||||
|
||||
lockdep_assert_held(&dev->lock);
|
||||
@ -1499,31 +1467,12 @@ gpio_virtuser_device_activate(struct gpio_virtuser_device *dev)
|
||||
if (ret)
|
||||
goto err_remove_swnode;
|
||||
|
||||
reinit_completion(&dev->probe_completion);
|
||||
dev->driver_bound = false;
|
||||
bus_register_notifier(&platform_bus_type, &dev->bus_notifier);
|
||||
|
||||
pdev = platform_device_register_full(&pdevinfo);
|
||||
if (IS_ERR(pdev)) {
|
||||
ret = PTR_ERR(pdev);
|
||||
bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier);
|
||||
ret = dev_sync_probe_register(&dev->probe_data, &pdevinfo);
|
||||
if (ret)
|
||||
goto err_remove_lookup_table;
|
||||
}
|
||||
|
||||
wait_for_completion(&dev->probe_completion);
|
||||
bus_unregister_notifier(&platform_bus_type, &dev->bus_notifier);
|
||||
|
||||
if (!dev->driver_bound) {
|
||||
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:
|
||||
@ -1539,11 +1488,10 @@ gpio_virtuser_device_deactivate(struct gpio_virtuser_device *dev)
|
||||
|
||||
lockdep_assert_held(&dev->lock);
|
||||
|
||||
swnode = dev_fwnode(&dev->pdev->dev);
|
||||
platform_device_unregister(dev->pdev);
|
||||
swnode = dev_fwnode(&dev->probe_data.pdev->dev);
|
||||
dev_sync_probe_unregister(&dev->probe_data);
|
||||
gpio_virtuser_remove_lookup_table(dev);
|
||||
fwnode_remove_software_node(swnode);
|
||||
dev->pdev = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1772,8 +1720,7 @@ 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->bus_notifier.notifier_call = gpio_virtuser_bus_notifier_call;
|
||||
init_completion(&dev->probe_completion);
|
||||
dev_sync_probe_init(&dev->probe_data);
|
||||
|
||||
return &no_free_ptr(dev)->group;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user