@@ -1567,6 +1567,7 @@ config GPIO_AGGREGATOR
config GPIO_MOCKUP
tristate "GPIO Testing Driver"
+ depends on DEBUG_FS
select IRQ_SIM
help
This enables GPIO Testing driver, which provides a way to test GPIO
@@ -348,38 +348,55 @@ static const struct file_operations gpio_mockup_debugfs_ops = {
.release = single_release,
};
-static void gpio_mockup_debugfs_setup(struct device *dev,
- struct gpio_mockup_chip *chip)
+static void gpio_mockup_remove_chip_debugfs_entry(void *data)
+{
+ struct dentry *entry = data;
+
+ debugfs_remove_recursive(entry);
+}
+
+static int gpio_mockup_debugfs_setup(struct device *dev,
+ struct gpio_mockup_chip *chip)
{
struct gpio_mockup_dbgfs_private *priv;
struct gpio_chip *gc;
+ struct dentry *attr;
const char *devname;
char *name;
- int i;
+ int i, ret;
gc = &chip->gc;
devname = dev_name(&gc->gpiodev->dev);
chip->dbg_dir = debugfs_create_dir(devname, gpio_mockup_dbg_dir);
+ if (IS_ERR(chip->dbg_dir))
+ return PTR_ERR(chip->dbg_dir);
+
+ ret = devm_add_action_or_reset(dev,
+ gpio_mockup_remove_chip_debugfs_entry, chip->dbg_dir);
+ if (ret)
+ return ret;
for (i = 0; i < gc->ngpio; i++) {
name = devm_kasprintf(dev, GFP_KERNEL, "%d", i);
if (!name)
- return;
+ return -ENOMEM;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
- return;
+ return -ENOMEM;
priv->chip = chip;
priv->offset = i;
priv->desc = &gc->gpiodev->descs[i];
- debugfs_create_file(name, 0200, chip->dbg_dir, priv,
- &gpio_mockup_debugfs_ops);
+ attr = debugfs_create_file(name, 0200, chip->dbg_dir, priv,
+ &gpio_mockup_debugfs_ops);
+ if (IS_ERR(attr))
+ return PTR_ERR(attr);
}
- return;
+ return 0;
}
static void gpio_mockup_dispose_mappings(void *data)
@@ -462,7 +479,9 @@ static int gpio_mockup_probe(struct platform_device *pdev)
if (rv)
return rv;
- gpio_mockup_debugfs_setup(dev, chip);
+ rv = gpio_mockup_debugfs_setup(dev, chip);
+ if (rv)
+ return rv;
return 0;
}
@@ -629,6 +648,8 @@ static int __init gpio_mockup_init(void)
int ret;
gpio_mockup_dbg_dir = debugfs_create_dir("gpio-mockup", NULL);
+ if (IS_ERR(gpio_mockup_dbg_dir))
+ return PTR_ERR(gpio_mockup_dbg_dir);
ret = platform_driver_register(&gpio_mockup_driver);
if (ret) {
@@ -650,9 +671,9 @@ static int __init gpio_mockup_init(void)
static void __exit gpio_mockup_exit(void)
{
- debugfs_remove_recursive(gpio_mockup_dbg_dir);
platform_driver_unregister(&gpio_mockup_driver);
gpio_mockup_unregister_devices();
+ debugfs_remove_recursive(gpio_mockup_dbg_dir);
}
module_init(gpio_mockup_init);