]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
regmap: debugfs: fix possbile NULL pointer dereference
authorXiubo Li <Li.Xiubo@freescale.com>
Sun, 28 Sep 2014 03:35:25 +0000 (11:35 +0800)
committerZefan Li <lizefan@huawei.com>
Mon, 2 Feb 2015 09:04:44 +0000 (17:04 +0800)
commit 2c98e0c1cc6b8e86f1978286c3d4e0769ee9d733 upstream.

If 'map->dev' is NULL and there will lead dev_name() to be NULL pointer
dereference. So before dev_name(), we need to have check of the map->dev
pionter.

We also should make sure that the 'name' pointer shouldn't be NULL for
debugfs_create_dir(). So here using one default "dummy" debugfs name when
the 'name' pointer and 'map->dev' are both NULL.

Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
[lizf: Backported to 3.4: dev_name() is passed to debugfs_create_dir() in 3.4]
Signed-off-by: Zefan Li <lizefan@huawei.com>
drivers/base/regmap/regmap-debugfs.c

index 8ab1eab90be7c0cf5cb34f380f4cc45c6b11631c..1db12895110af3b1c360ed7af9b8eb928c99496b 100644 (file)
@@ -244,7 +244,12 @@ static const struct file_operations regmap_access_fops = {
 
 void regmap_debugfs_init(struct regmap *map)
 {
-       map->debugfs = debugfs_create_dir(dev_name(map->dev),
+       const char *devname = "dummy";
+
+       if (map->dev)
+               devname = dev_name(map->dev);
+
+       map->debugfs = debugfs_create_dir(devname,
                                          regmap_debugfs_root);
        if (!map->debugfs) {
                dev_warn(map->dev, "Failed to create debugfs directory\n");