From ba55a9741da6c85176987c15e24383b858749aa2 Mon Sep 17 00:00:00 2001 From: Mark Brown Date: Tue, 23 Aug 2011 17:39:10 +0100 Subject: regulator: Add debugfs file showing the supply map table Useful for working out why things aren't getting plugged together properly. Signed-off-by: Mark Brown Signed-off-by: Liam Girdwood --- drivers/regulator/core.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'drivers/regulator/core.c') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index d8e6a42..9a33fe2 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -2907,6 +2907,43 @@ void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data) } EXPORT_SYMBOL_GPL(regulator_get_init_drvdata); +#ifdef CONFIG_DEBUG_FS +static ssize_t supply_map_read_file(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); + ssize_t len, ret = 0; + struct regulator_map *map; + + if (!buf) + return -ENOMEM; + + list_for_each_entry(map, ®ulator_map_list, list) { + len = snprintf(buf + ret, PAGE_SIZE - ret, + "%s -> %s.%s\n", + rdev_get_name(map->regulator), map->dev_name, + map->supply); + if (len >= 0) + ret += len; + if (ret > PAGE_SIZE) { + ret = PAGE_SIZE; + break; + } + } + + ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); + + kfree(buf); + + return ret; +} + +static const struct file_operations supply_map_fops = { + .read = supply_map_read_file, + .llseek = default_llseek, +}; +#endif + static int __init regulator_init(void) { int ret; @@ -2919,6 +2956,10 @@ static int __init regulator_init(void) pr_warn("regulator: Failed to create debugfs directory\n"); debugfs_root = NULL; } + + if (IS_ERR(debugfs_create_file("supply_map", 0444, debugfs_root, + NULL, &supply_map_fops))) + pr_warn("regulator: Failed to create supplies debugfs\n"); #endif regulator_dummy_init(); -- cgit v1.1 From d1685e4e2c3854782272f32b71f2f3eff5c6e0d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Heiko=20St=C3=BCbner?= Date: Fri, 14 Oct 2011 18:00:29 +0200 Subject: regulator: Fix possible nullpointer dereference in regulator_enable() In the case where _regulator_enable returns an error it was not checked if a supplying regulator exists before trying to disable it, leading to a null pointer-dereference if no supplying regulator existed. Signed-off-by: Heiko Stuebner Signed-off-by: Mark Brown --- drivers/regulator/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/regulator/core.c') diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 9a33fe2..87d9328 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1425,7 +1425,7 @@ int regulator_enable(struct regulator *regulator) ret = _regulator_enable(rdev); mutex_unlock(&rdev->mutex); - if (ret != 0) + if (ret != 0 && rdev->supply) regulator_disable(rdev->supply); return ret; -- cgit v1.1